How to extend the uboot-menu


(Frank W.) #1

Hi, on uboot-console i can see the options for boot menu:

bootmenu_0=1. System Load Linux to SDRAM via TFTP.=run boot0
bootmenu_1=2. System Load Linux Kernel then write to Flash via TFTP.=run boot1
bootmenu_2=3. Boot Linux from SD.=run boot10
bootmenu_3=4. System Load Boot Loader then write to Flash via TFTP.=run boot3
bootmenu_4=5. System Load Linux Kernel then write to Flash via Serial.=run boot4
bootmenu_5=6. System Load Boot Loader then write to Flash via Serial.=run boot5
bootmenu_6=7. Boot system code via Flash.=run boot2

these are not set via uEnv.txt and so are build-in…

now i tried to add another bootmenu-entry via uEnv.txt:

kernel_4.14=uImage_4.14.33
kernel_4.9=uImage_4.9.92
boot49=mmc init; fatload mmc 0:1 ${loadaddr} ${bpi}/${board}/${service}/${kernel_4.9}; bootm
boot414=mmc init; fatload mmc 0:1 ${loadaddr} ${bpi}/${board}/${service}/${kernel_4.14}; bootm

bootmenu_7=8. Boot kernel 4.9.=run boot49
bootmenu_8=9. Boot kernel 4.14.=run boot414

i know i can modify existing kernel=-param to set another name for the uImage…this works, but the corresponding menuentry boot10 goes through some variables and also loads the env after selecting the entry.

the bootentry and my variables seems not to be loaded before displaying the menu…how can i change this?

i also tried with patches from @Jackzeng, but it seems that uEnv.txt from sd.card is not load before menu is displayed

also the following commands on uboot-console did not load it:

  1. mmc init

  2. run loadbootenv

    BPI-IoT> run loadbootenv
    reading bananapi/bpi-r2/linux/uEnv.txt
    1146 bytes read in 10 ms (111.3 KiB/s)

  3. printenv => does not show my vars

  4. bootmenu => does not display the menuentries

Frank


(ZB) #2

Hello,Frank,I will test it.

you mean you add your cmds to uboot-menu,but they don’t work right?


(Frank W.) #3

uEnv.txt seems not to be loaded before displaying boot-menu.

i can go in the console, but see nothing of my vars set. also after a manual load “mmc init”+" run loadenv" my vars not there.

i changed kernel-variable to another name, it is not my value when i use printenv, but it is used when selecting “boot from SD”…so this menuentry loads uEnv.txt in the chain (going through different vars)…thats where i have the loadenv-command


(ZB) #4

Hello Frank, uboot menu is built-in, and after uboot menu , uEnv.txt will be loaded.

image


(Frank W.) #5

in my tests uEnv.txt is not loaded if only go into console…only on selecting “Boot from SD”

i got also loaded Environment from uEnv.txt-message if i make “run loadenv” in colsole, but my vars still not loaded


(ZB) #6

I see, let me check the code.


(ZB) #7

Hello Frank,You could add your cmd to uboot-menu by this way: After you modified uEnv.txt,you could load uEnv.txt by these following ways:

  1. Boot from emmc:
  • enter to uboot-console;
  • execute “mmc init 0”
  • execute “setenv partition 0:1”
  • execute “run loadbootenv”
  • execute “env import -t ${scriptaddr} ${filesize} ”
  1. Boot from SD:
  • enter to uboot-console;
  • execute “mmc init 1”
  • execute “setenv partition 1:1”
  • execute “run loadbootenv”
  • execute “env import -t ${scriptaddr} ${filesize} ”

(Frank W.) #8

after the last command “env import …” my vars are loaded and items in bootmenu are also visible.

is there a way to load the envs on uboot-start (just before the menu is displayed)?


(ZB) #9

Yes,we could achieve this by moving load uEnv.txt code to where judge device boot from.


(Frank W.) #10

Is this a big change? Are you workin on it?


(ZB) #11

I have no idea,maybe it’s not a big change,but I need to discuss this.


(Frank W.) #12

currently saving env is useless until it is not loaded by default…if booting to console you have only the burned in Environment which you can extend, but without the ability to load it next time it helps not much…

in my case i want to boot multiple kernels to compare functions/behaviour…currently i had to modify the kernel-var in uenv.txt every time i want to switch to another kernel

uboot is also much code if you don’t know where to begin search ;(


#13

Hello Frank-w,

uboot is also much code if you don’t know where to begin search ;(

I think the file you are looking for is u-boot-mt/include/configs/mt7623_evb.h. On line 445 the U-Boot Environment is defined. If you add your 2 new menu lines there and recompile u-boot it should work.

#define ENV_BOOT_MENU \
    "bootmenu_0=1. System Load Linux to SDRAM via TFTP.=run boot0\0" \
    "bootmenu_1=2. System Load Linux Kernel then write to Flash via TFTP.=run boot1\0" \
    "bootmenu_2=3. Boot Linux from SD.=run boot10\0" \
    "bootmenu_3=4. System Load Boot Loader then write to Flash via TFTP.=run boot3\0" \
    "bootmenu_4=5. System Load Linux Kernel then write to Flash via Serial.=run boot4\0" \
    "bootmenu_5=6. System Load Boot Loader then write to Flash via Serial.=run boot5\0" \
    "bootmenu_6=7. Boot system code via Flash.=run boot2\0" \
    "bpiver=1\0" \
    "bpi=bananapi\0" \
    "board=bpi-r2\0" \
    "chip=MT7623N\0" \
    "service=linux\0" \
    "scriptaddr=0x83000000\0" \
    "device=mmc\0" \
    "partition=1:1\0" \
    "kernel=uImage\0" \
    "root=/dev/mmcblk0p2\0" \
    "debug=7\0" \
    "bootenv=uEnv.txt\0" \
    "checksd=fatinfo ${device} 1:1\0" \
    "loadbootenv=fatload ${device} ${partition} ${scriptaddr} ${bpi}/${board}/${service}/${bootenv} || fatload ${device} ${partition} ${scriptaddr} ${bootenv}\0" \
    "boot_normal=if run checksd; then echo Boot from SD ; setenv partition 1:1; else echo Boot from eMMC ; mmc init 0 ; setenv partition 0:1 ; fi; if run loadbootenv; then echo Loaded environment from ${bootenv}; env import -t ${scriptaddr} ${filesize}; fi; run uenvcmd; fatload mmc 0:1 ${loadaddr} ${bpi}/${board}/${service}/${kernel}; bootm\0" \
    "bootmenu_delay=30\0" \
    ""

(Frank W.) #14

I will try that, in my case it will help.

but that solves not the problem with not loading environment from uEnv.txt before displaying menu.So uboot is not really configurable without recompilation/reinstall


(Frank W.) #15

Basicly it works…i try to optimize vars and then push it to my repo


(Frank W.) #16

optimizing vars seems not to work…here is what i tried:

"bootmenu_9=10. Boot Kernel 4.16.=run boot416\0" \
"boot416=run newloadenv; setenv kernel ${kernel416}; run newboot\0" \
"kernel416=uImage_4.16\0" \
"newloadenv=mmc init; if run checksd; then echo Boot from SD ; setenv partition 1:1; else echo Boot from eMMC ; mmc init 0 ; setenv partition 0:1 ; fi; if run loadbootenv; then echo Loaded environment  from ${bootenv}; env import -t ${scriptaddr} ${filesize}; fi; run uenvcmd\0" \
"newboot=fatload mmc ${partition} ${loadaddr} ${bpi}/${board}/${service}/${kernel}; bootm\0" \

the steps should be

  • load environment from uEnv.txt
  • set var “kernel” to the content of env-var kernel416
  • boot with new “kernel” var

instead the old kernel-var (kernel=uImage) is used (overwrite it seems not to work, also build-in content is not used)

any idea?


(ZB) #17

Did you mean after you set uEnv.txt, but it doesn’t execute when board boot?


(Frank W.) #18

i modified uEnv.txt, but it is not loaded in my construct for kernel 4.16 or at least my var-setting does not work


Boot fails with self-build u-boot
(Frank W.) #19

btw. here is my bootlog:

dev_num = 1                                                                     
***size=4096, offset=1577059840, blk_start=3080195, blk_cnt=8                   
*** Warning - bad CRC, using default environment                                
                                                                                
In:    serial                                                                   
Out:   serial                                                                   
Err:   serial                                                                   
Boot From SD(id:1)                                                              
                                                                                
dev_num = 1                                                                     
***size=4096, offset=1577059840, blk_start=3080195, blk_cnt=8                   
*** Warning - bad CRC, using default environment                                
                                                                                
bootargs = board=bpi-r2 earlyprintk console=tty1 fbcon=map:0 console=ttyS0,1152t
Net:   mtk_eth                                                                  
Uip activated                                                                   


  *** U-Boot Boot Menu ***

     1. System Load Linux to SDRAM via TFTP.
     2. System Load Linux Kernel then write to Flash via TFTP.
     3. Boot Linux from SD.
     4. System Load Boot Loader then write to Flash via TFTP.
     5. System Load Linux Kernel then write to Flash via Serial.
     6. System Load Boot Loader then write to Flash via Serial.
     7. Boot system code via Flash.
     8. Boot Kernel 4.4.
     9. Boot Kernel 4.9.
     10. Boot Kernel 4.16.
     U-Boot console

BPI: SD/eMMC SD=1 eMMC=0 id = 1 (drivers/mmc/mediatek/mtk_mmc.c)
__mmc_init ret = 0
ret2 = 1
ret2 = 1
BPI: g_mtk_mmc_block.dev = 1
<= [mmc1 block 0] =>
[0x00000000] 53 44 4d 4d 43 5f 42 4f
[0x00000008] 4f 54 00 00 01 00 00 00
[0x00000010] 00 02 00 00 ff ff ff ff
[0x00000018] ff ff ff ff ff ff ff ff
[0x00000020] ff ff ff ff ff ff ff ff
[0x00000028] ff ff ff ff ff ff ff ff
[0x00000030] ff ff ff ff ff ff ff ff
[0x00000038] ff ff ff ff ff ff ff ff
[0x00000040] ff ff ff ff ff ff ff ff
[0x00000048] ff ff ff ff ff ff ff ff
[0x00000050] ff ff ff ff ff ff ff ff
[0x00000058] ff ff ff ff ff ff ff ff
[0x00000060] ff ff ff ff ff ff ff ff
[0x00000068] ff ff ff ff ff ff ff ff
[0x00000070] ff ff ff ff ff ff ff ff
[0x00000078] ff ff ff ff ff ff ff ff
[0x00000080] ff ff ff ff ff ff ff ff
[0x00000088] ff ff ff ff ff ff ff ff                                            
[0x00000090] ff ff ff ff ff ff ff ff                                            
[0x00000098] ff ff ff ff ff ff ff ff                                            
[0x000000a0] ff ff ff ff ff ff ff ff                                            
[0x000000a8] ff ff ff ff ff ff ff ff                                            
[0x000000b0] ff ff ff ff ff ff ff ff                                            
[0x000000b8] ff ff ff ff ff ff ff ff                                            
[0x000000c0] ff ff ff ff ff ff ff ff                                            
[0x000000c8] ff ff ff ff ff ff ff ff                                            
[0x000000d0] ff ff ff ff ff ff ff ff                                            
[0x000000d8] ff ff ff ff ff ff ff ff                                            
[0x000000e0] ff ff ff ff ff ff ff ff                                            
[0x000000e8] ff ff ff ff ff ff ff ff                                            
[0x000000f0] ff ff ff ff ff ff ff ff                                            
[0x000000f8] ff ff ff ff ff ff ff ff                                            
[0x00000100] ff ff ff ff ff ff ff ff                                            
[0x00000108] ff ff ff ff ff ff ff ff                                            
[0x00000110] ff ff ff ff ff ff ff ff                                            
[0x00000118] ff ff ff ff ff ff ff ff                                            
[0x00000120] ff ff ff ff ff ff ff ff                                            
[0x00000128] ff ff ff ff ff ff ff ff                                            
[0x00000130] ff ff ff ff ff ff ff ff                                            
[0x00000138] ff ff ff ff ff ff ff ff                                            
[0x00000140] ff ff ff ff ff ff ff ff                                            
[0x00000148] ff ff ff ff ff ff ff ff                                            
[0x00000150] ff ff ff ff ff ff ff ff                                            
[0x00000158] ff ff ff ff ff ff ff ff                                            
[0x00000160] ff ff ff ff ff ff ff ff                                            
[0x00000168] ff ff ff ff ff ff ff ff                                            
[0x00000170] ff ff ff ff ff ff ff ff                                            
[0x00000178] ff ff ff ff ff ff ff ff                                            
[0x00000180] ff ff ff ff ff ff ff ff                                            
[0x00000188] ff ff ff ff ff ff ff ff                                            
[0x00000190] ff ff ff ff ff ff ff ff                                            
[0x00000198] ff ff ff ff ff ff ff ff                                            
[0x000001a0] ff ff ff ff ff ff ff ff                                            
[0x000001a8] ff ff ff ff ff ff ff ff                                            
[0x000001b0] ff ff ff ff ff ff ff ff                                            
[0x000001b8] cd d6 0e 00 00 00 00 be                                            
[0x000001c0] 33 0c 0c 61 34 2d 00 20                                            
[0x000001c8] 03 00 00 00 08 00 00 61                                            
[0x000001d0] 35 2d 83 81 cb b6 00 20                                            
[0x000001d8] 0b 00 00 e0 dd 00 00 00                                            
[0x000001e0] 00 00 00 00 00 00 00 00                                            
[0x000001e8] 00 00 00 00 00 00 00 00                                            
[0x000001f0] 00 00 00 00 00 00 00 00                                            
[0x000001f8] 00 00 00 00 00 00 55 aa                                            
                                                                                
Partition Map for MMC device 1  --   Partition Type: DOS                        
                                                                                
Part    Start Sector    Num Sectors     UUID            Type                    
  1     204800          524288          000ed6cd-01     0c                      
  2     729088          14540800        000ed6cd-02     83                      
mmc1 is available                                                               
Interface:  MMC                                                                 
  Device 1: Vendor: Man 000003 Snr 8a0e0900 Rev: 13.10 Prod: SL32G0             
            Type: Removable Hard Disk                                           
            Capacity: 29664.0 MB = 28.9 GB (60751872 x 512)                     
Filesystem: FAT16 "BPI-BOOT   "                                                 
Boot from SD                                                                    
reading bananapi/bpi-r2/linux/uEnv.txt                                          
1190 bytes read in 10 ms (116.2 KiB/s)                                          
Loaded environment from uEnv.txt                                                
Banana Pi bpi-r2 chip: mt7623n Service: linux                                   
reading bananapi/bpi-r2/linux/uImage                                            
6096565 bytes read in 803 ms (7.2 MiB/s)                                        
reading bananapi/berryboot.img                                                  
** Unable to read file bananapi/berryboot.img **                                
bootm flag=0, states=70f                                                        
## Booting kernel from Legacy Image at 84000000 ...                             
   Image Name:   Linux Kernel 4.14.35-main                                      
   Image Type:   ARM Linux Kernel Image (uncompressed)                          
   Data Size:    6096501 Bytes = 5.8 MiB                                        
   Load Address: 80008000                                                       
   Entry Point:  80008000                                                       
   Verifying Checksum ... OK                                                    
   Loading Kernel Image ... OK                                                  
                                                                                
Starting kernel ...              

i modified boot416 like this:

"boot416=run newloadenv; setenv kernel ${kernel416}; printenv; run newboot\0" \

i choose “10. kernel 4.16” but default uImage is loaded…printenv is also not executed

really strange behaviour…

making the steps manually:

BPI-IoT> mmc init
BPI: SD/eMMC SD=1 eMMC=0 id = 1 (drivers/mmc/mediatek/mtk_mmc.c)
__mmc_init ret = 0
ret2 = 1
ret2 = 1
BPI: g_mtk_mmc_block.dev = 1
<= [mmc1 block 0] =>
[0x00000000] 53 44 4d 4d 43 5f 42 4f
[0x00000008] 4f 54 00 00 01 00 00 00
[0x00000010] 00 02 00 00 ff ff ff ff
[0x00000018] ff ff ff ff ff ff ff ff
[0x00000020] ff ff ff ff ff ff ff ff
[0x00000028] ff ff ff ff ff ff ff ff
[0x00000030] ff ff ff ff ff ff ff ff
[0x00000038] ff ff ff ff ff ff ff ff
[0x00000040] ff ff ff ff ff ff ff ff
[0x00000048] ff ff ff ff ff ff ff ff
[0x00000050] ff ff ff ff ff ff ff ff
[0x00000058] ff ff ff ff ff ff ff ff
[0x00000060] ff ff ff ff ff ff ff ff
[0x00000068] ff ff ff ff ff ff ff ff
[0x00000070] ff ff ff ff ff ff ff ff
[0x00000078] ff ff ff ff ff ff ff ff
[0x00000080] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000088] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000090] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000098] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000000a0] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000000a8] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000000b0] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000000b8] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000000c0] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000000c8] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000000d0] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000000d8] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000000e0] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000000e8] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000000f0] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000000f8] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000100] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000108] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000110] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000118] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000120] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000128] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000130] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000138] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000140] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000148] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000150] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000158] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000160] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000168] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000170] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000178] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000180] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000188] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000190] ff ff ff ff ff ff ff ff                                                                                                                        
[0x00000198] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000001a0] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000001a8] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000001b0] ff ff ff ff ff ff ff ff                                                                                                                        
[0x000001b8] cd d6 0e 00 00 00 00 be                                                                                                                        
[0x000001c0] 33 0c 0c 61 34 2d 00 20                                                                                                                        
[0x000001c8] 03 00 00 00 08 00 00 61                                                                                                                        
[0x000001d0] 35 2d 83 81 cb b6 00 20                                                                                                                        
[0x000001d8] 0b 00 00 e0 dd 00 00 00                                                                                                                        
[0x000001e0] 00 00 00 00 00 00 00 00                                                                                                                        
[0x000001e8] 00 00 00 00 00 00 00 00                                                                                                                        
[0x000001f0] 00 00 00 00 00 00 00 00                                                                                                                        
[0x000001f8] 00 00 00 00 00 00 55 aa                                                                                                                        
                                                                                                                                                            
Partition Map for MMC device 1  --   Partition Type: DOS                                                                                                    
                                                                                                                                                            
Part    Start Sector    Num Sectors     UUID            Type                                                                                                
  1     204800          524288          000ed6cd-01     0c                                                                                                  
  2     729088          14540800        000ed6cd-02     83                                                                                                  
mmc1 is available                                                                                                                                           
BPI-IoT> printenv partition                                                                                                                                 
partition=1:1                                                                                                                                               
BPI-IoT> run loadbootenv                                                                                                                                    
reading bananapi/bpi-r2/linux/uEnv.txt                                                                                                                      
1270 bytes read in 10 ms (124 KiB/s)                                                                                                                        
BPI-IoT> env import -t ${scriptaddr} ${filesize}                                                                                                            
BPI-IoT> printenv boot16                                                                                                                                    
## Error: "boot16" not defined                                                                                                                              
BPI-IoT> printenv boot416                                                                                                                                   
boot416=run newloadenv; setenv kernel ${kernel416}; printenv; run newboot                                                                                   
BPI-IoT> printenv kernel416                                                                                                                                 
kernel416=uImage_4.16.4                                                                                                                                     
BPI-IoT> setenv kernel ${kernel416}                                                                                                                         
BPI-IoT> printenv kernel                                                                                                                                    
kernel=uImage_4.16.4                                                                                                                                        
BPI-IoT> run newboot                                                                                                                                        
reading bananapi/bpi-r2/linux/uImage_4.16.4                                                                                                                 
5087956 bytes read in 670 ms (7.2 MiB/s)                                                                                                                    
bootm flag=0, states=70f                                                                                                                                    
## Booting kernel from Legacy Image at 84000000 ...                                                                                                         
   Image Name:   Linux Kernel 4.16.4-main                                                                                                                   
   Image Type:   ARM Linux Kernel Image (uncompressed)                                                                                                      
   Data Size:    5087892 Bytes = 4.9 MiB                                                                                                                    
   Load Address: 80008000                                                                                                                                   
   Entry Point:  80008000                                                                                                                                   
   Verifying Checksum ... OK                                                                                                                                
   Loading Kernel Image ... OK

(ZB) #20

Maybe you miss “env import -t ${scriptaddr} ${filesize}”.

Did you check item10,will it run “env import -t ${scriptaddr} ${filesize}”?