121.rk3399 uboot(2017.09) 源码分析1(2024-09-05)
参考源码 : uboot(2017.09)
硬件平台:rk3399
辅助工具:linux虚拟机,sourceinsight4,文件浏览器(可以使用samba访问),ultraeidt(查看bin文件比较方便)
说明:
1.本文是源码分析的第一篇,但是不涉及汇编部分的分析。(汇编部分自行百度)
2.由于作者水平有限,错误之处在所难免,请高手及时指正,不胜感激。其实也算是第一次阅读源码,肯定还是有很多的局限,请包含。
零、汇编阶段
0.1 start.S 文件
一般入口都是start.S,不同的平台,对应这个不同的start.S文件,这个必须要找对。
rk3399是armv8的架构,这里看上去,就是这和个armv8下的这个文件了。
同时把uboot源码编译之后,到该目录下,一定可以看到对应的.o文件,就说明是这个文件无疑了。
有兴趣的小伙伴可以认真分析这个文件的启动过程。我就直接略过了。
164行,跳转到_main. (可能是c的入口,也可能不是)
用sourceinsight的搜索直接搜,找到crt0_64.S文件中。
0.2 crt0_64.S文件
board_init_f 是一个比较熟悉的名字,估计就是c的入口了。
通过搜索(为方便截图,我删除了很多无用的结果),有3个可疑的结果,可以到目录中查看是否有对应的.o文件判断。
arch\arm\mach-rockchip 目录下这两个文件没有对应的o文件
board_f是存在o文件的,所以肯定是使用了这个文件的board_init_f
0.3 board_f.c 文件
这个便是我要找的c的入口文件。common目录下。
一、c的入口 board_init_f
1.1 board_init_f 的参数为0
首先gd->flags 的值应该就是0了,应该就是初始化吧,目前我还不确定flags有哪些意义。
在文件中有flag相关的宏定义
void board_init_f(ulong boot_flags)
{gd->flags = boot_flags;gd->have_console = 0;#if defined(CONFIG_DISABLE_CONSOLE)gd->flags |= GD_FLG_DISABLE_CONSOLE;
#endifif (initcall_run_list(init_sequence_f))hang();#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \!defined(CONFIG_EFI_APP) && !CONFIG_IS_ENABLED(X86_64)/* NOTREACHED - jump_to_copy() does not return */hang();
#endif
}#if defined(CONFIG_X86) || defined(CONFIG_ARC)
/** For now this code is only used on x86.** init_sequence_f_r is the list of init functions which are run when* U-Boot is executing from Flash with a semi-limited 'C' environment.* The following limitations must be considered when implementing an* '_f_r' function:* - 'static' variables are read-only* - Global Data (gd->xxx) is read/write** The '_f_r' sequence must, as a minimum, copy U-Boot to RAM (if* supported). It _should_, if possible, copy global data to RAM and* initialise the CPU caches (to speed up the relocation process)** NOTE: At present only x86 uses this route, but it is intended that* all archs will move to this when generic relocation is implemented.*/
static const init_fnc_t init_sequence_f_r[] = {
#if !CONFIG_IS_ENABLED(X86_64)init_cache_f_r,
#endifNULL,
};
这里主要就是initcall_run_list 这个函数,执行了一个init_sequence_f数组中的初始化函数列表,如果initcall_run_list返回值不为0,则程序卡死。
看到hang函数中最后的死循环。
void hang(void)
{
#if !defined(CONFIG_SPL_BUILD) || (defined(CONFIG_SPL_LIBCOMMON_SUPPORT) && \defined(CONFIG_SPL_SERIAL_SUPPORT))puts("### ERROR ### Please RESET the board ###\n");
#endifbootstage_error(BOOTSTAGE_ID_NEED_RESET);
#ifdef CONFIG_SPL_BUILDspl_hang_reset();
#endiffor (;;);
}
1.2 initcall_run_list函数
DECLARE_GLOBAL_DATA_PTR;#define TICKS_TO_US(ticks) ((ticks) / (COUNTER_FREQUENCY / 1000000))
#define US_TO_MS(ticks) ((ticks) / 1000)
#define US_TO_US(ticks) ((ticks) % 1000)#ifdef DEBUG
static inline void call_get_ticks(ulong *ticks) { *ticks = get_ticks(); }
#else
static inline void call_get_ticks(ulong *ticks) { }
#endifint initcall_run_list(const init_fnc_t init_sequence[])
{const init_fnc_t *init_fnc_ptr;ulong start = 0, end = 0, sum = 0;if (!gd->sys_start_tick) //如果是0,表示第一次进来gd->sys_start_tick = get_ticks(); //获取当前的ticksfor (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { //循环执行数组中的函数unsigned long reloc_ofs = 0;int ret;if (gd->flags & GD_FLG_RELOC) //是否重定位reloc_ofs = gd->reloc_off; //在全局gd中保存了偏移量
#ifdef CONFIG_EFI_APP //这个没有定义,不关心reloc_ofs = (unsigned long)image_base;
#endifdebug("initcall: %p", (char *)*init_fnc_ptr - reloc_ofs); //输出debug信息if (gd->flags & GD_FLG_RELOC)debug(" (relocated to %p)\n", (char *)*init_fnc_ptr);elsedebug("\n");call_get_ticks(&start); //start记录开始的时间ret = (*init_fnc_ptr)(); //执行函数call_get_ticks(&end); //end记录结束的时间if (start != end) {sum = TICKS_TO_US(end - gd->sys_start_tick);debug("\t\t\t\t\t\t\t\t#%8ld us #%4ld.%3ld ms\n",TICKS_TO_US(end - start), US_TO_MS(sum), US_TO_US(sum)); //输出调试信息,函数执行的时间,还有总时间}if (ret) { //如果函数的返回值不为0,则表示出错,输出出错信息,并且不再执行数组后面的函数,函数返回后,执行hang函数,程序卡死printf("initcall sequence %p failed at call %p (err=%d)\n",init_sequence,(char *)*init_fnc_ptr - reloc_ofs, ret);return -1;}}return 0; //所有的函数都执行正常,则返回0,表示程序可以继续进行
}
1.2.1 get_ticks函数
到目录中查看.o文件判断是否是哪一个。
在lib目录中也有定义,并且这个文件也被编译了。
但是它被宏定义控制了。而且宏定义没有定义
else 有__weak 属性,这个基本可以确定了 。
__weak 表示如果没有其他地方定义,则使用这个函数,如果在其他地方有定义,则该函数失效。
由编译器控制的。
1.3 init_sequence_f初始化函数数组
先对每一个函数编个号吧,总共73个,如果没编错的话。
其中有好几个是喂狗,等会就直接跳过了。
还有很多跟配置相关,不一定都会执行到。
接下来就要一一来看这些初始化干了啥。
static const init_fnc_t init_sequence_f[] = {//1.setup_mon_len,
#ifdef CONFIG_OF_CONTROL//2.fdtdec_setup,
#endif
#ifdef CONFIG_TRACE//3.trace_early_init,
#endif//4.initf_malloc,//5.log_init,//6.initf_bootstage, /* uses its own timer, so does not need DM *///7.initf_console_record,
#if defined(CONFIG_HAVE_FSP)//8.arch_fsp_init,
#endif//9.arch_cpu_init, /* basic arch cpu dependent setup *///10.mach_cpu_init, /* SoC/machine dependent CPU setup *///11.initf_dm,//12.arch_cpu_init_dm,
#if defined(CONFIG_BOARD_EARLY_INIT_F)//13.board_early_init_f,
#endif
#if defined(CONFIG_PPC) || defined(CONFIG_SYS_FSL_CLK) || defined(CONFIG_M68K)/* get CPU and bus clocks according to the environment variable *///14.get_clocks, /* get CPU and bus clocks (etc.) */
#endif
#if !defined(CONFIG_M68K)//15.timer_init, /* initialize timer */
#endif
#if defined(CONFIG_BOARD_POSTCLK_INIT)//16.board_postclk_init,
#endif//17.env_init, /* initialize environment *///18.init_baud_rate, /* initialze baudrate settings *///19.serial_init, /* serial communications setup *///20.console_init_f, /* stage 1 init of console *///21.display_options, /* say that we are here *///22.display_text_info, /* show debugging info if required */
#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SH) || \defined(CONFIG_X86)//23.checkcpu,
#endif
#if defined(CONFIG_DISPLAY_CPUINFO)//24.print_cpuinfo, /* display cpu info (and speed) */
#endif
#if defined(CONFIG_DTB_RESELECT)//25.embedded_dtb_select,
#endif
#if defined(CONFIG_DISPLAY_BOARDINFO)//26.show_board_info,
#endif//27.INIT_FUNC_WATCHDOG_INIT
#if defined(CONFIG_MISC_INIT_F)//28.misc_init_f,
#endif//29.INIT_FUNC_WATCHDOG_RESET
#if defined(CONFIG_SYS_I2C)//30.init_func_i2c,
#endif
#if defined(CONFIG_HARD_SPI)//31.init_func_spi,
#endif
#if defined(CONFIG_ROCKCHIP_PRELOADER_SERIAL)//32.announce_pre_serial,
#endif//33.announce_dram_init,//34.dram_init, /* configure available RAM banks */
#ifdef CONFIG_POST//35.post_init_f,
#endif//36.INIT_FUNC_WATCHDOG_RESET
#if defined(CONFIG_SYS_DRAM_TEST)//37.testdram,
#endif /* CONFIG_SYS_DRAM_TEST *///38.INIT_FUNC_WATCHDOG_RESET#ifdef CONFIG_POST//39.init_post,
#endif//40.INIT_FUNC_WATCHDOG_RESET/** Now that we have DRAM mapped and working, we can* relocate the code and continue running from DRAM.** Reserve memory at end of RAM for (top down in that order):* - area that won't get touched by U-Boot and Linux (optional)* - kernel log buffer* - protected RAM* - LCD framebuffer* - monitor code* - board info struct*///41.setup_dest_addr,
#ifdef CONFIG_PRAM//42.reserve_pram,
#endif//43.reserve_round_4k,
#ifdef CONFIG_ARM//44. reserve_mmu,
#endif//45.reserve_video,//46.reserve_trace,//47.reserve_uboot,//48.reserve_malloc,
#ifdef CONFIG_SYS_NONCACHED_MEMORY//49.reserve_noncached,
#endif//50.reserve_board,//51.setup_machine,//52.reserve_global_data,//53.reserve_fdt,//54.reserve_bootstage,//55.reserve_arch,//56.reserve_stacks,//57.dram_init_banksize,//58.show_dram_config,
#ifdef CONFIG_SYSMEM//59.sysmem_init, /* Validate above reserve memory */
#endif
#if defined(CONFIG_M68K) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \defined(CONFIG_SH)//60.setup_board_part1,
#endif
#if defined(CONFIG_PPC) || defined(CONFIG_M68K)//61.INIT_FUNC_WATCHDOG_RESET//62.setup_board_part2,
#endif//63.display_new_sp,
#ifdef CONFIG_OF_BOARD_FIXUP//64.fix_fdt,
#endif//65.INIT_FUNC_WATCHDOG_RESET//66.reloc_fdt,//67.reloc_bootstage,//68.setup_reloc,
#if defined(CONFIG_X86) || defined(CONFIG_ARC)//69.copy_uboot_to_ram,//70.do_elf_reloc_fixups,//71.clear_bss,
#endif
#if defined(CONFIG_XTENSA)//72.clear_bss,
#endif
#if !defined(CONFIG_ARM) && !defined(CONFIG_SANDBOX) && \!CONFIG_IS_ENABLED(X86_64)//73.jump_to_copy,
#endif//74.NULL,
};
1.3.1 setup_mon_len
应该就是执行__ARM__宏定义的这个部分,
gd->mon_len 应该是uboot.bin的大小,暂时这么理解吧。bin文件一般不包含bss段,所以这个长度应该比bin文件的大小还要大一些。
static int setup_mon_len(void)
{
#if defined(__ARM__) || defined(__MICROBLAZE__)gd->mon_len = (ulong)&__bss_end - (ulong)_start; //这应该就是执行文件的二进制长度
#elif defined(CONFIG_SANDBOX) || defined(CONFIG_EFI_APP)gd->mon_len = (ulong)&_end - (ulong)_init;
#elif defined(CONFIG_NIOS2) || defined(CONFIG_XTENSA)gd->mon_len = CONFIG_SYS_MONITOR_LEN;
#elif defined(CONFIG_NDS32) || defined(CONFIG_SH) || defined(CONFIG_RISCV)gd->mon_len = (ulong)(&__bss_end) - (ulong)(&_start);
#elif defined(CONFIG_SYS_MONITOR_BASE)/* TODO: use (ulong)&__bss_end - (ulong)&__text_start; ? */gd->mon_len = (ulong)&__bss_end - CONFIG_SYS_MONITOR_BASE;
#endifreturn 0;
}
1.3.2 fdtdec_setup (lib/fdtdec.c)
这个函数受到配置CONFIG_OF_CONTROL的影响,si中可以看到这个宏被定义了,那这个函数会执行。
int fdtdec_setup(void)
{
#if CONFIG_IS_ENABLED(OF_CONTROL) //定义了宏CONFIG_OF_CONTROL
# if CONFIG_IS_ENABLED(MULTI_DTB_FIT) //这个没有定义void *fdt_blob;
# endif
# ifdef CONFIG_OF_EMBED/* Get a pointer to the FDT */
# ifdef CONFIG_SPL_BUILDgd->fdt_blob = __dtb_dt_spl_begin;
# elsegd->fdt_blob = __dtb_dt_begin;
# endif //# ifdef CONFIG_SPL_BUILD
# elif defined CONFIG_OF_SEPARATE //这个宏定义了
# ifdef CONFIG_SPL_BUILD //这个没有定义/* FDT is at end of BSS unless it is in a different memory region */if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))gd->fdt_blob = (ulong *)&_image_binary_end;elsegd->fdt_blob = (ulong *)&__bss_end;
# else //执行这里/* FDT is at end of image */gd->fdt_blob = (ulong *)&_end; //在uboot的镜像后面放在dtc文件,现在获取地址# ifdef CONFIG_USING_KERNEL_DTB //这个宏定义了,表示使用内核里面的dtc文件gd->fdt_blob_kern = (ulong *)((ulong)gd->fdt_blob + //使用对齐方式获取内核dtc文件的地址????ALIGN(fdt_totalsize(gd->fdt_blob), 8));
# endif //# ifdef CONFIG_USING_KERNEL_DTB
# endif //# ifdef CONFIG_SPL_BUILD
# elif defined(CONFIG_OF_BOARD) //这个宏没有定义/* Allow the board to override the fdt address. */gd->fdt_blob = board_fdt_blob_setup();
# elif defined(CONFIG_OF_HOSTFILE) //这个宏没有定义if (sandbox_read_fdt_from_file()) {puts("Failed to read control FDT\n");return -1;}
# endif //# ifdef CONFIG_OF_EMBED
# ifndef CONFIG_SPL_BUILD //这个没有定义/* Allow the early environment to override the fdt address */gd->fdt_blob = (void *)env_get_ulong("fdtcontroladdr", 16,(uintptr_t)gd->fdt_blob);
# endif //# ifndef CONFIG_SPL_BUILD # if CONFIG_IS_ENABLED(MULTI_DTB_FIT) //这个没有定义/** Try and uncompress the blob.* Unfortunately there is no way to know how big the input blob really* is. So let us set the maximum input size arbitrarily high. 16MB* ought to be more than enough for packed DTBs.*/if (uncompress_blob(gd->fdt_blob, 0x1000000, &fdt_blob) == 0)gd->fdt_blob = fdt_blob;/** Check if blob is a FIT images containings DTBs.* If so, pick the most relevant*/fdt_blob = locate_dtb_in_fit(gd->fdt_blob);if (fdt_blob)gd->fdt_blob = fdt_blob;
# endif
#endif //#if CONFIG_IS_ENABLED(OF_CONTROL) //结束return fdtdec_prepare_fdt(); //预分析dtc文件,判断该文件是否存在
}
从打开的uboot.bin来看,这个文件后面的部分确实包含了一个dtc文件的内容(用ultraedit打开)。
看样子还得研究一下uboot.bin 和uboot.img的组成啊。(先挖个坑吧,看了一下make.sh还是比较复杂)
1.3.2.1 fdtdec_prepare_fdt(lib/fdtdec.c)
fdt_blob 不为空,,所以取反后为0
fdt_blob&3 ,判断最低2位是否为0,4字节对齐? 先假设对齐吧(这个地方不太确定是哪个值)。
执行fdt_check_header
int fdtdec_prepare_fdt(void)
{if (!gd->fdt_blob || ((uintptr_t)gd->fdt_blob & 3) || //fdt_blob 指针不为NULL,执行fdt_check_headerfdt_check_header(gd->fdt_blob)) {
#ifdef CONFIG_SPL_BUILDputs("Missing DTB\n");
#elseputs("No valid device tree binary found - please append one to U-Boot binary, use u-boot-dtb.bin or define CONFIG_OF_EMBED. For sandbox, use -d <file.dtb>\n");
# ifdef DEBUGif (gd->fdt_blob) {printf("fdt_blob=%p\n", gd->fdt_blob);print_buffer((ulong)gd->fdt_blob, gd->fdt_blob, 4,32, 0);}
# endif
#endifreturn -1;}return 0;
}
1.3.2.1.1 fdt_check_header(script/dtc//libfdt/fdt.c)
找到magic,跟上面得图片对比了一下,确实存在。而且存放的格式为大端模式
int fdt_check_header(const void *fdt)
{if (fdt_magic(fdt) == FDT_MAGIC) { //FDT_MAGIC 0xd00dfeed/* Complete tree */if (fdt_version(fdt) < FDT_FIRST_SUPPORTED_VERSION) //FDT_FIRST_SUPPORTED_VERSION 0x10return -FDT_ERR_BADVERSION;if (fdt_last_comp_version(fdt) > FDT_LAST_SUPPORTED_VERSION) //FDT_LAST_SUPPORTED_VERSION 0x11return -FDT_ERR_BADVERSION;} else if (fdt_magic(fdt) == FDT_SW_MAGIC) { //FDT_SW_MAGIC (~FDT_MAGIC)/* Unfinished sequential-write blob */if (fdt_size_dt_struct(fdt) == 0)return -FDT_ERR_BADSTATE;} else {return -FDT_ERR_BADMAGIC;}return 0;
}
下图中标出来的为fdt_version和fdt_last_comp_version。根据结构体的成员排列顺序。
比较后,返回0,没啥问题。
如果uboot启动该时出错打印:
"No valid device tree binary found - please append one to U-Boot binary, use u-boot-dtb.bin or define CONFIG_OF_EMBED. For sandbox, use -d <file.dtb>\n"
就说明uboot本身没有包含dtb文件,所以需要使用包含dtb文件的uboot启动。
这一步做完之后:
gd->fdt_blob 指向dtb文件的位置
gd->fdt_blob_kern 执行等于 gd->fdt_blob + 长度,然后8字节对齐。可能这个值等于NULL。
经过计算,这个值正好到了uboot.bin的最后。
0xe69e8+0x2806=0xe91ee,8字节对齐,取值0xe91f0.
1.3.3 trace_early_init
CONFIG_TRACE 宏未定义,不执行,略。
1.3.4 initf_malloc (common/dlmalloc.c)
在.config 中找到设置CONFIG_SYS_MALLOC_F_LEN=0x4000 (16KB)
对gd->malloc_limit 和gd->malloc_ptr 进行初始化赋值。
gd->malloc_base,看注释,这个应该在汇编中已经赋值了,先不管了。
int initf_malloc(void)
{
#if CONFIG_VAL(SYS_MALLOC_F_LEN)assert(gd->malloc_base); /* Set up by crt0.S */gd->malloc_limit = CONFIG_VAL(SYS_MALLOC_F_LEN);gd->malloc_ptr = 0;
#endifreturn 0;
}
1.3.5 log_init (common/log.c)
ll_entry_start(struct log_driver, log_driver); 是个宏定义。
#define ll_entry_start(_type, _list) \
({ \
static char start[0] __aligned(4) __attribute__((unused, \
section(".u_boot_list_2_"#_list"_1"))); \
(_type *)&start; \
})
似乎是要找到u_boot_list_2_log_driver_1 这个段的所有成员。
int log_init(void)
{struct log_driver *drv = ll_entry_start(struct log_driver, log_driver);const int count = ll_entry_count(struct log_driver, log_driver);struct log_driver *end = drv + count;/** We cannot add runtime data to the driver since it is likely stored* in rodata. Instead, set up a 'device' corresponding to each driver.* We only support having a single device.*/INIT_LIST_HEAD((struct list_head *)&gd->log_head);while (drv < end) {struct log_device *ldev;ldev = calloc(1, sizeof(*ldev));if (!ldev) {debug("%s: Cannot allocate memory\n", __func__);return -ENOMEM;}INIT_LIST_HEAD(&ldev->filter_head);ldev->drv = drv;list_add_tail(&ldev->sibling_node,(struct list_head *)&gd->log_head);drv++;}gd->flags |= GD_FLG_LOG_READY;gd->default_log_level = LOGL_INFO;return 0;
}
用文本编辑器(我是sublime),打开System.map文件
看到了一些u_boot_list_2_开头的一些名字,但是log_driver确实没有。
只搜索log_driver关键字,也没有任何结果,就说明没有相关的定义。(暂时这么理解)
drv = NULL;
count = 0;
end = NULL;
gd->log_head 队列初始化完成,里面应该出来头,应该其他都是空。
while循环不需要执行
gd->flags |= GD_FLG_LOG_READY; //设置flag
gd->default_log_level = LOGL_INFO; //默认打印等级为info
我猜测:
这里应该是不同的打印等级有一个log_driver,但是uboot实际没有用到这个打印等级。
1.3.6 initf_bootstage(common/board_f.c)
/* Record the board_init_f() bootstage (after arch_cpu_init()) */
static int initf_bootstage(void)
{bool from_spl = IS_ENABLED(CONFIG_SPL_BOOTSTAGE) &&IS_ENABLED(CONFIG_BOOTSTAGE_STASH); //两个宏都没有定义,值为0int ret;ret = bootstage_init(!from_spl); //参数为1if (ret)return ret;if (from_spl) { //if不能执行const void *stash = map_sysmem(CONFIG_BOOTSTAGE_STASH_ADDR,CONFIG_BOOTSTAGE_STASH_SIZE);ret = bootstage_unstash(stash, CONFIG_BOOTSTAGE_STASH_SIZE);if (ret && ret != -ENOENT) {debug("Failed to unstash bootstage: err=%d\n", ret);return ret;}}bootstage_mark_name(BOOTSTAGE_ID_START_UBOOT_F, "board_init_f");return 0;
}
from_spl 应该是0.宏没有被定义
先看看bootstage_init函数
1.3.6.1 bootstage_init
int bootstage_init(bool first)
{struct bootstage_data *data;int size = sizeof(struct bootstage_data);gd->bootstage = (struct bootstage_data *)malloc(size); //分配空间if (!gd->bootstage)return -ENOMEM;data = gd->bootstage; //用data指针操作memset(data, '\0', size); //全部清零if (first) { //这个为1data->next_id = BOOTSTAGE_ID_USER; //gd->bootstage->next_id 设置一个值bootstage_add_record(BOOTSTAGE_ID_AWAKE, "reset", 0, 0); //增加一条记录?}return 0;
}
目前看到是gd->bootstage 里面增加了一条记录(rec).
不知道这个记录有啥用,后面再看吧。
RECORD_COUNT 这个等于宏定义(配置的)CONFIG_BOOTSTAGE_RECORD_COUNT 为30
也就说,最多可以记录30条。
1.3.6.1.1 bootstage_add_record
ulong bootstage_add_record(enum bootstage_id id, const char *name,int flags, ulong mark) //flags 等于0 ,mark也是0
{struct bootstage_data *data = gd->bootstage;struct bootstage_record *rec;if (flags & BOOTSTAGEF_ALLOC) //这个if不成立id = data->next_id++;/* Only record the first event for each */rec = find_id(data, id); //去gd->bootstage里面 找id = BOOTSTAGE_ID_AWAKE 记录 ,应该是没有,因为刚刚全部清零了。if (!rec && data->rec_count < RECORD_COUNT) { //不存在,则记录该idrec = &data->record[data->rec_count++];rec->time_us = mark; //0rec->name = name; //name = "board_init_f"rec->flags = flags; //0rec->id = id; //id = BOOTSTAGE_ID_AWAKE}/* Tell the board about this progress */show_boot_progress(flags & BOOTSTAGEF_ERROR ? -id : id); //目前看到是个空函数,可以自己定义return mark;
}
1.3.7 initf_console_record(common/board_f.c)
static int initf_console_record(void)
{
#if defined(CONFIG_CONSOLE_RECORD) && CONFIG_VAL(SYS_MALLOC_F_LEN) //CONFIG_CONSOLE_RECORD未定义return console_record_init();
#elsereturn 0; //空函数,返回0
#endif
}
1.3.8 arch_fsp_init
宏未定义,直接跳过。
1.3.9 arch_cpu_init (arch/arm/mach-rockchip/rk3399/rk3399.c)
跟具体的cpu相关,那就只能是这个文件了。
我是根据它自带的注释翻译了一把,不知对错,
这里就是设置了几个寄存器,具体影响未知。
#define GRF_BASE 0xff770000
#define PMUGRF_BASE 0xff320000
#define PMUSGRF_BASE 0xff330000
#define PMUCRU_BASE 0xff750000
#define NIU_PERILP_NSP_ADDR 0xffad8188
#define QOS_PRIORITY_LEVEL(h, l) ((((h) & 3) << 8) | ((l) & 3))int arch_cpu_init(void)
{struct rk3399_pmugrf_regs *pmugrf = (void *)PMUGRF_BASE; //寄存器地址struct rk3399_grf_regs * const grf = (void *)GRF_BASE; //基地址/* We do some SoC one time setting here. */#ifdef CONFIG_SPL_BUILD //未定义,不执行struct rk3399_pmusgrf_regs *sgrf = (void *)PMUSGRF_BASE;/** Disable DDR and SRAM security regions.** As we are entered from the BootROM, the region from* 0x0 through 0xfffff (i.e. the first MB of memory) will* be protected. This will cause issues with the DW_MMC* driver, which tries to DMA from/to the stack (likely)* located in this range.*/rk_clrsetreg(&sgrf->ddr_rgn_con[16], 0x1ff, 0);rk_clrreg(&sgrf->slv_secure_con4, 0x2000);
#endif/* eMMC clock generator: disable the clock multipilier */rk_clrreg(&grf->emmccore_con[11], 0x0ff); //emmc的控制器,禁止时钟倍频/* PWM3 select pwm3a io */rk_clrreg(&pmugrf->soc_con0, 1 << 5); //pwm3 选择pwm3a 输出#if defined(CONFIG_ROCKCHIP_RK3399PRO) //不是rk3399pro,不执行struct rk3399_pmucru *pmucru = (void *)PMUCRU_BASE;/* set wifi_26M to 24M and disabled by default */writel(0x7f002000, &pmucru->pmucru_clksel[1]);writel(0x01000100, &pmucru->pmucru_clkgate_con[0]);
#endif/* Set perilp_nsp QOS priority to 3 for USB 3.0 */writel(QOS_PRIORITY_LEVEL(3, 3), NIU_PERILP_NSP_ADDR); //设置usb3.0的特性return 0;
}
1.3.10 mach_cpu_init
weak定义,空函数
1.3.11 initf_dm (common/board_f.c)
static int initf_dm(void)
{
#if defined(CONFIG_DM) && CONFIG_VAL(SYS_MALLOC_F_LEN) //有定义int ret;bootstage_start(BOOTSTATE_ID_ACCUM_DM_F, "dm_f"); //bootstage 记录BOOTSTATE_ID_ACCUM_DM_Fret = dm_init_and_scan(true); //有点长,下文继续解释bootstage_accum(BOOTSTATE_ID_ACCUM_DM_F); //更新记录的时间if (ret)return ret;
#endif
#ifdef CONFIG_TIMER_EARLY //未定义,不执行ret = dm_timer_init();if (ret)return ret;
#endifreturn 0;
}
1.3.11.1 dm_init_and_scan (drivers/core/root.c)
参数 pre_reloc_only 为true
int dm_init_and_scan(bool pre_reloc_only)
{int ret;ret = dm_init(IS_ENABLED(CONFIG_OF_LIVE));if (ret) {debug("dm_init() failed: %d\n", ret);return ret;}ret = dm_scan_platdata(pre_reloc_only);if (ret) {debug("dm_scan_platdata() failed: %d\n", ret);return ret;}if (CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)) {ret = dm_extended_scan_fdt(gd->fdt_blob, pre_reloc_only);if (ret) {debug("dm_extended_scan_dt() failed: %d\n", ret);return ret;}}ret = dm_scan_other(pre_reloc_only);if (ret)return ret;return 0;
}
刚刚稍微浏览了一下,有点复杂,要不留到下篇文章吧。
写了两天有点长。