OK335xS U-boot 环境变量解析
/************************************************************************************************** * OK335xS U-boot 环境变量解析 * 声明: * 本文主要是为了知道OK335xS U-boot环境变量设置、如何选择启动方式等等内容。 * * 2015-9-28 晴 深圳 南山平山村 曾剑锋 *************************************************************************************************/ #ifdef CONFIG_ANDROID #define CON \ /** * console: kernel终端输出设置为ttyO0、115200n8 */ "console=ttyO0,115200n8 earlyprintk androidboot.console=ttyO0\0" \ /** * In all cases we make use of optargs to control passing in of additional arguments and ip_method to determine how the kernel will deal with networking PRIOR to userspace spawning init. */ "optargs=init=/init\0" \ /** * 文件系统存放的位置,文进系统存放在emmc中 */ "mmcroot=/dev/mmcblk0p2 rw\0" \ /** * 文件系统的类型是ext4 */ "mmcrootfstype=ext4 rootwait\0" \ /** * 文件系统存放的位置,文进系统存放在nand中 */ "nandroot=ubi0:rootfs rw ubi.mtd=7,2048\0" \ /** * 文件系统的类型是ubifs */ "nandrootfstype=ubifs rootwait=1\0" #else /*"console=ttyO0,115200n8\0" \ */ #define CON \ /** * console: kernel终端输出设置为ttyO0、115200n8 */ "console=ttyO0,115200n8\0" \ "optargs=\0" \ "mmcroot=/dev/mmcblk0p2 ro\0" \ /** * 文件系统的类型是ext3 */ "mmcrootfstype=ext3 rootwait\0" \ "nandroot=ubi0:rootfs rw ubi.mtd=7,2048\0" \ "nandrootfstype=ubifs rootwait=1\0" #endif #if 1 #define CONFIG_EXTRA_ENV_SETTINGS \ CON \ /** * printf("current screen type is `%s`\n",getenv("screentype")); * printf("R means Resistor screen,C means Capacitor screen\n"); * printf("---------------------screen type----------------------\n"); * printf("0 -- exit to upper menu\n"); * printf("1 -- Resistor screen\n"); * printf("2 -- Capacitor screen\n"); * printf("------------------------------------------------------\n"); * */ "screentype=R\0"\ /** * printf("current screen size is `%s`\n",getenv("screensize")); * printf("AAAxAAA-B means Binch screen with AAAxAAA pixels\n"); * printf("---------------------screen type----------------------\n"); * printf("0 -- exit to upper menu\n"); * printf("1 -- 480x272-4\n"); * printf("2 -- 800x480-5\n"); * printf("3 -- 800x480-7\n"); * printf("4 -- 800x600-8\n"); * printf("5 -- 800x600-10\n"); * printf("------------------------------------------------------\n"); */ "screensize=800x600-10\0"\ /** * load address */ "loadaddr=0x80200000\0" \ /** * kernel load address */ "kloadaddr=0x80007fc0\0" \ "fdtaddr=0x80F80000\0" \ "fdt_high=0xffffffff\0" \ /** * ramdisk address */ "rdaddr=0x81000000\0" \ /** * boot device */ "bootdev=MMC\0"\ /** * boot file name */ "bootfile=uImage\0" \ "fdtfile=\0" \ /** * mmc设备可能有几个,选择第0个 */ "mmcdev=0\0" \ /** * nand中内核保存的其实地址,这个需要看nand分区设置,kernel中有一个分区表,下面的update也有对应的值 */ "nandsrcaddr=0x280000\0" \ /** * nand中的kernel的大小 */ "nandimgsize=0x500000\0" \ /** * 网络文件系统所使用的挂在路径方式 */ "rootpath=/export/rootfs\0" \ "nfsopts=nolock\0" \ "static_ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}" \ "::off\0" \ "ramroot=/dev/ram0 rw ramdisk_size=65536 initrd=${rdaddr},64M\0" \ "ramrootfstype=ext2\0" \ /** * ip_method to determine how the kernel will deal with networking PRIOR to userspace spawning init */ "ip_method=none\0" \ "bootargs_defaults=setenv bootargs " \ "console=${console} " \ "${optargs}\0" \ "mmcargs=run bootargs_defaults;" \ "setenv bootargs ${bootargs} " \ "root=${mmcroot} " \ "rootfstype=${mmcrootfstype} ip=${ip_method} screentype=${screentype} screensize=${screensize}\0" \ "nandargs=setenv bootargs console=${console} " \ "${optargs} " \ "root=${nandroot} " \ "rootfstype=${nandrootfstype} screentype=${screentype} screensize=${screensize}\0" \ "spiroot=/dev/mtdblock4 rw\0" \ "spirootfstype=jffs2\0" \ "spisrcaddr=0xe0000\0" \ "spiimgsize=0x362000\0" \ "spibusno=0\0" \ "spiargs=setenv bootargs console=${console} " \ "${optargs} " \ "root=${spiroot} " \ "rootfstype=${spirootfstype}\0" \ "netargs=setenv bootargs console=${console} " \ "${optargs} " \ "root=/dev/nfs " \ "nfsroot=${serverip}:${rootpath},${nfsopts} rw " \ "ip=dhcp\0" \ "bootenv=uEnv.txt\0" \ "loadbootenv=fatload mmc ${mmcdev} ${loadaddr} ${bootenv}\0" \ "importbootenv=echo Importing environment from mmc ...; " \ "env import -t $loadaddr $filesize\0" \ "ramargs=setenv bootargs console=${console} " \ "${optargs} " \ "root=${ramroot} " \ "rootfstype=${ramrootfstype}\0" \ "loadramdisk=fatload mmc ${mmcdev} ${rdaddr} ramdisk.gz\0" \ "loaduimagefat=fatload mmc ${mmcdev} ${kloadaddr} ${bootfile}\0" \ "loaduimage=ext2load mmc ${mmcdev}:2 ${kloadaddr} /boot/${bootfile}\0" \ "mmcboot=echo Booting from mmc ...; " \ "run mmcargs; " \ "bootm ${kloadaddr}\0" \ "nandboot=echo Booting from nand ...; " \ "run nandargs; " \ "nandecc hw 2;"\ "nand read ${loadaddr} ${nandsrcaddr} ${nandimgsize}; " \ "bootm ${loadaddr}\0" \ "spiboot=echo Booting from spi ...; " \ "run spiargs; " \ "sf probe ${spibusno}:0; " \ "sf read ${loadaddr} ${spisrcaddr} ${spiimgsize}; " \ "bootm ${loadaddr}\0" \ "netboot=echo Booting from network ...; " \ "setenv autoload no; " \ "dhcp; " \ "tftp ${loadaddr} ${bootfile}; " \ "run netargs; " \ "bootm ${loadaddr}\0" \ "ramboot=echo Booting from ramdisk ...; " \ "run ramargs; " \ "bootm ${loadaddr}\0" \ "findfdt="\ "if test $board_name = A335BONE; then " \ "setenv fdtfile am335x-bone.dtb; fi; " \ "if test $board_name = A33515BB; then " \ "setenv fdtfile am335x-evm.dtb; fi; " \ "if test $board_name = A335X_SK; then " \ "setenv fdtfile am335x-evmsk.dtb; fi\0" \ /** * cat drivers/video/cfb_console.c * * env = getenv("TYPE"); * if(env) * type = (*env)-'0'; * else * type = 9; * * switch(type) * { * case 0: * title = "Erasing nand chip............"; * break; * case 1: * title = "Reading MLO from MMC........."; * break; * case 2: * title = "Burning MLO to nand.........."; * break; * case 3: * title = "Reading u-boot.img from MMC.."; * break; * case 4: * title = "Burning u-boot.img to nand..."; * break; * case 5: * title = "Reading uImage from MMC......"; * break; * case 6: * title = "Burning uImage to nand......."; * break; * case 7: * title = "Reading ubi.img from MMC....."; * break; * case 8: * title = "Burning ubi.img to nand......"; * break; * default: * title = "env is null.................."; * break; * } */ /** * 这一部分写到nand中的内容,需要和kernel对nand的分区进行对应,貌似这样就可以直接对u-boot、kernel进行更新了 */ "auto_update_nand= echo ---------------Begin update system to Nand---------------;led all on;"\ "setenv TYPE 0;nand erase.chip;mmc rescan; "\ "setenv TYPE 1;fatload mmc 0 80A00000 nand_MLO; setenv TYPE 2;nandecc hw 2;nand write.i 80A00000 0 ${filesize}; "\ "setenv TYPE 3;fatload mmc 0 80A00000 nand_u-boot.img;setenv TYPE 4;nandecc hw 2;nand write.i 80A00000 80000 ${filesize}; "\ "setenv TYPE 5;fatload mmc 0 80A00000 uImage; setenv TYPE 6;nandecc hw 2;nand write.i 80A00000 280000 ${filesize}; "\ "setenv TYPE 7;fatload mmc 0 80A00000 ubi.img; setenv TYPE 8;nandecc sw;nand write.i 80A00000 780000 ${filesize};"\ "echo ;"\ "echo --------------Update system to Nand success--------------;led flash all;\0"\ "update_nand= echo ---------------Begin update system to Nand---------------;led all on;"\ "setenv TYPE 0;nand erase.chip;mmc rescan; "\ "setenv TYPE 1;fatload mmc 0 80A00000 MLO; setenv TYPE 2;nandecc hw 2;nand write.i 80A00000 0 ${filesize}; "\ "setenv TYPE 3;fatload mmc 0 80A00000 u-boot.img;setenv TYPE 4;nandecc hw 2;nand write.i 80A00000 80000 ${filesize}; "\ "setenv TYPE 3;fatload mmc 0 80A00000 u-boot.img;setenv TYPE 4;nandecc hw 2;nand write.i 80A00000 80000 ${filesize}; "\ "setenv TYPE 5;fatload mmc 0 80A00000 uImage; setenv TYPE 6;nandecc hw 2;nand write.i 80A00000 280000 ${filesize}; "\ "setenv TYPE 7;fatload mmc 0 80A00000 ubi.img; setenv TYPE 8;nandecc sw;nand write.i 80A00000 780000 ${filesize};"\ "echo ;"\ "echo --------------Update system to Nand success--------------;led all off;"\ /** * 虽然这部分代码确认是可运行的,但是感觉真的不合理,后面的源代码貌似更为合理一点 */ #define CONFIG_BOOTCOMMAND \ " if test $bootdev = MMC; then " \ // bootdev = MMC "mmc dev ${mmcdev}; mmc rescan;"\ // mmcdev = 0, 设置0为当前设备 "echo SD/MMC found on device ${mmcdev};" \ /** * loadaddr = 0x80200000 * bootenv = uEnv.txt * loadbootenv = fatload mmc ${mmcdev} ${loadaddr} ${bootenv} * importbootenv = echo Importing environment from mmc ...;env import -t $loadaddr $filesize */ "if run loadbootenv; then " \ "echo Loaded environment from ${bootenv};" \ "run importbootenv;" \ "fi;" \ /** * test -n: 字符串的长度非零 * uenvcmd: 不存在,不用解析 */ "if test -n $uenvcmd; then " \ "echo Running uenvcmd ...;" \ "run uenvcmd;" \ "fi;" \ /** * kloadaddr = 0x80007fc0 * bootfile = uImage * loaduimagefat = fatload mmc ${mmcdev} ${kloadaddr} ${bootfile} * * mmcboot = echo Booting from mmc ...;run mmcargs;bootm ${kloadaddr} * mmcroot = /dev/mmcblk0p2 ro * mmcrootfstype = ext3 rootwait * ip_method = none * screentype = R * screensize = 800x600-10 * mmcargs = run bootargs_defaults;setenv bootargs ${bootargs} root=${mmcroot} rootfstype=${mmcrootfstype} ip=${ip_method} screentype=${screentype} screensize=${screensize} */ "if run loaduimagefat; then " \ "run mmcboot;" \ /** * kloadaddr = 0x80007fc0 * bootfile = uImage * loaduimage = ext2load mmc ${mmcdev}:2 ${kloadaddr} /boot/${bootfile} */ "elif run loaduimage; then " \ "run mmcboot;" \ "else " \ "echo Could not find ${bootfile} ;" \ "fi;" \ "else " \ "run nandboot;" \ "fi;" \ /** * 个人认为更合理的bootcmd */ #define CONFIG_BOOTCOMMAND \ /** * mmcdev = 0, 设置0为当前设备 */ "mmc dev ${mmcdev}; " \ /** * 重新搜索mmc设备,如果不存在mmc设备,自然就是nand启动了 */ "if mmc rescan; then " \ "echo SD/MMC found on device ${mmcdev};" \ "if run loadbootenv; then " \ "echo Loaded environment from ${bootenv};" \ "run importbootenv;" \ "fi;" \ "if test -n $uenvcmd; then " \ "echo Running uenvcmd ...;" \ "run uenvcmd;" \ "fi;" \ "if run loaduimagefat; then " \ "run mmcboot;" \ "elif run loaduimage; then " \ "run mmcboot;" \ "else " \ "echo Could not find ${bootfile} ;" \ "fi;" \ "else " \ "run nandboot;" \ "fi;" \ #else