Skip to content

Commit

Permalink
image: simplify Linksys footer creation and fix alignment
Browse files Browse the repository at this point in the history
Current factory image sizes for Linksys devices are 256-byte aligned, while
OEM FW images appear aligned with the 128K erase blocksize. This is not an
issue writing factory images from the OpenWrt or Linksys GUIs, but can
lead to failures when using a TFTP client from the Linksys bootloader.

Simplify Linksys footer creation by migrating to a makefile build recipe,
and add footer pre-padding to ensure the proper final image size. Finally,
remove the linksys-image.sh script no longer needed.

Link: openwrt#11405 (comment)
Link: openwrt#11405 (comment)

Signed-off-by: Tony Ambardar <[email protected]>
  • Loading branch information
guidosarducci committed Oct 3, 2023
1 parent 868e43c commit 65cccfa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 67 deletions.
25 changes: 22 additions & 3 deletions include/image-commands.mk
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,30 @@ define Build/kernel-bin
cp $< $@
endef

# Linksys image footer (256 bytes) is appended to the factory image and tested
# by both the Linksys Upgrader (as observed in civic) and OpenWrt sysupgrade.
# Final file is $BLOCKSIZE aligned to satisfy some devices' TFTP clients, by
# preceding the footer with padding (0xFF).
# Footer format:
# .LINKSYS. Checked by Linksys upgrader before continuing. (9 bytes)
# <VERSION> Upgrade version number, unchecked so arbitrary. (8 bytes)
# <TYPE> Model of device, space padded (0x20). (15 bytes)
# <CRC> CRC checksum of factory image to flash. (8 bytes)
# <padding> Padding ('0' + 0x20 * 7) (8 bytes)
# <signature> Signature of signer, unchecked so arbitrary. (16 bytes)
# <padding> Padding with nulls (0x00) (192 bytes)
define Build/linksys-image
$(TOPDIR)/scripts/linksys-image.sh \
let \
size="$$(stat -c%s $@)" \
pad="$(subst k,* 1024,$(BLOCKSIZE))" \
offset="256" \
pad="(pad - ((size + offset) % pad)) % pad"; \
dd if=/dev/zero bs=$$pad count=1 | tr '\000' '\377' >> $@
printf ".LINKSYS.01000409%-15s%08X%-8s%-16s" \
"$(call param_get_default,type,$(1),$(DEVICE_NAME))" \
$@ $@.new
mv $@.new $@
"$$(cksum $@ | cut -d ' ' -f1)" \
"0" "K0000000F0246434" >> $@
dd if=/dev/zero bs=192 count=1 >> $@
endef

define Build/lzma
Expand Down
64 changes: 0 additions & 64 deletions scripts/linksys-image.sh

This file was deleted.

0 comments on commit 65cccfa

Please sign in to comment.