zoukankan      html  css  js  c++  java
  • 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" 
        /**
          * 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" 
        /**
          * 文件系统存放的位置,文进系统存放在emmc中
          */
        "mmcroot=/dev/mmcblk0p2 rw" 
        /**
          * 文件系统的类型是ext4
          */
        "mmcrootfstype=ext4 rootwait" 
        /**
          * 文件系统存放的位置,文进系统存放在nand中
          */
        "nandroot=ubi0:rootfs rw ubi.mtd=7,2048" 
        /**
          * 文件系统的类型是ubifs
          */
        "nandrootfstype=ubifs rootwait=1" 
    #else
        /*"console=ttyO0,115200n8"  */
    #define CON     
        /**
          * console: kernel终端输出设置为ttyO0、115200n8
          */
        "console=ttyO0,115200n8" 
        "optargs=" 
        "mmcroot=/dev/mmcblk0p2 ro" 
        /**
          * 文件系统的类型是ext3
          */
        "mmcrootfstype=ext3 rootwait" 
        "nandroot=ubi0:rootfs rw ubi.mtd=7,2048" 
        "nandrootfstype=ubifs rootwait=1" 
    #endif
    
    
    #if 1
    #define CONFIG_EXTRA_ENV_SETTINGS 
        CON 
        /**
          * printf("current screen type is `%s`
    ",getenv("screentype"));
          * printf("R means Resistor screen,C means Capacitor screen
    ");
          * printf("---------------------screen type----------------------
    ");
          * printf("0 -- exit to upper menu
    ");
          * printf("1 -- Resistor screen
    ");
          * printf("2 -- Capacitor screen
    ");
          * printf("------------------------------------------------------
    ");
          * 
          */
        "screentype=R"
        /**
          * printf("current screen size is `%s`
    ",getenv("screensize"));
          * printf("AAAxAAA-B means Binch screen with AAAxAAA pixels
    ");
          * printf("---------------------screen type----------------------
    ");
          * printf("0 -- exit to upper menu
    ");
          * printf("1 -- 480x272-4
    ");
          * printf("2 -- 800x480-5
    ");
          * printf("3 -- 800x480-7
    ");
          * printf("4 -- 800x600-8
    ");
          * printf("5 -- 800x600-10
    ");
          * printf("------------------------------------------------------
    ");
          */
        "screensize=800x600-10"
        /**
          * load address
          */
        "loadaddr=0x80200000" 
        /**
          * kernel load address
          */
        "kloadaddr=0x80007fc0" 
        "fdtaddr=0x80F80000" 
        "fdt_high=0xffffffff" 
        /**
          * ramdisk address
          */
        "rdaddr=0x81000000" 
        /**
          * boot device
          */
        "bootdev=MMC"
        /**
          * boot file name
          */
        "bootfile=uImage" 
        "fdtfile=" 
        /**
          * mmc设备可能有几个,选择第0个
          */
        "mmcdev=0" 
        /**
          * nand中内核保存的其实地址,这个需要看nand分区设置,kernel中有一个分区表,下面的update也有对应的值
          */
        "nandsrcaddr=0x280000" 
        /**
          * nand中的kernel的大小
          */
        "nandimgsize=0x500000" 
        /**
          * 网络文件系统所使用的挂在路径方式
          */
        "rootpath=/export/rootfs" 
        "nfsopts=nolock" 
        "static_ip=${ipaddr}:${serverip}:${gatewayip}:${netmask}:${hostname}" 
            "::off" 
        "ramroot=/dev/ram0 rw ramdisk_size=65536 initrd=${rdaddr},64M" 
        "ramrootfstype=ext2" 
        /**
          * ip_method to determine how the kernel will deal with networking PRIOR to userspace spawning init
          */
        "ip_method=none" 
        "bootargs_defaults=setenv bootargs " 
            "console=${console} " 
            "${optargs}" 
        "mmcargs=run bootargs_defaults;" 
            "setenv bootargs ${bootargs} " 
            "root=${mmcroot} " 
            "rootfstype=${mmcrootfstype} ip=${ip_method} screentype=${screentype} screensize=${screensize}" 
        "nandargs=setenv bootargs console=${console} " 
            "${optargs} " 
            "root=${nandroot} " 
            "rootfstype=${nandrootfstype} screentype=${screentype} screensize=${screensize}" 
        "spiroot=/dev/mtdblock4 rw" 
        "spirootfstype=jffs2" 
        "spisrcaddr=0xe0000" 
        "spiimgsize=0x362000" 
        "spibusno=0" 
        "spiargs=setenv bootargs console=${console} " 
            "${optargs} " 
            "root=${spiroot} " 
            "rootfstype=${spirootfstype}" 
        "netargs=setenv bootargs console=${console} " 
            "${optargs} " 
            "root=/dev/nfs " 
            "nfsroot=${serverip}:${rootpath},${nfsopts} rw " 
            "ip=dhcp" 
        "bootenv=uEnv.txt" 
        "loadbootenv=fatload mmc ${mmcdev} ${loadaddr} ${bootenv}" 
        "importbootenv=echo Importing environment from mmc ...; " 
            "env import -t $loadaddr $filesize" 
        "ramargs=setenv bootargs console=${console} " 
            "${optargs} " 
            "root=${ramroot} " 
            "rootfstype=${ramrootfstype}" 
        "loadramdisk=fatload mmc ${mmcdev} ${rdaddr} ramdisk.gz" 
        "loaduimagefat=fatload mmc ${mmcdev} ${kloadaddr} ${bootfile}" 
        "loaduimage=ext2load mmc ${mmcdev}:2 ${kloadaddr} /boot/${bootfile}" 
        "mmcboot=echo Booting from mmc ...; " 
            "run mmcargs; " 
            "bootm ${kloadaddr}" 
        "nandboot=echo Booting from nand ...; " 
            "run nandargs; " 
            "nandecc hw 2;"
            "nand read ${loadaddr} ${nandsrcaddr} ${nandimgsize}; " 
            "bootm ${loadaddr}" 
        "spiboot=echo Booting from spi ...; " 
            "run spiargs; " 
            "sf probe ${spibusno}:0; " 
            "sf read ${loadaddr} ${spisrcaddr} ${spiimgsize}; " 
            "bootm ${loadaddr}" 
        "netboot=echo Booting from network ...; " 
            "setenv autoload no; " 
            "dhcp; " 
            "tftp ${loadaddr} ${bootfile}; " 
            "run netargs; " 
            "bootm ${loadaddr}" 
        "ramboot=echo Booting from ramdisk ...; " 
            "run ramargs; " 
            "bootm ${loadaddr}" 
        "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" 
        /**
          * 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;"
        "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
  • 相关阅读:
    C/C++程序内存泄漏检测
    linux下的内存管理
    Linker Script 链接器脚本
    linux内核进程调度以及定时器实现机制
    嵌入式软件设计中查找缺陷的几个技巧
    winCE DEBUGZONE
    程序员三个境界
    EJB初识(通熟易懂)
    JVM/JDK/JRE/IDE—区别(很经典)
    dubbo初识(一)Dubbo架构设计详解
  • 原文地址:https://www.cnblogs.com/zengjfgit/p/4845023.html
Copyright © 2011-2022 走看看