怎么才能将LK的变量,在KERNEL中读取使用?
写个简单版本的,未亲测
以lk传递lcm的名称为例说明:
lk的文件位置
./bootable/bootloader/lk/app/mt_boot/mt_boot.c
custom_port_in_kernel(g_boot_mode, commanline);
//FIXME, Waiting LCM Driver owner to fix it
strlen += sprintf(commanline, "%s lcm=%1d-%s", commanline, DISP_IsLcmFound(), mt_disp_get_lcm_id());
strlen += sprintf(commanline, "%s fps=%1d", commanline, mt_disp_get_lcd_time());
boot_linux((void *)CFG_BOOTIMG_LOAD_ADDR, (unsigned *)CFG_BOOTARGS_ADDR,
(char *)commanline, board_machtype(),
(void *)CFG_RAMDISK_LOAD_ADDR, g_rimg_sz);
kernel的读取位置
./mediatek/kernel/drivers/video/mtkfb.c
BOOL mtkfb_find_lcm_driver(void)
{
BOOL ret = FALSE;
char *p, *q;
p = strstr(saved_command_line, "lcm=");
用 __setup
__setup这条宏在Linux Kernel中使用最多的地方就是定义处理Kernel的启动参数的函数及数据结构
- static int __init hw_configuration(char *str)
- {
- char cfg[30];
- char *arg1, *arg2;
- memset(cfg, 0, 30);
- strcpy(cfg, str);
- arg1 = strchr(cfg, ',');
- memcpy(hw_config, ++arg1, 8);
- printk("hw_configuration: hw_config=%s\n", hw_config);
- arg2 = strchr(arg1, ',');
- memcpy(sw_config, ++arg2, 3);
- printk("hw_configuration: sw_config=%s\n", sw_config);
-
- memcpy(board_cfg.idx, hw_config, 1);
- memcpy(lcm_cfg.idx, hw_config+1, 1);
- memcpy(tp_cfg.idx, hw_config+2, 1);
- memcpy(ps_cfg.idx, hw_config+3, 1);
- memcpy(acc_cfg.idx, hw_config+4, 1);
- memcpy(bt_cfg.idx, hw_config+5, 1);
- memcpy(mcp_cfg.idx, hw_config+6, 1);
- memcpy(res2_cfg.idx, hw_config+7, 1);
- if(strcmp(lcm_cfg.idx, "1") == 0)
- strcpy(lcm_cfg.name, "hx8357c_ysm");
- else if(strcmp(lcm_cfg.idx, "2") == 0)
- strcpy(lcm_cfg.name, "hx8357d_ysm");
- else if(strcmp(lcm_cfg.idx, "3") == 0)
- strcpy(lcm_cfg.name, "hx8357d_tm");
- else if(strcmp(lcm_cfg.idx, "5") == 0)
- strcpy(lcm_cfg.name, "hx8357d_tm");
- else if(strcmp(lcm_cfg.idx, "6") == 0)
- strcpy(lcm_cfg.name, "nt35510_xxd");
- else if(strcmp(lcm_cfg.idx, "9") == 0)
- strcpy(lcm_cfg.name, "sh1282_ysm");
- else if(strcmp(lcm_cfg.idx, "a") == 0)
- strcpy(lcm_cfg.name, "rm68171_blj");
- else if(strcmp(lcm_cfg.idx, "b") == 0)
- strcpy(lcm_cfg.name, "8018b_xxd");
- else
- strcpy(lcm_cfg.name, "hx8357c_ysm");
- printk("lcm_cfg: idx=%s, name=%s\n", lcm_cfg.idx, lcm_cfg.name);
- if(strcmp(tp_cfg.idx, "1") == 0)
- strcpy(tp_cfg.name, "gsl1680_huihai");
- else if(strcmp(tp_cfg.idx, "2") == 0)
- strcpy(tp_cfg.name, "gsl1680_hefang");
- else if(strcmp(tp_cfg.idx, "3") == 0)
- strcpy(tp_cfg.name, "gsl1688e_hefang");
- else if(strcmp(tp_cfg.idx, "4") == 0)
- strcpy(tp_cfg.name, "gsl1688e_zhengxing");
- /*-------------------- for new r360 tp start --------------------*/
- else if(strcmp(tp_cfg.idx, "5") == 0)
- strcpy(tp_cfg.name, "gsl1688e_duocai_om");
- else if(strcmp(tp_cfg.idx, "6") == 0)
- strcpy(tp_cfg.name, "gsl1688e_dongyu");
- else if(strcmp(tp_cfg.idx, "7") == 0)
- strcpy(tp_cfg.name, "gsl1688e_green_gg");
- /*-------------------- for new r360 tp end --------------------*/
- /*-------------------- for r40v1 tp start --------------------*/
- else if(strcmp(tp_cfg.idx, "a") == 0)
- strcpy(tp_cfg.name, "gsl1688e_hc_ogs");
- else if(strcmp(tp_cfg.idx, "b") == 0)
- strcpy(tp_cfg.name, "gsl1688e_green40v1_gg");
- /*-------------------- for r40v1 tp end --------------------*/
- /*-------------------- for r390 tp start --------------------*/
- else if(strcmp(tp_cfg.idx, "8") == 0)
- strcpy(tp_cfg.name, "gsl1688e_chenhe");
- /*-------------------- for r390 tp end --------------------*/
- else
- strcpy(tp_cfg.name, "gsl1688e_hefang");
-
- printk("tp_cfg: idx=%s, name=%s\n", tp_cfg.idx, tp_cfg.name);
- if(strcmp(ps_cfg.idx, "1") == 0)
- strcpy(ps_cfg.name, "ltr502_2in1");
- else if(strcmp(ps_cfg.idx, "2") == 0)
- strcpy(ps_cfg.name, "epl6881_3in1");
- else if(strcmp(ps_cfg.idx, "3") == 0)
- strcpy(ps_cfg.name, "tpasps");
- else
- strcpy(ps_cfg.name, "ltr502_2in1");
- printk("ps_cfg: idx=%s, name=%s\n", ps_cfg.idx, ps_cfg.name);
- if(strcmp(acc_cfg.idx, "1") == 0)
- strcpy(acc_cfg.name, "mma7660");
- else if(strcmp(acc_cfg.idx, "2") == 0)
- strcpy(acc_cfg.name, "mc3230");
- else if(strcmp(acc_cfg.idx, "3") == 0)
- strcpy(acc_cfg.name, "stk8312");
- else
- strcpy(acc_cfg.name, "mc3230");
- printk("acc_cfg: idx=%s, name=%s\n", acc_cfg.idx, acc_cfg.name);
- if(strcmp(bt_cfg.idx, "1") == 0)
- strcpy(bt_cfg.name, "withbt");
- else if(strcmp(bt_cfg.idx, "2") == 0)
- strcpy(bt_cfg.name, "nobt");
- else
- strcpy(bt_cfg.name, "nobt");
- printk("bt_cfg: idx=%s, name=%s\n", bt_cfg.idx, bt_cfg.name);
- if(strcmp(board_cfg.idx, "1") == 0)
- strcpy(board_cfg.name, "R360");
- else if(strcmp(board_cfg.idx, "2") == 0)
- strcpy(board_cfg.name, "R360C");
- else if(strcmp(board_cfg.idx, "3") == 0)
- strcpy(board_cfg.name, "R40V1C");
- else if(strcmp(board_cfg.idx, "4") == 0)
- strcpy(board_cfg.name, "R40V1");
- else if(strcmp(board_cfg.idx, "5") == 0)
- strcpy(board_cfg.name, "R360SC");
- else if(strcmp(board_cfg.idx, "6") == 0)
- strcpy(board_cfg.name, "R360S");
- else if(strcmp(board_cfg.idx, "7") == 0)
- strcpy(board_cfg.name, "R395C");
- else if(strcmp(board_cfg.idx, "8") == 0)
- strcpy(board_cfg.name, "R395");
- else
- strcpy(board_cfg.name, "R360");
- printk("board_cfg: idx=%s, name=%s\n", board_cfg.idx, board_cfg.name);
- return 1;
- }
- __setup("cfg=", hw_configuration);
以上这段代码就是处理cmdline传过来的参数, cfg hw_configuration就是处理函数。
__setup("cfg=", hw_configuration);
关键就是这句代码, 处理函数根据自己从cmdline传过来的参数自己写。
我从cmdline传过来的参数是这样的:
"console=ttyMSM0,115200,n8 androidboot.hardware=qcom loglevel=1 cfg=H80,49b30040,018";
H80,49b30040,018 这个参数就是我的 hw_configuration 需要处理的。
mark,之前一直看__setup看不懂,还请详细解释一下这个宏。还有cmdline是什么。
你这个没有LK的代码?
你在LK中是怎么用cmdline传过来的?
你这个只是kernel的代码吧?
在aboot.c里面有个函数 boot_linux_from_flash() (我这个是nandflash版本)
emmc应该是 boot_linux_from_mmc()
我贴出代码:
- int boot_linux_from_flash(void)
- {
- struct boot_img_hdr *hdr = (void*) buf;
- unsigned n;
- struct ptentry *ptn;
- struct ptable *ptable;
- unsigned offset = 0;
- const char *cmdline;
- if (target_is_emmc_boot()) {
- hdr = (struct boot_img_hdr *)EMMC_BOOT_IMG_HEADER_ADDR;
- if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
- dprintf(CRITICAL, "ERROR: Invalid boot image header\n");
- return -1;
- }
- goto continue_boot;
- }
- ptable = flash_get_ptable();
- if (ptable == NULL) {
- dprintf(CRITICAL, "ERROR: Partition table not found\n");
- return -1;
- }
- if(!boot_into_recovery)
- {
- ptn = ptable_find(ptable, "boot");
- if (ptn == NULL) {
- dprintf(CRITICAL, "ERROR: No boot partition found\n");
- return -1;
- }
- }
- else
- {
- ptn = ptable_find(ptable, "recovery");
- if (ptn == NULL) {
- dprintf(CRITICAL, "ERROR: No recovery partition found\n");
- return -1;
- }
- }
- if (flash_read(ptn, offset, buf, page_size)) {
- dprintf(CRITICAL, "ERROR: Cannot read boot image header\n");
- return -1;
- }
- offset += page_size;
- if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
- dprintf(CRITICAL, "ERROR: Invalid boot image header\n");
- return -1;
- }
- if (hdr->page_size != page_size) {
- dprintf(CRITICAL, "ERROR: Invalid boot image pagesize. Device pagesize: %d, Image pagesize: %d\n",page_size,hdr->page_size);
- return -1;
- }
- n = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
- if (flash_read(ptn, offset, (void *)hdr->kernel_addr, n)) {
- dprintf(CRITICAL, "ERROR: Cannot read kernel image\n");
- return -1;
- }
- offset += n;
- n = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
- if (flash_read(ptn, offset, (void *)hdr->ramdisk_addr, n)) {
- dprintf(CRITICAL, "ERROR: Cannot read ramdisk image\n");
- return -1;
- }
- offset += n;
- continue_boot:
- dprintf(INFO, "\nkernel @ %x (%d bytes)\n", hdr->kernel_addr,
- hdr->kernel_size);
- dprintf(INFO, "ramdisk @ %x (%d bytes)\n", hdr->ramdisk_addr,
- hdr->ramdisk_size);
- //if(hdr->cmdline[0]) {
- // cmdline = (char*) hdr->cmdline;
- //} else {
- // cmdline = DEFAULT_CMDLINE;
- //}
- cmdline = CUSTOMIZED_CMDLINE;
- dprintf(INFO, "cmdline = '%s'\n", cmdline);
- /* TODO: create/pass atags to kernel */
-
- #ifdef WIDE_AREA
- // turn on backlight normal boot
- gpio_set(GPIO_BACKLIGHT_EN, 1);
- #endif
- dprintf(INFO, "\nBooting Linux\n");
- boot_linux((void *)hdr->kernel_addr, (void *)hdr->tags_addr,
- (const char *)cmdline, board_machtype(),
- (void *)hdr->ramdisk_addr, hdr->ramdisk_size);
- return 0;
- }
代码 79-85行,我把原来的注掉了,改成了 cmdline = CUSTOMIZED_CMDLINE;
CUSTOMIZED_CMDLINE = "console=ttyMSM0,115200,n8 androidboot.hardware=qcom loglevel=1 cfg=H80,49b30040,018";
比较靠谱 再详细点就好了
还是楼上的头像霸气
哈哈。你的也不差啊
