以定义参数 cus_param 为例,int型变量。
1. Preloader部分
Platform.h(mediatek\platform\[$platform]\preloader\src\drivers\inc\platform.h)
在如下结构体中加cus_param变量,如果是char型,请注意4byte对其:
typedef struct {
u32 magic;
boot_mode_t mode;
u32 e_flag;
u32 log_port;
u32 log_baudrate;
u8 log_enable;
u8 part_num;
u8 reserved[2];
u32 dram_rank_num;
u32 dram_rank_size[4];
u32 boot_reason;
u32 meta_com_type;
u32 meta_com_id;
u32 boot_time;
da_info_t da_info;
SEC_LIMIT sec_limit;
part_hdr_t *part_info;
u8 md_type[4];
u32 ddr_reserve_enable;
u32 ddr_reserve_success;
u32 cus_param; //mediatek add
} boot_arg_t;
Platform.c(mediatek\platform\[$platform]\preloader\src\drivers\platform.c)
在此函数中添加对cus_param的赋值,通过函数,或者直接写入所需的值:
void platform_set_boot_args()
{
#if CFG_BOOT_ARGUMENT
bootarg.magic = BOOT_ARGUMENT_MAGIC;
bootarg.mode = g_boot_mode;
bootarg.e_flag = sp_check_platform();
bootarg.log_port = CFG_UART_LOG;
bootarg.log_baudrate = CFG_LOG_BAUDRATE;
bootarg.log_enable = (u8)log_status();
bootarg.dram_rank_num = get_dram_rank_nr();
get_dram_rank_size(bootarg.dram_rank_size);
bootarg.boot_reason = g_boot_reason;
bootarg.meta_com_type = (u32)g_meta_com_type;
bootarg.meta_com_id = g_meta_com_id;
bootarg.boot_time = get_timer(g_boot_time);
bootarg.part_num = g_dram_buf->part_num;
bootarg.part_info = g_dram_buf->part_info;
bootarg.ddr_reserve_enable = g_ddr_reserve_enable;
bootarg.ddr_reserve_success= g_ddr_reserve_success;
//mediatek add,mt_get_cus_param这个函数是客制化得到cus_param的函数,请自行实现
bootarg.cus_param = mt_get_cus_param();
2.LK 部分
Boot_mode.h(mediatek\platform\[$platform]\lk\include\platform\boot_mode.h)
在如下结构体中同样添加cus_param变量,如果是char型,请注意4byte对其:
typedef struct {
u32 maggic_number;
BOOTMODE boot_mode;
u32 e_flag;
u32 log_port;
u32 log_baudrate;
u8 log_enable;
u8 part_num;
u8 reserved[2];
u32 dram_rank_num;
u32 dram_rank_size[4];
u32 boot_reason;
META_COM_TYPE meta_com_type;
u32 meta_com_id;
u32 boot_time;
da_info_t da_info;
SEC_LIMIT sec_limit;
part_hdr_t *part_info;
u8 md_type[4];
u32 ddr_reserve_enable;
u32 ddr_reserve_success;
u32 cus_param; //mediatek add,和preloader部分相同,两个结构体要一样
} BOOT_ARGUMENT;
Mt_boot.c(bootable\bootloader\lk\app\mt_boot\mt_boot.c)
在此函数中,将cus_param的信息添加到cmdline上:
int boot_linux_from_storage(void)
{
.....
strlen += sprintf(commanline, "%s fps=%1d", commanline, mt_disp_get_lcd_time());
strlen += sprintf(commanline, "%s cus_param=%1d", commanline, g_boot_arg->cus_param); //mediatek add
3.Kernel部分
saved_command_line 这是一个全局变量,在您所需要此参数的driver文件中,extern saved_command_line变量,
通过查找 cus_param 的字符串即可:
char * ptr;
int cus_param;
ptr = strstr(saved_command_line, "cus_param=");
ptr += strlen("cus_param=");
cus_param = simple_strtol(ptr, NULL, 10);
此时 cus_param就是最初的int值。