Getting image into SPI Flash

I have built an image for an MT7628 based board.

I have full access to the board, including a serial console that's live during boot (u-boot) and has full root access after boot. I also have full access to the SPI Flash that contains the existing image.

The output directory for my build looks like this:

kenny@IS-28868:~/lede/lede/bin/targets/ramips/mt76x8$ pwd
/home/kenny/lede/lede/bin/targets/ramips/mt76x8
kenny@IS-28868:~/lede/lede/bin/targets/ramips/mt76x8$ ls
config.seed							openwrt-ramips-mt76x8-tplink_c20-v4-squashfs-tftp-recovery.bin
openwrt-imagebuilder-ramips-mt76x8.Linux-x86_64.tar.xz		openwrt-ramips-mt76x8-tplink_c50-v3-squashfs-sysupgrade.bin
openwrt-ramips-mt76x8-default.manifest				openwrt-ramips-mt76x8-tplink_c50-v3-squashfs-tftp-recovery.bin
openwrt-ramips-mt76x8-duzun-dm06-squashfs-sysupgrade.bin	openwrt-ramips-mt76x8-tplink_tl-mr3420-v5-squashfs-sysupgrade.bin
openwrt-ramips-mt76x8-gl-mt300n-v2-squashfs-sysupgrade.bin	openwrt-ramips-mt76x8-tplink_tl-mr3420-v5-squashfs-tftp-recovery.bin
openwrt-ramips-mt76x8-hc5661a-squashfs-sysupgrade.bin		openwrt-ramips-mt76x8-u7628-01-128M-16M-squashfs-sysupgrade.bin
openwrt-ramips-mt76x8-LinkIt7688-squashfs-sysupgrade.bin	openwrt-ramips-mt76x8-vocore2lite-squashfs-sysupgrade.bin
openwrt-ramips-mt76x8-mac1200r-v2-squashfs-sysupgrade.bin	openwrt-ramips-mt76x8-vocore2-squashfs-sysupgrade.bin
openwrt-ramips-mt76x8-miwifi-nano-squashfs-sysupgrade.bin	openwrt-ramips-mt76x8-wcr-1166ds-squashfs-factory.bin
openwrt-ramips-mt76x8-omega2p-squashfs-sysupgrade.bin		openwrt-ramips-mt76x8-wcr-1166ds-squashfs-sysupgrade.bin
openwrt-ramips-mt76x8-omega2-squashfs-sysupgrade.bin		openwrt-ramips-mt76x8-widora_neo-16m-squashfs-sysupgrade.bin
openwrt-ramips-mt76x8-pbr-d1-squashfs-sysupgrade.bin		openwrt-ramips-mt76x8-widora_neo-32m-squashfs-sysupgrade.bin
openwrt-ramips-mt76x8-tama_w06-squashfs-sysupgrade.bin		openwrt-ramips-mt76x8-wl-wn575a3-squashfs-sysupgrade.bin
openwrt-ramips-mt76x8-tl-wr840n-v4-squashfs-sysupgrade.bin	openwrt-ramips-mt76x8-wrtnode2p-squashfs-sysupgrade.bin
openwrt-ramips-mt76x8-tl-wr840n-v4-squashfs-tftp-recovery.bin	openwrt-ramips-mt76x8-wrtnode2r-squashfs-sysupgrade.bin
openwrt-ramips-mt76x8-tl-wr840n-v5-squashfs-sysupgrade.bin	openwrt-ramips-mt76x8-zbtlink_zbt-we1226-squashfs-sysupgrade.bin
openwrt-ramips-mt76x8-tl-wr841n-v13-squashfs-sysupgrade.bin	openwrt-sdk-ramips-mt76x8_gcc-5.5.0_musl.Linux-x86_64.tar.xz
openwrt-ramips-mt76x8-tl-wr841n-v13-squashfs-tftp-recovery.bin	packages
openwrt-ramips-mt76x8-tplink_c20-v4-squashfs-sysupgrade.bin	sha256sums
kenny@IS-28868:~/lede/lede/bin/targets/ramips/mt76x8$

How do I replace the existing image with my new image?

1 Like

There are several ways to do it.

  1. If the u-boot supports ramdisk image, it's strongly suggested to build a ramdisk image and upload it with the tftp protocol. In this way you can test the firmware safely.
  2. If the factory firmware is OpenWrt based, you can upload the squashfs image, then use 'sysupgrade -n' or 'mtd write'.
  3. Using the u-boot, you can upload the squashfs image with the tftp protocol.
  4. If you have a SPI flash programmer, just overwrite the squashfs image at the correct position.

Yes you should test from RAM first to be sure your image is going to work at all.

The "sysupgrade" bin from your build is byte for byte what goes into the flash chip with no extra headers. So this is what to use with any flashing method other than through the factory firmware, which only works with "factory" images having model-specific headers the factory firmware expects.

To expand on TFTP flashing with the bootloader, if you have the typical Ralink / MediaTek U-boot, first hit 4 on the serial console when it says "autobooting in X seconds" to get the bootloader prompt and printenv to see what IP addresses and file name the TFTP transfer expects. Then set up your TFTP server and reboot, pressing I think it is 3 to flash the Linux. Many of these bootloader builds do not support cp.b into flash, you have to use the canned one-step TFTP and flash routine.

1 Like

Thanks for the replies!
I can try all of those methods. I do have an SPI flash programmer, and a copy of the current flash contents, so I can easily restore things if I get in a mess.

Thanks again

@SpiderKenny Please place all code, configs, and log output within code blocks, not quote blocks.

Aye, sorry about that. It was my first time posting such things.
However I should have known better! I shall now subject myself to 20 lashes....