uboot定制--Apple的学习笔记

前言:

为了再熟悉下代码,改改源码。其实搜索原来串口打印的关键字就可以找到,然后替换字符而已。
另外,就是将u-boot-spl调用的函数及u-boot调用的函数大致弄清楚了。lds的layout弄清楚了。

2020-09-23日已将定制后的bb black uboot源码及编译结果上传到我的gitee

问题1:u-boot-spl的主要makefile在哪里?

[移植uboot[2020.10.r4]--Apple的学习笔记]https://www.jianshu.com/p/5a420c27e78d)我里面提交到uboot-spl和uboot的调用哪个board_init_f及board_init_r我有点搞不清楚,之前是通过map文件反向搜索board_init_f中调用的函数来确认到底用了那个文件中的board_init_f。主要是我没找到uboot-spl的makefile。感觉区分不了。

所以,我今天就从顶层makefile来找spl的地图线索。通过搜索u-boot-spl的依赖关系,最后搜索到spl/u-boot-spl,里面有关键信息Makefile.spl all。如果要指定特定的Makefile,你可以使用make的“- f”和“--file”参数。所以打开Makefile.spl all后就得知结果。所以Makefile.spl文件是u-boot-spl的地图。

spl/u-boot-spl: tools prepare \
        $(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_SPL_OF_PLATDATA),dts/dt.dtb) \
        $(if $(CONFIG_OF_SEPARATE)$(CONFIG_OF_EMBED)$(CONFIG_TPL_OF_PLATDATA),dts/dt.dtb)
    $(Q)$(MAKE) obj=spl -f $(srctree)/scripts/Makefile.spl all

问题2:spl调用的board_init_r在哪里?

从Makefile.spl中可以看到。用的是common/spl.c里面的board_init_r。另外,其它共享文件中,其实是通过# ifdef CONFIG_SPL_BUILD来区分某几行属于spl,某几行属于uboot的。
比如如下代码中,#if ! defined(CONFIG_SPL_BUILD),说明board_init_f函数后,uboot调用了relocate_code。而spl调用了spl_relocate_stack_gd。

    mov r0, #0
    bl  board_init_f

#if ! defined(CONFIG_SPL_BUILD)

/*
 * Set up intermediate environment (new sp and gd) and call
 * relocate_code(addr_moni). Trick here is that we'll return
 * 'here' but relocated.
 */

    ldr r0, [r9, #GD_START_ADDR_SP] /* sp = gd->start_addr_sp */
    bic r0, r0, #7  /* 8-byte alignment for ABI compliance */
    mov sp, r0
    ldr r9, [r9, #GD_NEW_GD]        /* r9 <- gd->new_gd */

    adr lr, here
    ldr r0, [r9, #GD_RELOC_OFF]     /* r0 = gd->reloc_off */
    add lr, lr, r0
#if defined(CONFIG_CPU_V7M)
    orr lr, #1              /* As required by Thumb-only */
#endif
    ldr r0, [r9, #GD_RELOCADDR]     /* r0 = gd->relocaddr */
    b   relocate_code
here:
/*
 * now relocate vectors
 */

    bl  relocate_vectors

/* Set up final (full) environment */

    bl  c_runtime_cpu_setup /* we still call old routine here */
#endif
#if !defined(CONFIG_SPL_BUILD) || CONFIG_IS_ENABLED(FRAMEWORK)

#if !defined(CONFIG_SPL_BUILD) || !defined(CONFIG_SPL_EARLY_BSS)
    CLEAR_BSS
#endif

# ifdef CONFIG_SPL_BUILD
    /* Use a DRAM stack for the rest of SPL, if requested */
    bl  spl_relocate_stack_gd
    cmp r0, #0
    movne   sp, r0
    movne   r9, r0
# endif

问题3:ddr的size宏定义设置的是1G,但是输出是512M,我买了次货?

代码中定义的是1G的,但是确能识别出512M,分析了下get_ram_size函数里面的机制是先按1G写入,然后一个个读取,若一致,则说明内存大小存在。通过此方法确认大小。后来查了下我的订购信息,原版用的是美光系列内存,我是中国版用的是金士顿ddr3内存,确实是512M,所以我将宏定义改成了512<<20了。

问题4:在哪里设置环境参数默认值?

env_default.h中的default_environment数组可以看到,需要在menuconfig中设置即可。


image.png

简单定制效果

字符串哪里看的不顺眼就在源码中修改哪里,哈哈~
之前我不改源码,只改配置,如下

U-Boot SPL 2020.10-rc4 (Sep 20 2020 - 20:37:17 +0800)
Trying to boot from MMC1
Loading Environment from FAT... OK


U-Boot 2020.10-rc4 (Sep 20 2020 - 20:37:17 +0800)

CPU  : AM335X-GP rev 2.1
Model: TI AM335x BeagleBone Black
DRAM:  512 MiB
MMC:   OMAP SD/MMC: 0, OMAP SD/MMC: 1
Loading Environment from FAT... OK
Net:   eth2: ethernet@4a100000, eth3: usb_ether
Press SPACE to abort autoboot in 2 seconds
switch to partitions #0, OK
mmc0 is current device
6020864 bytes read in 399 ms (14.4 MiB/s)
34782 bytes read in 5 ms (6.6 MiB/s)
## Flattened Device Tree blob at 88000000
   Booting using the fdt blob at 0x88000000
   Loading Device Tree to 8fff4000, end 8ffff7dd ... OK

Starting kernel ...

现在简单修改源码,由于删除了uenv.txt,导致警告crc bad,所以我将此句改成了Apple,Good job!
简单定制后,如下

U-Boot SPL 2020.10-rc4 (Sep 21 2020 - 21:17:39 +0800)
Trying to boot from MMC1
Loading Environment from FAT... Apple,Good job!
Loading Environment from MMC... Apple,Good job!


U-Boot 2020.10-rc4 (Sep 21 2020 - 21:17:39 +0800)

CPU  : AM335X-GP rev 2.1
Model: TI AM335x BeagleBone Black
Apple's DRAM:  512 MiB
Apple's MMC:   OMAP SD/MMC: 0, OMAP SD/MMC: 1
Loading Environment from FAT... Apple,Good job!
Loading Environment from MMC... Apple,Good job!
<ethaddr> not set. Validating first E-fuse MAC
Apple's Net:   eth2: ethernet@4a100000, eth3: usb_ether
Press SPACE to abort autoboot in 2 seconds
Apple:switch to partitions #0, OK
mmc0 is current device
6020864 bytes read in 399 ms (14.4 MiB/s)
48713 bytes read in 6 ms (7.7 MiB/s)
## Flattened Device Tree blob at 88000000
   Booting using the fdt blob at 0x88000000
   Loading Device Tree to 8fff1000, end 8ffffe48 ... OK

Starting kernel ...

9月22日追加遗留问题

今天修改了dts中的Model name,然后把In:Out:通过关闭静默配置项打印出来,无法通过配置的方法删除<ethaddr> not set. Validating first E-fuse MAC


U-Boot SPL 2020.10-rc4 (Sep 22 2020 - 21:30:07 +0800)
Trying to boot from MMC1
Loading Environment from FAT... Apple,Good job!
Loading Environment from MMC... Apple,Good job!


U-Boot 2020.10-rc4 (Sep 22 2020 - 21:30:07 +0800)

CPU  : AM335X-GP rev 2.1
Model: APPLE's TI AM335x BeagleBone Black
Apple's DRAM:  512 MiB
Apple's MMC:   OMAP SD/MMC: 0, OMAP SD/MMC: 1
Loading Environment from FAT... Apple,Good job!
Loading Environment from MMC... Apple,Good job!
In:    serial@44e09000
Out:   serial@44e09000
Err:   serial@44e09000
<ethaddr> not set. Validating first E-fuse MAC
Apple's Net:   eth2: ethernet@4a100000, eth3: usb_ether
Press SPACE to abort autoboot in 2 seconds
Apple:switch to partitions #0, OK
mmc0 is current device
6020864 bytes read in 399 ms (14.4 MiB/s)
48721 bytes read in 7 ms (6.6 MiB/s)
## Flattened Device Tree blob at 88000000
   Booting using the fdt blob at 0x88000000
   Loading Device Tree to 8fff1000, end 8ffffe50 ... OK

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.19.59 (root@applecaiHP) (gcc version 8.4.0 (Buildroot 2020.05.2)) #1 SMP Sun Sep 6 17:05:07 CST 2020
[    0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7), cr=10c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[    0.000000] OF: fdt: Machine model: APPLE's TI AM335x BeagleBone Black
[    0.000000] Memory policy: Data cache writeback
[    0.000000] cma: Reserved 16 MiB at 0x9e800000
[    0.000000] CPU: All CPU(s) started in SVC mode.
[    0.000000] AM335X ES2.1 (sgx neon)

9月23日解决22日的问题

1.<ethaddr> not set已解决,我可以在启动的时候set ethaddr,但是这不是我期望的,我期望固化在固件中,后来分析代码得到修改方法,在NETARGS中添加即可。


image.png

2.CONFIG_ENV_IS_IN_MMC改为FALSE。就不会出现
Loading Environment from MMC... Apple,Good job!
修改后效果如下

U-Boot SPL 2020.10-rc4 (Sep 23 2020 - 20:47:42 +0800)
Trying to boot from MMC1
Loading Environment from FAT... Apple,Good job!


U-Boot 2020.10-rc4 (Sep 23 2020 - 20:47:42 +0800)

CPU  : AM335X-GP rev 2.1
Model: APPLE's TI AM335x BeagleBone Black
Apple's DRAM:  512 MiB
Apple's MMC:   OMAP SD/MMC: 0, OMAP SD/MMC: 1
Loading Environment from FAT... Apple,Good job!
In:    serial@44e09000
Out:   serial@44e09000
Err:   serial@44e09000
Apple's Net:   eth2: ethernet@4a100000, eth3: usb_ether
Press SPACE to abort autoboot in 2 seconds
Apple:switch to partitions #0, OK
mmc0 is current device
6020864 bytes read in 397 ms (14.5 MiB/s)
48721 bytes read in 7 ms (6.6 MiB/s)
## Flattened Device Tree blob at 88000000
   Booting using the fdt blob at 0x88000000
   Loading Device Tree to 8fff1000, end 8ffffe50 ... OK

Starting kernel ...

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.19.59 (root@applecaiHP) (gcc version 8.4.0 (Buildroot 2020.05.2)) #1 SMP Sun Sep 6 17:05:07 CST 2020
[    0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7), cr=10c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[    0.000000] OF: fdt: Machine model: APPLE's TI AM335x BeagleBone Black

uboot网络功能也正常,可以ping通

U-Boot 2020.10-rc4 (Sep 23 2020 - 20:47:42 +0800)

CPU  : AM335X-GP rev 2.1
Model: APPLE's TI AM335x BeagleBone Black
Apple's DRAM:  512 MiB
Apple's MMC:   OMAP SD/MMC: 0, OMAP SD/MMC: 1
Loading Environment from FAT... Apple,Good job!
In:    serial@44e09000
Out:   serial@44e09000
Err:   serial@44e09000
Apple's Net:   eth2: ethernet@4a100000, eth3: usb_ether
Press SPACE to abort autoboot in 2 seconds
=> printenv ipaddr
ipaddr=192.168.0.2
=> ping 192.168.0.111
link up on port 0, speed 100, full duplex
Using ethernet@4a100000 device
host 192.168.0.111 is alive
=> 

至此,本轮的uboot定制完结了。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,542评论 6 504
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,822评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,912评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,449评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,500评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,370评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,193评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,074评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,505评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,722评论 3 335
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,841评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,569评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,168评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,783评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,918评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,962评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,781评论 2 354