当前位置: 首页 > news >正文

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;
}

刚刚稍微浏览了一下,有点复杂,要不留到下篇文章吧。

写了两天有点长。

相关文章:

121.rk3399 uboot(2017.09) 源码分析1(2024-09-05)

参考源码 : uboot&#xff08;2017.09&#xff09; 硬件平台&#xff1a;rk3399 辅助工具&#xff1a;linux虚拟机&#xff0c;sourceinsight4&#xff0c;文件浏览器&#xff08;可以使用samba访问&#xff09;&#xff0c;ultraeidt(查看bin文件比较方便) 说明&#xff1a…...

【图论】虚树 - 模板总结

适用于解决一棵树中只需要用到少部分点的时候&#xff0c;将需要用到的点提出来单独建一棵树 /********************* 虚树 *********************/ struct edge {int to, next;int val; };struct Virtual_Tree {int n; // 点数int dfn[N]; // dfs序int dep[N]; // 深度int fa…...

[C#学习笔记]注释

官方文档&#xff1a;Documentation comments - C# language specification | Microsoft Learn 一、常用标记总结 1.1 将文本设置为代码风格的字体&#xff1a;<c> 1.2 源代码或程序输出:<code> 1.3 异常指示:<exception> 1.4 段落 <para> 1.5 换行&…...

c# checkbox的text文字放到右边

checkbox的text文字放到右边 实现方法如下图 特此记录 anlog 2024年9月2日...

【node.js】基础之修改文件

node.js 基础(一) node.js是什么&#xff1f; 上面这句话的意思就是&#xff1a;Node.js 是一个开源的&#xff0c;跨平台的javascript运行环境。通俗的说就是一个应用程序或者说是一个软件&#xff0c;可以运行javascript。 Node.js的作用&#xff1a; 开发服务器应用。 将数…...

Notepad++回车不自动补全

问题 使用Notepad时&#xff0c;按回车经常自动补全&#xff0c;但我们希望回车进行换行&#xff0c;而不是自动补全&#xff0c;而且自动补全使用Tab进行补全足够了。下文介绍设置方法。 设置方法 打开Notepad&#xff0c;进入设置 - 首选项 - 自动完成&#xff0c;在插入选…...

CSS线性渐变拼接,一个完整的渐变容器(div),要拆分成多个渐变容器(div),并且保持渐变效果一致

1 需求 一个有渐变背景的div&#xff0c;需要替换成多个渐变背景div拼接&#xff0c;渐变效果需要保持一致&#xff08;不通过一个大的div渐变&#xff0c;其他子的div绝对定位其上并且背景透明来解决&#xff09; 2 分析 主要工作&#xff1a; 计算完整div背景线性渐变时的…...

【60天备战软考高级系统架构设计师——第十天:软件设计与架构综合练习】

经过前十天的学习&#xff0c;我们已经了解了软件工程生命周期模型、需求分析与管理方法&#xff0c;以及软件设计与架构的核心内容。为了巩固这些知识点&#xff0c;今天我们将进行一个综合练习。 前十天学习内容回顾 第1-3天&#xff1a;软件工程概述 学习了软件生命周期模…...

2024.8.15(python管理mysql、Mycat实现读写分离)

一、python管理mysql 1、搭建主mysql [rootmysql57 ~]# tar -xf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz [rootmysql57 ~]# cp -r mysql-5.7.44-linux-glibc2.12-x86_64 /usr/local/mysql [rootmysql57 ~]# rm -rf /etc/my.cnf [rootmysql57 ~]# mkdir /usr/local/mysql…...

CMU 10423 Generative AI:lec2

文章目录 1 概述2 部分摘录2.1 噪声信道模型&#xff08;Noisy Channel Models&#xff09;主要内容&#xff1a;公式解释&#xff1a;应用举例&#xff1a; 2.2 n-Gram模型1. 什么是n-Gram模型2. 早期的n-Gram模型3. Google n-Gram项目4. 模型规模与训练数据5. n-Gram模型的局…...

恋爱相亲交友系统源码原生源码可二次开发APP 小程序 H5,web全适配

直播互动&#xff1a;平台设有专门的直播间&#xff0c;允许房间主人与其他异性用户通过视频连线的方式进行一对一互动。语音视频交流&#xff1a;异性用户可以发起语音或视频通话&#xff0c;以增进了解和交流。群组聊天&#xff1a;用户能够创建群聊&#xff0c;邀请自己关注…...

OceanBase 4.x 存储引擎解析:如何让历史库场景成本降低50%+

据国际数据公司&#xff08;IDC&#xff09;的报告显示&#xff0c;预计到2025年&#xff0c;全球范围内每天将产生高达180ZB的庞大数据量&#xff0c;这一趋势预示着企业将面临着更加严峻的海量数据处理挑战。随着数据日渐庞大&#xff0c;一些存储系统会出现诸如存储空间扩展…...

js 如何写构造函数 ,构造函数和普通函数有什么区别

在 JavaScript 中&#xff0c;构造函数是一种特殊的函数&#xff0c;用于初始化一个新创建的对象。构造函数通常用来创建具有相似属性和方法的对象实例。构造函数的主要特点是在调用时使用 new 关键字&#xff0c;这样就会创建一个新对象&#xff0c;并将其原型设置为构造函数的…...

MySQL-进阶篇-锁(全局锁、表级锁、行级锁)

文章目录 1. 锁概述2. 全局锁2.1 介绍2.2 数据备份2.3 使用全局锁造成的问题 3. 表级锁3.1 表锁3.1.1 语法3.1.2 读锁3.1.3 写锁3.1.4 读锁和写锁的区别 3.2 元数据锁&#xff08;Meta Data Lock&#xff0c;MDL&#xff09;3.3 意向锁3.3.1 案例引入3.3.2 意向锁的分类 4. 行级…...

c++懒汉式单例模式(Singleton)多种实现方式及最优比较

前言 关于C懒汉式单例模式的写法&#xff0c;大家都很熟悉。早期的设计模式中有代码示例。比如&#xff1a; class Singleton {private: static Singleton *instance;public: static Singleton *getInstance() {if (NULL instance)instance new Singleton();return instanc…...

Gartner《2024中国安全技术成熟度曲线》AI安全助手代表性产品:开发者安全助手D10

海云安关注到&#xff0c;近日&#xff0c;国际权威研究机构Gartner发布了《2024中国安全技术成熟度曲线》(Hype Cycle for Security in China,2024)报告。 在此次报告中&#xff0c;安全技术成熟度曲线将安全周期划分为技术萌芽期&#xff08;Innovation Trigger&#xff09;…...

奇安信椒图--服务器安全管理系统(云锁)

奇安信椒图–服务器安全管理系统&#xff08;云锁&#xff09; 椒图 奇安信服务器安全管理系统是一款符合Gartner定义的CWPP&#xff08;云工作负载保护平台&#xff09;标准、EDR&#xff08;终端检测与响应&#xff09;、EPP终端保护平台&#xff08;终端保护平台&#xff…...

pointer-events,添加水印的一个小小点

场景&#xff1a;平平无奇一个水印图&#xff0c;这类功能实现&#xff1a;就是覆盖在整个可视div后&#xff0c;又加了一个div&#xff08;使用定位canvas画一个水印图充当背景&#xff09;&#xff0c;可时我好奇的是&#xff0c;我使用控制台&#xff0c;选择对应的元素时&a…...

微服务--认识微服务

微服务架构的演变 1. 单体架构&#xff08;Monolithic&#xff09; 阶段描述&#xff1a;在单体应用时代&#xff0c;整个应用程序被设计为一个项目&#xff0c;并在一个进程内运行。这种架构方式开发简单&#xff0c;便于集中管理&#xff0c;但随着应用的复杂化&#xff0c…...

【docker】docker 镜像仓库的管理

Docker 仓库&#xff08; Docker Registry &#xff09; 是用于存储和分发 Docker 镜像的集中式存储库。 它就像是一个大型的镜像仓库&#xff0c;开发者可以将自己创建的 Docker 镜像推送到仓库中&#xff0c;也可以从仓库中拉取所需的镜像。 Docker 仓库可以分为公共仓…...

XCTF-web-easyupload

试了试php&#xff0c;php7&#xff0c;pht&#xff0c;phtml等&#xff0c;都没有用 尝试.user.ini 抓包修改将.user.ini修改为jpg图片 在上传一个123.jpg 用蚁剑连接&#xff0c;得到flag...

Debian系统简介

目录 Debian系统介绍 Debian版本介绍 Debian软件源介绍 软件包管理工具dpkg dpkg核心指令详解 安装软件包 卸载软件包 查询软件包状态 验证软件包完整性 手动处理依赖关系 dpkg vs apt Debian系统介绍 Debian 和 Ubuntu 都是基于 Debian内核 的 Linux 发行版&#xff…...

基于Uniapp开发HarmonyOS 5.0旅游应用技术实践

一、技术选型背景 1.跨平台优势 Uniapp采用Vue.js框架&#xff0c;支持"一次开发&#xff0c;多端部署"&#xff0c;可同步生成HarmonyOS、iOS、Android等多平台应用。 2.鸿蒙特性融合 HarmonyOS 5.0的分布式能力与原子化服务&#xff0c;为旅游应用带来&#xf…...

ESP32 I2S音频总线学习笔记(四): INMP441采集音频并实时播放

简介 前面两期文章我们介绍了I2S的读取和写入&#xff0c;一个是通过INMP441麦克风模块采集音频&#xff0c;一个是通过PCM5102A模块播放音频&#xff0c;那如果我们将两者结合起来&#xff0c;将麦克风采集到的音频通过PCM5102A播放&#xff0c;是不是就可以做一个扩音器了呢…...

CSS设置元素的宽度根据其内容自动调整

width: fit-content 是 CSS 中的一个属性值&#xff0c;用于设置元素的宽度根据其内容自动调整&#xff0c;确保宽度刚好容纳内容而不会超出。 效果对比 默认情况&#xff08;width: auto&#xff09;&#xff1a; 块级元素&#xff08;如 <div>&#xff09;会占满父容器…...

GruntJS-前端自动化任务运行器从入门到实战

Grunt 完全指南&#xff1a;从入门到实战 一、Grunt 是什么&#xff1f; Grunt是一个基于 Node.js 的前端自动化任务运行器&#xff0c;主要用于自动化执行项目开发中重复性高的任务&#xff0c;例如文件压缩、代码编译、语法检查、单元测试、文件合并等。通过配置简洁的任务…...

群晖NAS如何在虚拟机创建飞牛NAS

套件中心下载安装Virtual Machine Manager 创建虚拟机 配置虚拟机 飞牛官网下载 https://iso.liveupdate.fnnas.com/x86_64/trim/fnos-0.9.2-863.iso 群晖NAS如何在虚拟机创建飞牛NAS - 个人信息分享...

加密通信 + 行为分析:运营商行业安全防御体系重构

在数字经济蓬勃发展的时代&#xff0c;运营商作为信息通信网络的核心枢纽&#xff0c;承载着海量用户数据与关键业务传输&#xff0c;其安全防御体系的可靠性直接关乎国家安全、社会稳定与企业发展。随着网络攻击手段的不断升级&#xff0c;传统安全防护体系逐渐暴露出局限性&a…...

Xcode 16 集成 cocoapods 报错

基于 Xcode 16 新建工程项目&#xff0c;集成 cocoapods 执行 pod init 报错 ### Error RuntimeError - PBXGroup attempted to initialize an object with unknown ISA PBXFileSystemSynchronizedRootGroup from attributes: {"isa">"PBXFileSystemSynchro…...

ubuntu中安装conda的后遗症

缘由: 在编译rk3588的sdk时&#xff0c;遇到编译buildroot失败&#xff0c;提示如下&#xff1a; 提示缺失expect&#xff0c;但是实测相关工具是在的&#xff0c;如下显示&#xff1a; 然后查找借助各个ai工具&#xff0c;重新安装相关的工具&#xff0c;依然无解。 解决&am…...