_main 函数中会调用 board_init_f 函数,本文继续简单分析一下 board_init_f 函数。
具体分析 board_init_f函数的第二部分:内存分配代码。
本文继上一篇文章的学习,地址如下:
uboot启动流程-涉及board_init_f 函数-CSDN博客
下面具体分析 board_init_f 函数的后半部分:内存分配代码。
board_init_f 函数里面有大量的条件编译代码,这里为了缩小篇幅,将条件编译部分删除掉了,去掉条件编译以后的board_init_f 函数 后半部分代码如下:
1 static init_fnc_t init_sequence_f[] = {
2 setup_mon_len,
......
32 /*
33 * Now that we have DRAM mapped and working, we can
34 * relocate the code and continue running from DRAM.
35 *
36 * Reserve memory at end of RAM for (top down in that order):
37 * - area that won't get touched by U-Boot and Linux (optional)
38 * - kernel log buffer
39 * - protected RAM
40 * - LCD framebuffer
41 * - monitor code
42 * - board info struct
43 */
44 setup_dest_addr,
45 reserve_round_4k,
46 reserve_mmu,
47 reserve_trace,
48 reserve_uboot,
49 reserve_malloc,
50 reserve_board,
51 setup_machine,
52 reserve_global_data,
53 reserve_fdt,
54 reserve_arch,
55 reserve_stacks,
56 setup_dram_config,
57 show_dram_config,
58 display_new_sp,
59 INIT_FUNC_WATCHDOG_RESET
60 reloc_fdt,
61 setup_reloc,
62 NULL,
63 };
在 setup_dest_addr 函数加入打印如下:
printf("gd->ram_size: %#x\n", gd->ram_size);
printf("gd->ram_top: %#x\n", gd->ram_top);
printf("gd->relocaddr: %#x\n", gd->relocaddr);
重新编译 uboot源码后,生成 u-boot.bin。将 u-boot.bin拷贝到 ubuntu的 tftp服务设置目录下。
通过 tftp服务将 u-boot.bin下载到开发板。开发板uboot命令模式下输入如下:
=> tftp 0x87800000 u-boot.bin
Using FEC1 device
TFTP from server 192.168.1.66; our IP address is 192.168.1.50
Filename 'u-boot.bin'.
Load address: 0x87800000
Loading: #################################
2.7 MiB/s
done
Bytes transferred = 476700 (7461c hex)
运行下载到开发板的 DRAM的uboot。操作如下:
=> go 0x87800000
## Starting application at 0x87800000 ...
U-Boot 2016.03 (Oct 02 2023 - 21:20:41 +0800)
CPU: Freescale i.MX6ULL rev1.1 69 MHz (running at 396 MHz)
CPU: Industrial temperature grade (-40C to 105C) at 44C
Reset cause: unknown reset
Board: MX6ULL ALIENTEK NAND
I2C: ready
DRAM: gd->ram_size: 0x10000000
gd->ram_top: 0x90000000
gd->relocaddr: 0x90000000
256 MiB
......
可以看出, 这里三个参数:
gd->ram_size = 0X10000000 //ram 大小为 0X10000000= 256 MB
gd->ram_top = 0X90000000 //ram 最高地址为 0X80000000+0X10000000=0X90000000
gd->relocaddr = 0X90000000 //重定位后最高地址为 0X90000000
DRAM: gd->arch.tlb_size: 0x4000 //MMU 的 TLB 表大小
gd->arch.tlb_addr: 0x8fff0000 //MMU 的 TLB 表起始地址,64KB 对齐以后
gd->relocaddr: 0x8fff0000 //relocaddr 地址
第 47 行,reserve_trace 函数,留出跟踪调试的内存,I.MX6ULL 没有用到!
DRAM: gd->mon_len: 0xb7394
gd->start_addr_sp: 0x8ff38000
gd->relocaddr: 0x8ff38000
DRAM: TOTAL_MALLOC_LEN: 0x1020000
gd->start_addr_sp: 0x8ef18000 //0X8FF38000-16MB-4MB=0X8EF18000