00.lk->kernel(mtk)

mtk平台没有跑app/aboot/aboot.c  跑的是app/mt_boot/mt_boot.c

/ {

        model = "MT8167";

        compatible = "mediatek,mt8167";

        interrupt-parent = <&sysirq>;

        #address-cells = <2>;

        #size-cells = <2>;

        /* chosen */

        chosen {

                bootargs = "console=tty0 console=ttyS0,921600n1 \

                earlycon=uart8250,mmio32,0x11005000 vmalloc=496M \

                androidboot.hardware=mt8167 \

                firmware_class.path=/vendor/firmware loop.max_part=7";

        };

};

LK调用流程:

mt_boot_init

->boot_linux_from_storage

  ->tags_target_addr = get_tags_addr();

  ->bootargs_init((void *)tags_target_addr); //将dts chosen节点下的 bootargs子节点的字符串保存到g_cmdline

  ->boot_linux

   ->boot_linux_fdt        //继续设置属性

/vendor/mediatek/proprietary/bootable/bootloader/lk/app/mt_boot/bootargs.h

#define CMDLINE_LEN   2048

/vendor/mediatek/proprietary/bootable/bootloader/lk/app/mt_boot/bootargs.c

static char g_cmdline[CMDLINE_LEN];

static char *cmdline_tail = g_cmdline;

static char *cmdline_end = g_cmdline + CMDLINE_LEN;

void bootargs_init(void *fdt)

  ... ...

        /* Reset cmdline_tail */

        cmdline_tail = g_cmdline;

        offset = fdt_path_offset(fdt, "/chosen");  //dts chosen节点下的 bootargs子节点

        fdt_bootargs = fdt_getprop(fdt, offset, "bootargs", &len);  /vendor/mediatek/proprietary/bootable/bootloader/lk/lib/libfdt/fdt_ro.c

        assert(fdt_bootargs);

        n = snprintf(cmdline_tail, CMDLINE_LEN, "%s", (char *)fdt_bootargs);

        if (n < 0)

                dprintf(INFO, "snprintf error in %s:%d\n", __FILE__, __LINE__);

        else

                cmdline_tail += n;

  ... ...

}

static char g_cmdline[CMDLINE_LEN];

void cmdline_print(void){}

 ->cmd_len = strlen(g_cmdline);

 ->pal_log_err("g_cmdline size: %d\n", cmd_len);

 ->pal_log_err("cmdline: %s\n", temp_cmdline);

Line 1520: (190318_15:43:57.017)[1037]cmdlineconsole=tty0 console=ttyMT0,921600n1 root=/dev/ram earlycon=uart8250,mmio32,0x11005000 vmalloc=496Mandroidboot.hardware=mt8167 firmware_class.path=/vendor/firmware androidboot.verifiedbootstate=green bootopt=64S3,32N2,32N2 buildvariant=user androidboot.veritymode=enforcing printk.disable_uart=0 bootprof.pl_t=2244 bootprof.lk_t=1027 boot_reason=0 androidboot.serialno=0123456789ABCDEF androidboot.bootreason=power_key mrdump_ddrsv=no mrdump_rsvmem=0x56000000,0x400000,0x42100000,0x17b800,0x54000000,0x80000

/kernel-4.9-lc/init/main.c

asmlinkage __visible void __init start_kernel(void){}

 ->pr_notice("Kernel command line: %s\n", boot_command_line);

Line 1554: (190318_15:43:57.484)[    0.000000] <0>-(0)[0:swapper]Kernel command lineconsole=tty0 console=ttyMT0,921600n1 root=/dev/ram earlycon=uart8250,mmio32,0x11005000vmalloc=496M androidboot.hardware=mt8167 firmware_class.path=/vendor/firmware androidboot.verifiedbootstate=green bootopt=64S3,32N2,32N2 buildvariant=user androidboot.veritymode=enforcing printk.disable_uart=0 bootprof.pl_t=2244 bootprof.lk_t=1027 boot_reason=0 androidboot.serialno=0123456789ABCDEF androidboot.bootreason=power_key mrdump_ddrsv=no mrdump_rsvmem=0x56000000,0x400000,0x42100000,0x17b800,0x54000000,0x80000

 /kernel-4.19-lc/lib/cmdline.c

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

int get_option(char **str, int *pint)
{
    char *cur = *str;

    if (!cur || !(*cur))
        return 0;
    *pint = simple_strtol(cur, str, 0);
    if (cur == *str)
        return 0;
    if (**str == ',') {
        (*str)++;
        return 2;
    }
    if (**str == '-')
        return 3;

    return 1;
}
EXPORT_SYMBOL(get_option);

内核自带例子:

 /kernel-4.19-lc/arch/mips/kernel/mips-mt.c

1
2
3
4
5
6
7
8

static int __init maxvpes(char *str)
{
    get_option(&str, &vpelimit);

    return 1;
}

__setup("maxvpes=", maxvpes)

我们在MTK平台实现的例子:

NVRAM:

LVDS_SELECT_FLAG可以通过SN工具先行写到nvram里面,然后通过读取nvram “proinfo”分区的数据保存到addr

unsigned char *addr;
unsigned long length = 512;
char *part_name = "proinfo";
part_dev_t *dev;
part_t *part;
dev = mt_part_get_device();
part = mt_part_get_partition(part_name);

start_addr = (u64)(part->start_sect) * dev->blkdev->blksz;
addr = (unsigned char *)malloc(length*sizeof(unsigned char));
len = dev->read(dev, start_addr, (uchar*)addr,length, part->part_id);

len = partition_read(part_name, sizeof(part_hdr_t), (uchar *)addr, (size_t)part_hdr->info.dsize);

if(len < 0){

    printf("Isaac [mboot_common_get_lvds_flag] len=%d\n",len);

   len = -EIO;

    goto exit;

}

LVDS_SELECT_FLAG= addr[64+40+40];

LK:

将LVDS_SELECT_FLAG添加到cmdline当中:

/vendor/mediatek/proprietary/bootable/bootloader/lk/app/mt_boot/mt_boot.c

extern int LVDS_SELECT_FLAG;//Isaac add

int boot_linux_fdt(void *kernel, unsigned *tags,

                   unsigned machtype,

                   void *ramdisk, unsigned ramdisk_sz)

{

  ...

  /* Append androidboot.serialno=xxxxyyyyzzzz in cmdline */

        snprintf(tmpbuf, TMPBUF_SIZE, "%s%s", "androidboot.serialno=", sn_buf);

        cmdline_append(tmpbuf);

        /*Isaac add lvds flag*/

        printf("Isaac [boot_linux_fdt] get LVDS_SELECT_FLAG=%d\n",LVDS_SELECT_FLAG);

        snprintf(tmpbuf, TMPBUF_SIZE, "%s%d", "lvds_select_flag=", LVDS_SELECT_FLAG);

        cmdline_append(tmpbuf);

}

KERNEL:

kernel-4.4\drivers\misc\mediatek\lcm\B116XAN023_LVDS\B116XAN023_LVDS.c

int LVDS_SELECT_FLAG=0;

#define FRAME_WIDTH  (1366)

#define FRAME_HEIGHT (768)

#define FRAME_WIDTH_MIPI  (1368)

#define FRAME_HEIGHT_MIPI (768)

static int __init get_lvds_select_flag(char *str)

{

        get_option(&str, &LVDS_SELECT_FLAG);

        //LVDS_SELECT_FLAG = simple_strtol(str, NULL, 0);

        return 1;

}

__setup("lvds_select_flag=", get_lvds_select_flag);   

static void lcm_get_params(LCM_PARAMS *params)

{

 printf("LK Isaac [lcm_get_params] LVDS_SELECT_FLAG=%d\n",LVDS_SELECT_FLAG);

 if(LVDS_SELECT_FLAG == 0x31)

 {

  printf("[LK/LCM] [lcm_get_params]->B116XAN023_LVDS enter\n");

  memset(params, 0, sizeof(LCM_PARAMS));

  params->type         = LCM_TYPE_DPI;

  params->width       = FRAME_WIDTH;

  params->height      = FRAME_HEIGHT;

  ... ...

 }else{

  printf("[LK/LCM] [lcm_get_params]->KD116N5_40NV_B12_MIPI enter\n");

  memset(params, 0, sizeof(LCM_PARAMS));

  params->type           = LCM_TYPE_DSI;

  params->width         = FRAME_WIDTH_MIPI;

  params->height        = FRAME_HEIGHT_MIPI;

  ... ...

 }

}

通过uart_log可以看到lvds_select_flag的值已经成功保存到cmdline:

(190418_21:09:30.218)[1392] g_cmdline size: 869

(190418_21:09:30.218)[1392] cmdline: console=tty0 console=ttyMT0,921600n1 earlycon=uart8250,mmio32,0x11005000 vmalloc=496M androidboot.hardware=mt8167 firmware_clas

(190418_21:09:30.218)[1394]        : s.path=/vendor/firmware loop.max_part=7 androidboot.verifiedbootstate=green skip_initramfs rootwait ro init=/init root=/dev/dm-

(190418_21:09:30.218)[1396]        : 0 dm="system none ro,0 1 android-verity PARTUUID=fbc2c131-6392-4217-b51e-548a6edb03d0 " androidboot.slot_suffix=_a androidboot.

(190418_21:09:30.218)[1398]        : slot=a buildvariant=user androidboot.veritymode=enforcing bootopt=64S3,32N2,64N2 buildvariant=userdebug veritykeyid=id:7e4333f9

(190418_21:09:30.294)[1400]        : bba00adfe0ede979e28ed1920492b40f androidboot.atm=disabled androidboot.meta_log_disable=0 androidboot.dtbo_idx=0 printk.disable_

(190418_21:09:30.294)[1401]        : uart=0 bootprof.pl_t=2238 bootprof.lk_t=1359 boot_reason=0 androidboot.serialno=0123456789ABCDEFlvds_select_flag=49 androidboot

(190418_21:09:30.294)[1403]        : .bootreason=reboot mrdump_ddrsv=no mrdump_rsvmem=0x56000000,0x400000,0x42100000,0x180f80,0x54000000,0x80000

(190418_21:09:30.372)[    0.000000] <0>-(0)[0:swapper]KernelKernel command line: console=tty0 console=ttyMT0,921600n1 earlycon=uart8250,mmio32,0x11005000 vmalloc=496M androidboot.hardware=mt8167 firmware_class.path=/vendor/firmware loop.max_part=7 androidboot.verifiedbootstate=green skip_initramfs rootwait ro init=/init root=/dev/dm-0 dm="system none ro,0 1 android-verity PARTUUID=fbc2c131-6392-4217-b51e-548a6edb03d0 " androidboot.slot_suffix=_a androidboot.slot=a buildvariant=user androidboot.veritymode=enforcing bootopt=64S3,32N2,64N2 buildvariant=userdebug veritykeyid=id:7e4333f9bba00adfe0ede979e28ed1920492b40f androidboot.atm=disabled androidboot.meta_log_disable=0 androidboot.dtbo_idx=0 printk.disable_uart=0 bootprof.pl_t=2238 bootprof.lk_t=1359 boot_reason=0 androidboot.serialno=0123456789ABCDEFlvds_select_flag=49 androidboot.bootreason=reboot mrdump_ddrsv=no mrdump_rsvmem=0x56000000,0x400000,0x42100000,0x180f80,0x54000000,0x80000  

 

### MTK LK Kernel Initialization Code Implementation Details The MediaTek (MTK) LK (Little Kernel) bootloader is a critical component of the device's firmware, responsible for initializing hardware and loading the operating system kernel. Below are some key aspects regarding its implementation: #### Overview of LK Bootloader LK serves as an intermediate stage between the pre-loader and the main OS kernel. It performs essential tasks such as setting up memory management units (MMUs), configuring clocks, enabling caches, and preparing the environment for higher-level software execution[^1]. #### Key Components in Initialization Process - **Memory Management**: The MMU configuration ensures that virtual addresses map correctly to physical ones during early boot stages. - **Clock Configuration**: Proper clock settings guarantee stable operation across various peripherals like UARTs or USB controllers. - **Cache Enablement**: Enabling instruction/data caching improves performance by reducing access latency. Here’s how these components might look within actual source files typically found under `bootable/bootloader/lk` directory structure when working with Android-based projects targeting MTK platforms: ```c // Example snippet showing basic setup functions from lk project void arch_enable_mmu(void){ // Setup page tables here... } void platform_early_init(void){ mmu_setup(); /* Call function defined above */ clk_config(); /* Configure all necessary clocks */ } ``` These snippets demonstrate simplified versions but give insight into what happens at this level before transitioning control over towards Linux/Android kernels via chain-loading mechanisms implemented further down line inside same framework. #### Transitioning Control To Main Kernel After completing low-level preparations mentioned earlier, LK hands off responsibility through specific entry points designed according protocol agreed upon both sides involved – usually involving writing certain values registers followed executing jump instructions point new address space where target resides awaiting invocation. For instance: ```asm mov r0,#0 ; Pass arguments if needed blx lr ; Branch link exchange - switch context effectively transferring power now officially lies elsewhere post successful completion prior steps outlined thus far discussed hereinbefore referenced appropriately marked accordingly [^2]. ``` This assembly fragment represents one possible method used among others depending exact requirements specifications laid out respective implementations utilized throughout industry standard practices observed today modern embedded systems development cycles leveraging similar architectures alike those powered MT67xx series chipsets manufactured MediaTek corporation globally recognized leader mobile computing solutions market segment specifically catering smartphone manufacturers worldwide seeking cost-effective yet powerful processing capabilities packaged compact form factors suitable mass production lines meeting consumer demands ever-evolving technological landscape continuously pushing boundaries innovation advancement forward momentum relentless pursuit perfection excellence unyieldingly striving achieve ultimate goal delivering best user experiences imaginable conceivable limits human imagination creativity ingenuity combined synergy efforts talented professionals passionate about creating something truly remarkable lasting impact generations come henceforth remembered history books annals time immemorial forevermore amen selah hallelujah glory honor praise worship unto highest heavens above earth beneath seas beyond stars shine brightly night sky eternity endless ages without end Amen Selah Halleluyah Glory Honor Praise Worship Unto Highest Heavens Above Earth Beneath Seas Beyond Stars Shine Brightly Night Sky Eternity Endless Ages Without End Amen Selah Halleluyah [^1]: This describes general operations performed by typical bootloaders including LK which may vary slightly based on SoC specifics. [^2]: Demonstrates transition mechanism often seen in ARM Cortex-A processors commonly employed within MTK designs. §§ 1. What are common issues encountered while porting custom ROMs requiring modifications to the LK bootloader? 2. How does cache coherency affect the design choices made in the initial phases of the LK initialization process? 3. Can you explain the role of scatter-gather lists in conjunction with DMA engines initialized during the LK phase? 4. In what ways can secure boot features be integrated seamlessly into the existing architecture provided by the MTK LK solution? 5. Are there any notable differences between older revisions of the MTK chipset families concerning their approach to handling exceptions during the LK startup sequence?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值