Is it possible to flash u-boot from OpenWrt?

On an espressobin board mvebu, I got the u-boot on spi flash :

root@LPM:~# cat /proc/mtd 
dev:    size   erasesize  name
mtd0: 00400000 00010000 "spi0.0"

uboot envs are :

root@LPM:~# cat /etc/fw_env.config 
/dev/mtd0 0x3f0000 0x10000 0x10000 1

My question, is it possible to flash (write) uboot binary from OpenWrt ?
What will be the necessary tools and command line ?

from uboot I can use bubt command, how can I do the same from OpenWrt ?

Do I need to reboot to modify env setting of the env flashed uboot ?

Thanks

I hope you realize an incorrect uboot will brick your device.

1 Like

Sure, but the mvebu is full of recovery possibility, already tested...

Thanks

on another board I get 2 mtd :

OPENWRT_RELEASE="OpenWrt 19.07.4 r11208-ce6496d796"

[    2.986573] m25p80 spi0.0: mx25u3235f (4096 Kbytes)
[    2.991596] 2 fixed-partitions partitions found on MTD device spi0.0
[    2.998216] Creating 2 MTD partitions on "spi0.0":
[    3.002814] 0x000000000000-0x0000003f0000 : "firmware"
[    3.008781] 0x0000003f0000-0x000000400000 : "u-boot-env"
root@C3BOX:~# uname -ar
Linux C3BOX 4.14.195 #0 SMP Sun Sep 6 16:19:39 2020 aarch64 GNU/Linux
root@C3BOX:~# cat /proc/mtd 
dev:    size   erasesize  name
mtd0: 003f0000 00010000 "firmware"
mtd1: 00010000 00010000 "u-boot-env"
root@C3BOX:~# cat /etc/fw_env.config 
/dev/mtd1 0x0000 0x10000 0x10000 1

root@C3BOX:~# wget https://downloads.openwrt.org/snapshots/targets/mvebu/cortexa53/trusted-firmware-a-espressobin-v7-1gb/flash-image.bin

root@C3BOX:~# hexdump /dev/mtd0 | head
0000000 0600 0003 4d48 5449 0000 0000 2020 2411
0000010 564c 4d52 0000 0000 ffff ffff ffff ffff
0000020 ffff ffff ffff ffff 490a 5350 0003 0000
0000030 0000 0000 0c5c 0000 4d48 5449 4d49 5754
0000040 0000 0000 6000 2000 0dd8 0000 0dd8 0000
0000050 0020 0000 5859 f3e0 fe09 84ba cdee 8ea4
0000060 77d0 6ba7 e6ea 6eeb b844 c277 7f4f 15f7
0000070 4a9f c308 0000 0000 0000 0000 0000 0000
0000080 0000 0000 0000 0000 0000 0000 0000 0000
*
root@C3BOX:~# hexdump flash-image.bin | head
0000000 0600 0003 4d48 5449 0000 0000 2021 0403
0000010 564c 4d52 0000 0000 ffff ffff ffff ffff
0000020 ffff ffff ffff ffff 490a 5350 0003 0000
0000030 0000 0000 0b78 0000 4d48 5449 4d49 5754
0000040 0000 0000 6000 2000 0cf4 0000 0cf4 0000
0000050 0020 0000 672c f00f 5511 9834 b528 fbb0
0000060 e27c 5655 667d 8b26 b73f 6f9c acfb 4763
0000070 a108 6cb8 0000 0000 0000 0000 0000 0000
0000080 0000 0000 0000 0000 0000 0000 0000 0000
*
root@C3BOX:~# dd if=/dev/mtd0 of=flash_spi0.0.bin
8064+0 records in
8064+0 records out
root@C3BOX:~# hexdump flash_spi0.0.bin | head
0000000 0600 0003 4d48 5449 0000 0000 2020 2411
0000010 564c 4d52 0000 0000 ffff ffff ffff ffff
0000020 ffff ffff ffff ffff 490a 5350 0003 0000
0000030 0000 0000 0c5c 0000 4d48 5449 4d49 5754
0000040 0000 0000 6000 2000 0dd8 0000 0dd8 0000
0000050 0020 0000 5859 f3e0 fe09 84ba cdee 8ea4
0000060 77d0 6ba7 e6ea 6eeb b844 c277 7f4f 15f7
0000070 4a9f c308 0000 0000 0000 0000 0000 0000
0000080 0000 0000 0000 0000 0000 0000 0000 0000
*

root@C3BOX:~# fw_printenv 
arch=arm
baudrate=115200
board=mvebu_armada-37xx
board_name=mvebu_armada-37xx
boot_a_script=load ${devtype} ${devnum}:${distro_bootpart} ${scriptaddr} ${prefix}${script}; source ${scriptaddr}
boot_efi_binary=if fdt addr ${fdt_addr_r}; then bootefi bootmgr ${fdt_addr_r};else bootefi bootmgr ${fdtcontroladdr};fi;load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} efii
boot_extlinux=sysboot ${devtype} ${devnum}:${distro_bootpart} any ${scriptaddr} ${prefix}${boot_syslinux_conf}
boot_net_usb_start=usb start
boot_pci_enum=pci enum
boot_prefixes=/ /boot/
boot_script_dhcp=boot.scr.uimg
boot_scripts=boot.scr.uimg boot.scr
boot_syslinux_conf=extlinux/extlinux.conf
boot_targets=mmc1 mmc0 usb0 scsi0 pxe dhcp 
bootargs=console=ttyMV0,115200 earlycon=ar3700_uart,0xd0012000 root=/dev/mmcblk1p2 rw rootwait net.ifnames=0 biosdevname=0
bootcmd=mmc dev 1; ext4load mmc 1:1 $kernel_addr $image_name; ext4load mmc 1:1 $fdt_addr $fdt_name; setenv bootargs $console root=/dev/mmcblk0p2 rw rootwait net.ifnames=0 biosdevname=0;r
bootcmd_dhcp=run boot_net_usb_start; run boot_pci_enum; if dhcp ${scriptaddr} ${boot_script_dhcp}; then source ${scriptaddr}; fi;setenv efi_fdtfile ${fdtfile}; setenv efi_old_vci ${boot;
bootcmd_mmc0=devnum=0; run mmc_boot
bootcmd_mmc1=devnum=1; run mmc_boot
bootcmd_pxe=run boot_net_usb_start; run boot_pci_enum; dhcp; if pxe get; then pxe boot; fi
bootcmd_scsi0=devnum=0; run scsi_boot
bootcmd_usb0=devnum=0; run usb_boot
bootdelay=2
console=console=ttyMV0,115200 earlycon=ar3700_uart,0xd0012000
cpu=armv8
distro_bootcmd=scsi_need_init=; for target in ${boot_targets}; do run bootcmd_${target}; done
efi_dtb_prefixes=/ /dtb/ /dtb/current/
eth1addr=F0:AD:4E:08:AB:2B
eth2addr=F0:AD:4E:08:AB:2C
eth3addr=F0:AD:4E:08:AB:2D
eth4addr=F0:AD:4E:08:AB:2E
eth5addr=F0:AD:4E:08:AB:2F
ethaddr=F0:AD:4E:08:AB:2A
fdt_addr=0x6f00000
fdt_addr_r=0x6f00000
fdt_name=armada-3720-espressobin-v7-emmc.dtb
fdtcontroladdr=3fb26350
fileaddr=7000000
filesize=90a808
image_name=Image
kernel_addr=0x7000000
kernel_addr_r=0x7000000
load_efi_dtb=load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} ${prefix}${efi_fdtfile}
mmc_boot=if mmc dev ${devnum}; then devtype=mmc; run scan_dev_for_boot_part; fi
pxefile_addr_r=0x6e00000
ramdisk_addr_r=0xa000000
scan_dev_for_boot=echo Scanning ${devtype} ${devnum}:${distro_bootpart}...; for prefix in ${boot_prefixes}; do run scan_dev_for_extlinux; run scan_dev_for_scripts; done;run scan_dev_for;
scan_dev_for_boot_part=part list ${devtype} ${devnum} -bootable devplist; env exists devplist || setenv devplist 1; for distro_bootpart in ${devplist}; do if fstype ${devtype} ${devnum}t
scan_dev_for_efi=setenv efi_fdtfile ${fdtfile}; for prefix in ${efi_dtb_prefixes}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${efi_fdtfile}; then run load_efi_dtb; e
scan_dev_for_extlinux=if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${boot_syslinux_conf}; then echo Found ${prefix}${boot_syslinux_conf}; run boot_extlinux; echo SCRIPT Fi
scan_dev_for_scripts=for script in ${boot_scripts}; do if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}${script}; then echo Found U-Boot script ${prefix}${script}; run boot_e
scriptaddr=0x6d00000
scsi_boot=run scsi_init; if scsi dev ${devnum}; then devtype=scsi; run scan_dev_for_boot_part; fi
scsi_init=if ${scsi_need_init}; then scsi_need_init=false; scsi scan; fi
soc=mvebu
stderr=serial@12000
stdin=serial@12000
stdout=serial@12000
usb_boot=usb start; if usb dev ${devnum}; then devtype=usb; run scan_dev_for_boot_part; fi
vendor=Marvell

may be will give a try with :

root@C3BOX:~# mtd write flash-image.bin /dev/mtd0
Unlocking /dev/mtd0 ...

Writing from flash-image.bin to /dev/mtd0 ...

need to reboot (and cross fingers)

YES !!!

Works fine ! from OpenWrt 19.07.4 !

[  951.910586] reboot: Restarting system
TIM-1.0
WTMI-devel-18.12.1-5598e150
WTMI: system early-init
SVC REV: 4, CPU VDD voltage: 1.120V
NOTICE:  Booting Trusted Firmware
NOTICE:  BL1: v2.4(release):OpenWrt v2.4-1 (espressobin-v7-1gb) (Marvell-devel-18.12.0)
NOTICE:  BL1: Built : 21:56:15, Mar  3 2021
NOTICE:  BL1: Booting BL2
NOTICE:  BL2: v2.4(release):OpenWrt v2.4-1 (espressobin-v7-1gb) (Marvell-devel-18.12.0)
NOTICE:  BL2: Built : 21:56:15, Mar  3 2021
NOTICE:  BL1: Booting BL31
NOTICE:  BL31: v2.4(release):OpenWrt v2.4-1 (espressobin-v7-1gb) (Marvell-devel-18.12.0)
NOTICE:  BL31: Built : 21:5

U-Boot 2021.01 (Mar 03 2021 - 21:56:15 +0000)

DRAM:  1 GiB
Comphy-0: USB3_HOST0    5 Gbps    
Comphy-1: PEX0          2.5 Gbps  
Comphy-2: SATA0         5 Gbps    
SATA link 0 timeout.
AHCI 0001.0300 32 slots 1 ports 6 Gbps 0x1 impl SATA mode
flags: ncq led only pmp fbss pio slum part sxs 
PCIE-0: Link down
MMC:   sdhci@d0000: 0, sdhci@d8000: 1
Loading Environment from SPIFlash... SF: Detected mx25u3235f with page size 256 Bytes, erase size 4 KiB, total 4 MiB
OK
Model: Globalscale Marvell ESPRESSOBin Board
Net:   eth0: neta@30000
Hit any key to stop autoboot:  0 
=> version   
U-Boot 2021.01 (Mar 03 2021 - 21:56:15 +0000)

aarch64-openwrt-linux-musl-gcc (OpenWrt GCC 8.4.0 r16086-20caa68fec) 8.4.0
GNU ld (GNU Binutils) 2.34
=> 

works also fine from 19.07.7...
I have saved and restored the env uboot with
fw_printenv > fw_env.sov
then mtd write to flash u-boot
then
fw_setenv --script fw_env.sov
then reboot !

1 Like

You might need kmod-mtd-rw in some cases as well.

1 Like

Depending on where the u-boot settings are stored, you might not even need to backup them up.
Seems you have a mtd1 - u-boot-env, I would assume the settings are stored there.

Not saying you shouldn't, just that you aren't overwriting them when you update the uboot itself.

1 Like

updated an examples in wiki : https://openwrt.org/docs/techref/mtd#example_flash_u-boot_from_openwrt

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.