修改uboot代码增加环境变量

一 编译kernel

使用的开发板为: 盈鹏飞am3354

虚拟机里弄好了编译链和 nfs tftp但是没有源码需要拷贝uboot和kernel的源码进去.

编译uboot:

make com335x_nand_512_config
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-

编译kernel:

1.清理

 make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- mrproper

2. 配置

make ARCH=arm menuconfig

3. 编译

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage

这时如果没有mkimage工具会报错:


这时候需要将刚才uboot编译出来的工具拿来用.

将u-boot-2014.04-rc2-00037-gbaecd31/tools/mkimage拷贝到 PC 机 linux /usr/bin 目录下就可以了.


二 增加uboot环境变量, 实现tftp下载kernel和自动挂载NFS根文件系统

为了开发的方便我们一般都会有这么一个需求:

1. uboot启动不做任何操作从nand启动

2. 执行一个简单的命令, 从网络下载内核并启动, 启动之后自动挂接NFS根文件系统

为了实现上述的需求我们就不能修改nand启动的bootcmd, 那我们可以新建一个启动命令. 姑且叫它netboot 吧, 下边我们来看如何实现netboot

(1) 修改uboot代码

第一处:

include/configs/com335x.h 里添加 netboot(可以添加到CONFIG_BOOTCMD上方)

#define CONFIG_NETBOOT "tftp 0x81000000 uImage;"\
                             "run netargs;"\
                             "bootm 0x81000000"

第二处:

include/env_default.h  里添加 netboot
#ifdef CONFIG_NETBOOT
"netboot=" CONFIG_NETBOOT       "\0"
#endif

(2) 重新编译uboot, 并烧写

make com335x_nand_512_config
make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi-

代码里修改之后直接烧写到nand里还是不能立刻生效, 因为uboot是先读取nand里有没有环境变量, 如果有的话就用nand里的 如果nand里没有才使用默认的环境变量.所以我们在烧写uboot的时候需要将环境变量分区一起擦掉, 这样就可以使用我们代码里的默认环境变量了.

首先看下板子的分区信息

U-Boot# mtdpart

device nand0 <omap2-nand.0>, # parts = 9
 #: name                size            offset          mask_flags
 0: SPL                 0x00020000      0x00000000      0
 1: SPL.backup1         0x00020000      0x00020000      0
 2: SPL.backup2         0x00020000      0x00040000      0
 3: SPL.backup3         0x00020000      0x00060000      0
 4: u-boot              0x001e0000      0x00080000      0
 5: u-boot-env          0x00020000      0x00260000      0
 6: logo                0x00300000      0x00280000      0
 7: kernel              0x00500000      0x00580000      0
 8: rootfs              0x1f580000      0x00a80000      0

active partition: nand0,0 - (SPL) 0x00020000 @ 0x00000000

defaults:
mtdids  : nand0=omap2-nand.0
mtdparts: mtdparts=omap2-nand.0:128k(SPL),128k(SPL.backup1),128k(SPL.backup2),128k(SPL.backup3),1920k(u-boot),128k(u-boot-env),3m(logo),5m(kernel),-(rootfs)
然后执行如下语句, 

nand erase.part u-boot
nand erase.part u-boot-env
tftp 0x81000000 u-boot.img
nand write 0x81000000 u-boot ${filesize}

(3) 重新设置ip等环境变量, 添加netargs

U-Boot# setenv serverip 192.168.1.102
U-Boot# setenv ipaddr 192.168.1.105
U-Boot# setenv gatewayip 192.168.1.1
U-Boot# setenv netargs setenv bootargs noinitrd console=ttyO0,115200n8 lcdtype=AUO_AT070TN94 root=/dev/nfs ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:com335x:eth0:off nfsroot=192.168.1.102:/home/eac/nfsboot
U-Boot# save
U-Boot# run netboot

以上ip地址的配置需要根据自身的情况进行更改.

问题

问题1: 为什么不用setenv netboot tftp 0x81000000 uImage; run netboot; bootm 0x81000000 这条命令而要去修改uboot代码?

        因为这条语句执行了之后效果只有 netboot=tftp 0x81000000 第一个分号之后的内容丢失了, 所以必须更该代码

问题2: 如果不设置netargs会有什么后果? netargs各部分是什麽含义?

        设置netargs是为了能够挂载nfs, 如果netboot 设置为: tftp 0x81000000 uImage; bootm 0x81000000 就会因为没有设置根文件系统这个环境变量而出错.

setenv netargs setenv bootargs noinitrd console=ttyO0,115200n8 lcdtype=AUO_AT070TN94 root=/dev/nfs ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:com335x:eth0:off nfsroot=192.168.1.102:/home/eac/nfsboot
${ipaddr}           开发板本身的地址
${serverip}        tftp及nfs目录所在系统的地址
${gatewayip}    网关
${netmask}       子网掩码
com335x eth0:off  网卡名(这里随意)
nfsroot=192.168.1.102:/home/eac/nfsboot  nfs主机ip地址以及目录

猜你喜欢

转载自blog.csdn.net/gongyuan073/article/details/47150473