bootloaderu-boot

Why doesn't the setenv and tftp command work in my UBoot boot.scr script?


The following UBoot commands when entered manually via the UBoot prompt successfully load an image from my TFTP server:

setenv ipaddr 192.168.0.199
setenv serverip 192.168.0.198
tftp 0x10000000 rpi3bp/image.bin
go 0x10000000

However, when I compile a boot.scr file with the mkimage Uboot utility containing the above commands like so:


echo ===== Saving RPi's IP Address =====
setenv ipaddr 192.168.0.199

echo ===== Saving Home TFTP server's IP Address =====
setenv serverip 192.168.0.198

echo ===== Loading file from Home TFTP server =====
tftp 0x10000000 rpi3bp/image.bin

echo ===== Running image =====
go 0x10000000

I get the following failed output when my device boots using this boot.scr script:

...
Found U-Boot script /boot.scr
359 bytes read in 2 ms (174.8 KiB/s)
## Executing script at 02400000
===== Saving RPis IP Address =====
setenv ipaddr 192.168.0.199

echo ===== Saving Home TFTP servers IP Address =====
===== Loading file from Home TFTP server =====
lan78xx_eth Waiting for PHY auto negotiation to complete........ done
*** ERROR: `ipaddr' not set
===== Running image =====
## Starting application at 0x10000000 ...
"Synchronous Abort" handler, esr 0x02000000
elr: ffffffffd4d27000 lr : 0000000000088cc0 (reloc)
elr: 0000000010000000 lr : 000000003b361cc0
x0 : 0000000000000001 x1 : 000000003af6a028
x2 : 000000003af6a028 x3 : 000000000000003f
x4 : 000000003af60df0 x5 : 0000000000000000
x6 : 0000000000000000 x7 : 0000000000c0c0c0
x8 : 0000000000000010 x9 : 0000000000000008
x10: 00000000ffffffd0 x11: 0000000000000010
x12: 0000000000000000 x13: 0000000000000200
x14: 000000003b3cc640 x15: 0000000000000001
x16: 0000000010000000 x17: 0fac920a292163a0
x18: 000000003af54db0 x19: 000000003af6a028
x20: 0000000010000000 x21: 0000000000000002
x22: 000000003af6a020 x23: 0000000000000002
x24: 000000003b3e567c x25: 0000000000000000
x26: 0000000000000000 x27: 0000000000000000
x28: 000000003af6a080 x29: 000000003af52ed0

Code: aaaaaaaa aaaaaaaa aaaaaaaa a2aaaaaa (55555555)

Seems like ipaddr isn't getting saved and the TFTP file isn't getting copied from the server but I'm not sure why.

What am I doing wrong here in my UBoot script and how can I fix it?

Should boot.scr work just as one would be entering UBoot commands manually in the UBoot prompt?

Edit 1:

I've just hexdumped my boot.scr binary and can confirm I have Unix line endings and not Windows line endings, which is consistent with the fact that I'm using MacOS.

❯ hexdump -C boot.scr
00000000  27 05 19 56 fc 01 13 df  63 d4 67 63 00 00 01 27  |'..V�..�c�gc...'|
00000010  00 00 00 00 00 00 00 00  a6 de 91 ea 05 02 06 01  |........��.�....|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000040  00 00 01 1f 00 00 00 00  0a 65 63 68 6f 20 3d 3d  |.........echo ==|
00000050  3d 3d 3d 20 53 61 76 69  6e 67 20 52 50 69 27 73  |=== Saving RPi's|
00000060  20 49 50 20 41 64 64 72  65 73 73 20 3d 3d 3d 3d  | IP Address ====|
00000070  3d 0a 73 65 74 65 6e 76  20 69 70 61 64 64 72 20  |=.setenv ipaddr |
00000080  31 39 32 2e 31 36 38 2e  30 2e 31 39 39 0a 0a 65  |192.168.0.199..e|
00000090  63 68 6f 20 3d 3d 3d 3d  3d 20 53 61 76 69 6e 67  |cho ===== Saving|
000000a0  20 48 6f 6d 65 20 54 46  54 50 20 73 65 72 76 65  | Home TFTP serve|
000000b0  72 27 73 20 49 50 20 41  64 64 72 65 73 73 20 3d  |r's IP Address =|
000000c0  3d 3d 3d 3d 0a 73 65 74  65 6e 76 20 73 65 72 76  |====.setenv serv|
000000d0  65 72 69 70 20 31 39 32  2e 31 36 38 2e 30 2e 31  |erip 192.168.0.1|
000000e0  39 38 0a 0a 65 63 68 6f  20 3d 3d 3d 3d 3d 20 4c  |98..echo ===== L|
000000f0  6f 61 64 69 6e 67 20 66  69 6c 65 20 66 72 6f 6d  |oading file from|
00000100  20 48 6f 6d 65 20 54 46  54 50 20 73 65 72 76 65  | Home TFTP serve|
00000110  72 20 3d 3d 3d 3d 3d 0a  74 66 74 70 20 30 78 31  |r =====.tftp 0x1|
00000120  30 30 30 30 30 30 30 20  72 70 69 33 62 70 2f 69  |0000000 rpi3bp/i|
00000130  6d 61 67 65 2e 62 69 6e  0a 0a 65 63 68 6f 20 3d  |mage.bin..echo =|
00000140  3d 3d 3d 3d 20 52 75 6e  6e 69 6e 67 20 69 6d 61  |==== Running ima|
00000150  67 65 20 3d 3d 3d 3d 3d  0a 67 6f 20 30 78 31 30  |ge =====.go 0x10|
00000160  30 30 30 30 30 30 0a                              |000000.|
00000167

Solution

  • The problem is caused by the single quote (') which marks the start of a string:

    echo ===== Saving RPi's IP Address =====

    Please, remove the single quotes:

    echo ===== Saving RPis IP Address =====

    The return value of the TFTP command should be checked. You don't want to jump to an address where nothing has been loaded.

    echo ===== Saving RPis IP Address =====
    setenv ipaddr 192.168.0.199
    
    echo ===== Saving Home TFTP servers IP Address =====
    setenv serverip 192.168.0.198
    
    echo ===== Loading file from Home TFTP server =====
    tftp 0x10000000 rpi3bp/image.bin; setenv ret $?
    
    echo ===== Running image =====
    if test $ret -eq 0; then go 0x10000000; fi