rauc / meta-rauc-community

Yocto/OpenEmbedded meta layer with examples for integration of RAUC, the embedded Linux A/B update framework
MIT License
46 stars 51 forks source link

boot-scripts: use itest for comparison, as setexpr calculates in hexa… #73

Closed matthiasklein closed 7 months ago

matthiasklein commented 8 months ago

…decimal

If you use numbers greater than 9 for the boot attempts, you will get the wrong result for pure letter numbers (A..F). The test command incorrectly leads to the result that e.g. F would not be greater than 0. This leads to an incorrect A/B switchover.

ejoerns commented 8 months ago

@matthiasklein While using itest when comparing integers seems to be more correct, I noticed that no u-boot defconfig has enabled it by default.

I would assume that using 0xa instead of a when setting default would also resolve this, issue. Doesn't it?

matthiasklein commented 8 months ago

@ejoerns As long as there is still a number in front (e.g. 0x10), the comparison with test is also TRUE. But in the range 0xA ... 0xF the comparison becomes FALSE.

It is not just about the value that is set by RAUC, but in the boot script it is decremented by 1 before the comparison. And this happens with setexpr in hexadecimal. And then the comparison goes wrong depending on the value.

I did not have to activate the itest command separately. It was available in the meta-raspberrypi (kirkstone):

U-Boot 2022.01 (Jan 10 2022 - 18:46:34 +0000)

DRAM:  948 MiB
RPI 4 Model B (0xa03115)
MMC:   mmcnr@7e300000: 1, mmc@7e340000: 0
Loading Environment from FAT... OK
In:    serial
Out:   serial
Err:   serial
Net:   eth0: ethernet@7d580000
PCIe BRCM: link up, 5.0 Gbps x1 (SSC)
starting USB...
Bus xhci_pci: Register 5000420 NbrPorts 5
Starting the controller
USB XHCI 1.00
scanning bus xhci_pci for devices... 2 USB Device(s) found
       scanning usb for storage devices... 0 Storage Device(s) found
Hit any key to stop autoboot:  0
U-Boot>
U-Boot> help
?         - alias for 'help'
base      - print or set address offset
bdinfo    - print Board Info structure
blkcache  - block cache diagnostics and control
boot      - boot default, i.e., run 'bootcmd'
bootd     - boot default, i.e., run 'bootcmd'
bootefi   - Boots an EFI payload from memory
bootelf   - Boot from an ELF image in memory
booti     - boot Linux kernel 'Image' format from memory
bootm     - boot application image from memory
bootp     - boot image via network using BOOTP/TFTP protocol
bootvx    - Boot vxWorks from an ELF image
cmp       - memory compare
coninfo   - print console devices and information
cp        - memory copy
crc32     - checksum calculation
dhcp      - boot image via network using DHCP/TFTP protocol
dm        - Driver model low level access
echo      - echo args to console
editenv   - edit environment variable
env       - environment handling commands
exit      - exit script
ext2load  - load binary file from a Ext2 filesystem
ext2ls    - list files in a directory (default /)
ext4load  - load binary file from a Ext4 filesystem
ext4ls    - list files in a directory (default /)
ext4size  - determine a file's size
false     - do nothing, unsuccessfully
fatinfo   - print information about filesystem
fatload   - load binary file from a dos filesystem
fatls     - list files in a directory (default /)
fatmkdir  - create a directory
fatrm     - delete a file
fatsize   - determine a file's size
fatwrite  - write file into a dos filesystem
fdt       - flattened device tree utility commands
fstype    - Look up a filesystem type
fstypes   - List supported filesystem types
fsuuid    - Look up a filesystem UUID
go        - start application at address 'addr'
gpio      - query and control gpio pins
gzwrite   - unzip and write memory to block device
help      - print command description/usage
iminfo    - print header information for application image
imxtract  - extract a part of a multi-image
itest     - return true/false on integer compare
lcdputs   - print string on video framebuffer
ln        - Create a symbolic link
load      - load binary file from a filesystem
loadb     - load binary file over serial line (kermit mode)
loads     - load S-Record file over serial line
loadx     - load binary file over serial line (xmodem mode)
loady     - load binary file over serial line (ymodem mode)
loop      - infinite loop on address range
ls        - list files in a directory (default /)
lzmadec   - lzma uncompress a memory region
md        - memory display
mdio      - MDIO utility commands
mii       - MII utility commands
mm        - memory modify (auto-incrementing address)
mmc       - MMC sub system
mmcinfo   - display MMC info
mw        - memory write (fill)
net       - NET sub-system
nfs       - boot image via network using NFS protocol
nm        - memory modify (constant address)
panic     - Panic with optional message
part      - disk partition related commands
pci       - list and access PCI Configuration Space
ping      - send ICMP ECHO_REQUEST to network host
pinmux    - show pin-controller muxing
printenv  - print environment variables
pxe       - commands to get and boot from pxe files
random    - fill memory with random pattern
reset     - Perform RESET of the CPU
run       - run commands in an environment variable
save      - save file to a filesystem
saveenv   - save environment variables to persistent storage
setcurs   - set cursor position within screen
setenv    - set environment variables
setexpr   - set environment variable as the result of eval expression
showvar   - print local hushshell variables
size      - determine a file's size
sleep     - delay execution for some time
source    - run script from memory
sysboot   - command to get and boot from syslinux files
test      - minimal test like /bin/sh
tftpboot  - boot image via network using TFTP protocol
true      - do nothing, successfully
unlz4     - lz4 uncompress a memory region
unzip     - unzip a memory region
usb       - USB sub-system
usbboot   - boot from USB device
version   - print monitor, compiler and linker version
U-Boot>
leon-anavi commented 7 months ago

@ejoerns should we move on and merge this pull request?

@matthiasklein thank you for your contribution to meta-rauc-community and the provided feedback for improvements.

leon-anavi commented 7 months ago

I think this GitHub pull request makes sense so I merged it. I tested it as part of my efforts for porting RAUC to BeagleBone Black: https://github.com/rauc/meta-rauc-community/pull/77

@matthiasklein thank you for your contribution to meta-rauc-community!