Makefile (7620 platform) help needed

Need help to make the appropriate amendments to my makefile mt7620.mk. If we write the following, it overwrites the existing macros for KERNEL, right?:

  KERNEL := $(KERNEL_DTB) | etc

xyz-initramfs-kernel.bin boots fine via TFTP when it's built with:

  KERNEL := $(KERNEL_DTB) | uImage lzma

Presumably because the vmlinux-initramfs which goes in at the start is kosher.

I'm trying to produce a factory.bin which will pass the OEM firmware's pre-upgrade checks. I need these steps in this order (according to OEM makefile):

  • build vmlinux as normal
  • lzma it

( this is $(KERNEL_DTB) )

  • append magic string xYz
  • pad the above to specific kernel size
  • append ramfs (I suppose rootfs, also)
  • pad the above to specific image size
  • run mkimage or uImage to prepend the 64 byte header

When I supply any of these images to tftp boot them - they boot (only outputting Starting kernel ... if I choose vmlinux and not vmlinux-initramfs) or reset depending on what's wrong. Help?

I've been trawling the other makefiles and commands - I'm none the wiser.

So, my makefile portion:

define Device/zyxel_wre6505
  MTK_SOC := mt7620a
# image size is 3977216, less 64 byte mkimage haeder
  IMAGE_SIZE:= 3977152
# kernel size must be 1179648 (0x120000) bytes, less 64 byte mkimage header
  KRNL_SIZE := 1179584
  DEVICE_VENDOR := ZyXEL
  DEVICE_MODEL := WRE650
  KERNEL := $(KERNEL_DTB) | append-string-newline EdI0412zYx | pad-to 1179584
  IMAGES += factory.bin
  IMAGE/factory.bin:= append-kernel | append-rootfs | pad-to $$$$(IMAGE_SIZE) | uImage lzma 
  DEVICE_PACKAGES := ...
  SUPPORTED_DEVICES += zyxel_wre6505
endef
TARGET_DEVICES += zyxel_wre6505

This briefly (tftp)boots and resets:

done
Bytes transferred = 3977216 (3cb000 hex)
NetBootFileXferSize= 003cb000
Automatic boot of image at addr 0x80A00000 ...
## Booting image at 80a00000 ...
   Image Name:   MIPS OpenWrt Linux-4.14.134
   Image Type:   MIPS Linux Kernel Image (lzma compressed)
   Data Size:    3977152 Bytes =  3.8 MB
   Load Address: 80000000
   Entry Point:  80000000
   Verifying Checksum ... OK
   Uncompressing Kernel Image ... OK
No initrd
## Transferring control to Linux (at address 80000000) ...
## Giving linux memsize in MB, 64

Starting kernel ...



U-Boot 1.1.3 (Apr 13 2015 - 19:08:43)

I realise that rootfs and ramfs are not the same thing - how do I reconcile this?

Here's the OEM makefile:

KERNELZ = $(IMAGEDIR)/zImage
RAMDISK  = $(IMAGEDIR)/ramdisk
IMAGE = $(IMAGEDIR)/$(USER)_uImage
ROMFS_DIR = $(ROOTDIR)/romfs

RAMDISK_SIZE  := $(shell echo $(CONFIG_BLK_DEV_RAM_SIZE))
MKIMAGE_DIR = $(ROOTDIR)/user/mkimage
CUR_DIR = $(shell pwd)
COMP = lzma

ROMFS_DIRS = \
	tmp \
	bin \
	dev dev/pts \
	home \
	etc \
	etc_ro etc_ro/web etc_ro/ppp etc_ro/ppp/peers etc_ro/ppp/plugins etc_ro/ppp/3g \
	etc_ro/wlan etc_ro/Wireless etc_ro/xml etc_ro/usb \
	etc_ro/linuxigd etc_ro/Wireless/RT2860AP etc_ro/Wireless/RT61AP etc_ro/Wireless/iNIC \
	lib lib/modules lib/ipsec \
	mnt \
	proc \
	sbin \
	sys \
	media \
	usr usr/bin usr/sbin usr/codepages \
	var 

clean:
	rm -f mkimage

romfs: 
	[ -d $(ROMFSDIR)/$$i ] || mkdir -p $(ROMFSDIR)
	for i in $(ROMFS_DIRS); do \
		[ -d $(ROMFSDIR)/$$i ] || mkdir -p $(ROMFSDIR)/$$i; \
	done
	#generate device node
ifneq	($(LINUXDIR),linux-2.4.x)
	@if [ \! -d $(ROMFSDIR)/dev ];then mkdir -p $(ROMFSDIR)/dev;fi;
	./makedevlinks $(ROMFSDIR)
endif
	$(ROMFSINST) /etc_ro/rcS
	$(ROMFSINST) /etc_ro/inittab
	$(ROMFSINST) /etc_ro/motd
	$(ROMFSINST) /etc/fstab

	$(ROMFSINST) /etc_ro/wlan/MT7620_AP_2T2R-4L_V13.BIN

	$(ROMFSINST) /etc_ro/Wireless/RT2860AP/RT2860_default_novlan
	$(ROMFSINST) /etc_ro/Wireless/RT2860AP/RT2860_default_vlan
	$(ROMFSINST) /etc_ro/Wireless/iNIC/RT2860AP.dat
	$(ROMFSINST) -e CONFIG_RT2860V2_AP_RBUS_PCI_COEX_SUPPORT /etc_ro/Wireless/RT2860APCard.dat

	$(ROMFSINST) -e CONFIG_RT5592_AP /etc_ro/Wireless/iNIC/RT5592_PCIe_2T2R_V1_7.bin
	$(ROMFSINST) -e CONFIG_RT5592_AP_INCLUDE /etc_ro/Wireless/iNIC/RT5592_PCIe_2T2R_V1_7.bin

romfs.post:: 
	@cp -af drivers $(ROMFSDIR)/lib/modules/2.6.36/kernel/
	@cp -af gpio $(ROMFSDIR)/bin/
	@cp -af mii_mgr $(ROMFSDIR)/bin/
	[ -d $(IMAGEDIR) ] || mkdir -p $(IMAGEDIR)
	
	#Squash File System
	 rm -f $(RAMDISK)  
ifeq	($(LINUXDIR),linux-2.4.x)
	$(CONFIG_CROSS_COMPILER_PATH)/mksquashfs_lzma-3.0 $(ROMFSDIR) $(RAMDISK)
else
	#linux2.6.x support squashfs with lzma
ifeq	($(CONFIG_BLK_DEV_INITRD),)

ifeq	($(LINUXDIR),linux-2.6.21.x)
	$(CONFIG_CROSS_COMPILER_PATH)/mksquashfs_lzma-3.2 $(ROMFSDIR) $(RAMDISK)
endif
ifeq	($(LINUXDIR),linux-2.6.36MT.x)
	$(CONFIG_CROSS_COMPILER_PATH)/mksquashfs_lzma-4.2 $(ROMFSDIR) $(RAMDISK)
endif
ifeq	($(LINUXDIR),linux-2.6.36.x)
	$(CONFIG_CROSS_COMPILER_PATH)/mksquashfs_lzma-4.2 $(ROMFSDIR) $(RAMDISK)
endif
endif
endif

ifeq	($(CONFIG_BLK_DEV_INITRD),y)
ifeq	($(LINUXDIR),linux-2.4.x)
	gzip -9 -f $(RAMDISK)
	cp $(RAMDISK).gz $(ROOTDIR)/$(LINUXDIR)/arch/mips/ramdisk/ramdisk.gz 2>/dev/null
endif
endif


mkimage: $(MKIMAGE_DIR)/crc32.c $(MKIMAGE_DIR)/mkimage.c 
	$(HOSTCC) $(HOST_CFLAGS) -DUSE_HOSTCC -o $@ -I$(MKIMAGE_DIR)/include $^ 

image: mkimage
	$(CROSS_COMPILE)objcopy -O binary -R .note -R .comment -S $(ROOTDIR)/$(LINUXDIR)/vmlinux  $(KERNELZ)
	cd $(IMAGEDIR) ; rm -f $(KERNELZ).*; $(COMP) -9 -f -S .$(COMP) $(KERNELZ)

ifeq	($(CONFIG_BLK_DEV_INITRD),)
ifeq	($(CONFIG_ROOTFS_IN_FLASH_NO_PADDING),)
	@#============================================================
	@# uboot hdr(64B) + mtdblock0(192KB) + mtdblock1(64KB) + 
	@# mtdblock2(64KB) + mtdblock3 + mtdblock4 + mtdblock5
	@# 
	@# Padding size of mtdblock3 is equal to "MTD_KRN_PART_SIZE 
	@# - 64B - the size of compressed kernel image"
	@#
	@# In Other Words:
	@# MTD Kernel Partition Size is MUST bigger than 
	@# "Original Kernel Image Size + 64B"
	@#============================================================
	#========<< This is README not Warning Message>>==============
	# Please make sure that original kernel image size can't 
	# bigger or equal to Kernel Partition Size. 
	#
	# For Example:
	# 
	# Original kernel image size is 563421 Bytes(0x898DD Bytes).
	# Flash sector size is 0x10000, so MTD kernel 
	# partition size MUST bigger than 0x90000.
	#
	# #make menuconfig
	#
	# Kernel/Library/Defaults Selection  --->
	#   [*] Customize Kernel Settings (NEW)
	#      Machine selection  --->
	#        (90000) MTD Kernel Partition Size (Unit:Bytes)
	#=============================================================
	# Original Kernel Image Size
	# EDIMAX: Arvin add
	  @cp -f $(KERNELZ).$(COMP) $(KERNELZ).$(COMP).org
	  @echo "EdI0412zYx" >> $(KERNELZ).$(COMP)
	  @wc -c $(KERNELZ).$(COMP)
	# Padded Kernel Image Size 
ifeq    ($(findstring 0x, $(CONFIG_MTD_KERNEL_PART_SIZ)),0x)
	  @SIZE=`wc -c $(KERNELZ).$(COMP) | awk '{ print $$1 }'` ; \
	   MTD_KRN_PART_SIZE=`printf "%d" $(CONFIG_MTD_KERNEL_PART_SIZ)` ; \
	   PAD=`expr $$MTD_KRN_PART_SIZE - 64 - $$SIZE` ; \
	   dd if=/dev/zero count=1 bs=$$PAD 2> /dev/null | tr \\000 \\377 >> $(KERNELZ).$(COMP)
else
	  @SIZE=`wc -c $(KERNELZ).$(COMP) | awk '{ print $$1 }'` ; \
	   MTD_KRN_PART_SIZE=`printf "%d" 0x$(CONFIG_MTD_KERNEL_PART_SIZ)` ; \
	   PAD=`expr $$MTD_KRN_PART_SIZE - 64 - $$SIZE` ; \
	   dd if=/dev/zero count=1 bs=$$PAD 2> /dev/null | tr \\000 \\377 >> $(KERNELZ).$(COMP)
endif
endif
	@wc -c $(KERNELZ).$(COMP)
	# Original RootFs Size 
	  @du -sb $(ROMFSDIR)
	# Compressed RootFs Size 
	  @wc -c $(RAMDISK)
	# Padded Kernel Image + Compressed Rootfs Size
	  @cat $(RAMDISK) >> $(KERNELZ).$(COMP) 
	  @wc -c $(KERNELZ).$(COMP)
	#===========================================
endif
ifeq	($(CONFIG_ROOTFS_IN_FLASH_NO_PADDING),y)
	@cd $(IMAGEDIR) ; \
	ISIZE=`wc -c $(KERNELZ).$(COMP) | awk '{print $$1}'` ; \
	RSIZE=`wc -c $(RAMDISK) | awk '{print $$1}'` ; \
	KRN_SIZE=`expr $$ISIZE - $$RSIZE + 64` ; \
	ENTRY=`readelf -h $(ROOTDIR)/$(LINUXDIR)/vmlinux | grep "Entry" | awk '{print $$4}'` ; \
	$(CUR_DIR)/mkimage -A mips -O linux -T kernel -C $(COMP) -a 80000000 -e $$ENTRY -k $$KRN_SIZE -n "Linux Kernel Image" -d $(KERNELZ).$(COMP) $(IMAGE)
else
	@cd $(IMAGEDIR) ; $(CUR_DIR)/mkimage -A mips -O linux -T kernel -C $(COMP) -a 80000000 -e $(shell readelf -h $(ROOTDIR)/$(LINUXDIR)/vmlinux | grep "Entry" | awk '{print $$4}') -n "Linux Kernel Image"  -d $(KERNELZ).$(COMP) $(IMAGE)
endif

Here are the logs relevant to the image production (might be extra line-feeds in there):

make[5]: Nothing to be done for 'modules'.
make[5]: Leaving directory '/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/linux-4.14.134'
cmp -s /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/linux-4.14.134/vmlinux /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/vmlinux-initramfs.debug || { mipsel-openwrt-linux-musl-objcopy -O binary -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -S /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/linux-4.14.134/vmlinux /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/vmlinux-initramfs; mipsel-openwrt-linux-musl-objcopy -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -S /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/linux-4.14.134/vmlinux /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/vmlinux-initramfs.elf; cp -fpR /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/linux-4.14.134/vmlinux /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/vmlinux-initramfs.debug;  }
touch /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/linux-4.14.134/.image
make -C image compile install TARGET_BUILD=
make[5]: Entering directory '/home/user/openwrt/target/linux/ramips/image'
make[5]: Nothing to be done for 'compile'.
mipsel-openwrt-linux-musl-cpp -nostdinc -x assembler-with-cpp -I/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/linux-4.14.134/arch/mips/boot/dts -I/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/linux-4.14.134/arch/mips/boot/dts/include -I/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/linux-4.14.134/include/ -undef -D__DTS__  -o /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/image-mt7620a_zyxel_wre6505.dtb.tmp ../dts/mt7620a_zyxel_wre6505.dts
/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/linux-4.14.134/scripts/dtc/dtc -O dtb -i../dts/ -Wno-unit_address_vs_reg -Wno-unit_address_vs_reg -Wno-simple_bus_reg -Wno-unit_address_format -Wno-pci_bridge -Wno-pci_device_bus_num -Wno-pci_device_reg  -o /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/image-mt7620a_zyxel_wre6505.dtb /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/image-mt7620a_zyxel_wre6505.dtb.tmp
rm -f /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/image-mt7620a_zyxel_wre6505.dtb.tmp
mkdir -p /home/user/openwrt/bin/targets/ramips/mt7620 /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp
/home/user/openwrt/staging_dir/host/bin/mksquashfs4 /home/user/openwrt/build_dir/target-mipsel_24kc_musl/root-ramips /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/root.squashfs -nopad -noappend -root-owned -comp xz -Xpreset 9 -Xe -Xlc 0 -Xlp 2 -Xpb 2  -b 256k -p '/dev d 755 0 0' -p '/dev/console c 600 0 0 5 1' -processors 1
Parallel mksquashfs: Using 1 processor
Creating 4.0 filesystem on /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/root.squashfs, block size 262144.
Pseudo file "/dev" exists in source filesystem "/home/user/openwrt/build_dir/target-mipsel_24kc_musl/root-ramips/dev".
Ignoring, exclude it (-e/-ef) to override.
[====================================================================================================================================================================================================|] 366/366 100%

Exportable Squashfs 4.0 filesystem, xz compressed, data block size 262144
        compressed data, compressed metadata, compressed fragments,
        no xattrs, compressed ids
        duplicates are removed
Filesystem size 1342.13 Kbytes (1.31 Mbytes)
        38.19% of uncompressed filesystem size (3514.69 Kbytes)
Inode table size 3946 bytes (3.85 Kbytes)
        20.03% of uncompressed inode table size (19697 bytes)
Directory table size 5796 bytes (5.66 Kbytes)
        50.27% of uncompressed directory table size (11529 bytes)
Number of duplicate files found 52
Number of inodes 588
Number of files 363
Number of fragments 7
Number of symbolic links  165
Number of device nodes 1
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 59
Number of ids (unique uids + gids) 1
Number of uids 1
        root (0)
Number of gids 1
        root (0)
rm -f /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-initramfs-kernel.bin
cp /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/vmlinux-initramfs /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-initramfs-kernel.bin
cat /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/image-mt7620a_zyxel_wre6505.dtb >> /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-initramfs-kernel.bin
/home/user/openwrt/staging_dir/host/bin/lzma e /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-initramfs-kernel.bin -lc1 -lp2 -pb2  /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-initramfs-kernel.bin.new
echo -n EdI0412zYx >> /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-initramfs-kernel.bin
dd if=/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-initramfs-kernel.bin of=/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-initramfs-kernel.bin.new bs=1179584 conv=sync
2+1 records in
3+0 records out
3538752 bytes (3.5 MB, 3.4 MiB) copied, 0.00323622 s, 1.1 GB/s
mv /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-initramfs-kernel.bin.new /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-initramfs-kernel.bin
cp /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-initramfs-kernel.bin /home/user/openwrt/bin/targets/ramips/mt7620/openwrt-ramips-mt7620-zyxel_wre6505-initramfs-kernel.bin
rm -f /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/zyxel_wre6505-kernel.bin
cp /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/vmlinux /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/zyxel_wre6505-kernel.bin
cat /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/image-mt7620a_zyxel_wre6505.dtb >> /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/zyxel_wre6505-kernel.bin
/home/user/openwrt/staging_dir/host/bin/lzma e /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/zyxel_wre6505-kernel.bin -lc1 -lp2 -pb2  /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/zyxel_wre6505-kernel.bin.new
echo -n EdI0412zYx >> /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/zyxel_wre6505-kernel.bin
dd if=/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/zyxel_wre6505-kernel.bin of=/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/zyxel_wre6505-kernel.bin.new bs=1179584 conv=sync
0+1 records in
1+0 records out
1179584 bytes (1.2 MB, 1.1 MiB) copied, 0.00167373 s, 705 MB/s
mv /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/zyxel_wre6505-kernel.bin.new /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/zyxel_wre6505-kernel.bin
[ -f /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/zyxel_wre6505-kernel.bin -a -f /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/root.squashfs ]
dd if=/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/zyxel_wre6505-kernel.bin >> /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-sysupgrade.bin
2303+1 records in
2303+1 records out
1179584 bytes (1.2 MB, 1.1 MiB) copied, 0.0142913 s, 82.5 MB/s
dd if=/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/root.squashfs >> /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-sysupgrade.bin
2684+1 records in
2684+1 records out
1374342 bytes (1.4 MB, 1.3 MiB) copied, 0.0155616 s, 88.3 MB/s
/home/user/openwrt/staging_dir/host/bin/padjffs2 /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-sysupgrade.bin  4 8 16 64 128 256
padding image to 00270000
padding image to 00280000
echo '{  "metadata_version": "1.0", "supported_devices":["zyxel,wre6505","zyxel_wre6505"], "version": { "dist": "OpenWrt", "version": "SNAPSHOT", "revision": "r10684-a3a2b4857e", "target": "ramips/mt7620", "board": "zyxel_wre6505" } }' | fwtool -I - /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-sysupgrade.bin
[ ! -s "/home/user/openwrt/key-build" -o ! -s "/home/user/openwrt/key-build.ucert" -o ! -s "/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-sysupgrade.bin" ] || { cp "/home/user/openwrt/key-build.ucert" "/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-sysupgrade.bin.ucert" ; usign -S -m "/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-sysupgrade.bin" -s "/home/user/openwrt/key-build" -x "/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-sysupgrade.bin.sig" ; ucert -A -c "/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-sysupgrade.bin.ucert" -x "/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-sysupgrade.bin.sig" ; fwtool -S "/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-sysupgrade.bin.ucert" "/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-sysupgrade.bin" ; }
cp /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-sysupgrade.bin /home/user/openwrt/bin/targets/ramips/mt7620/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-sysupgrade.bin
[ -f /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/zyxel_wre6505-kernel.bin -a -f /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/root.squashfs ]
dd if=/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/zyxel_wre6505-kernel.bin >> /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-factory.bin
2303+1 records in
2303+1 records out
1179584 bytes (1.2 MB, 1.1 MiB) copied, 0.0146963 s, 80.3 MB/s
dd if=/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/root.squashfs >> /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-factory.bin
2684+1 records in
2684+1 records out
1374342 bytes (1.4 MB, 1.3 MiB) copied, 0.0157632 s, 87.2 MB/s
dd if=/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-factory.bin of=/home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-factory.bin.new bs=3977152 conv=sync
0+1 records in
1+0 records out
3977152 bytes (4.0 MB, 3.8 MiB) copied, 0.00550568 s, 722 MB/s
mv /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-factory.bin.new /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-factory.bin
mkimage -A mips -O linux -T kernel -C lzma -a 0x80000000 -e 0x80000000 -n 'MIPS OpenWrt Linux-4.14.134' -d /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-factory.bin /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-factory.bin.new
Image Name:   MIPS OpenWrt Linux-4.14.134
Created:      Mon Aug  5 20:37:46 2019
Image Type:   MIPS Linux Kernel Image (lzma compressed)
Data Size:    3977152 Bytes = 3883.94 KiB = 3.79 MiB
Load Address: 80000000
Entry Point:  80000000
mv /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-factory.bin.new /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-factory.bin
cp /home/user/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/tmp/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-factory.bin /home/user/openwrt/bin/targets/ramips/mt7620/openwrt-ramips-mt7620-zyxel_wre6505-squashfs-factory.bin
IPKG_NO_SCRIPT=1 IPKG_INSTROOT=/home/user/openwrt/build_dir/target-mipsel_24kc_musl/root.orig-ramips TMPDIR=/home/user/openwrt/build_dir/target-mipsel_24kc_musl/root.orig-ramips/tmp /home/user/openwrt/staging_dir/host/bin/opkg --offline-root /home/user/openwrt/build_dir/target-mipsel_24kc_musl/root.orig-ramips --force-postinstall --add-dest root:/ --add-arch all:100 --add-arch mipsel_24kc:200 list-installed > /home/user/openwrt/bin/targets/ramips/mt7620/openwrt-ramips-mt7620-device-zyxel-wre6505.manifest
make[5]: Leaving directory '/home/user/openwrt/target/linux/ramips/image'
make[4]: Leaving directory '/home/user/openwrt/target/linux/ramips'
make[3]: Leaving directory '/home/user/openwrt/target/linux'

well, i'll take a guess...

these seem to be the most relevant parts(ish) from the OEM Makefile...

	  @cp -f $(KERNELZ).$(COMP) $(KERNELZ).$(COMP).org
	  @echo "EdI0412zYx" >> $(KERNELZ).$(COMP)
	  @wc -c $(KERNELZ).$(COMP)
	# Padded Kernel Image Size 
ifeq    ($(findstring 0x, $(CONFIG_MTD_KERNEL_PART_SIZ)),0x)
	  @SIZE=`wc -c $(KERNELZ).$(COMP) | awk '{ print $$1 }'` ; \
	   MTD_KRN_PART_SIZE=`printf "%d" $(CONFIG_MTD_KERNEL_PART_SIZ)` ; \
	   PAD=`expr $$MTD_KRN_PART_SIZE - 64 - $$SIZE` ; \
	   dd if=/dev/zero count=1 bs=$$PAD 2> /dev/null | tr \\000 \\377 >> $(KERNELZ).$(COMP)

So... with your build.... I think to replicate... you'll be focusing where you are already..... it is well worth diving into the OEM .bins to shed physicality to your results.... as is backtracking into the factory generation code and poking around in the ./scripts directory.....

But the assignment i'd advice is biology 101... your task should you choose to accept it... is to deconstruct an OEM bin..... using dd, hexdump... binwalk.... fmk...... od..... cat..... file... strings..... etc. etc...

given that your pretty much have the picture above.... the aim is to very what you believe to be the case.....

( don't worry even if you don't have solid answers after an hour or few...... switch the .bin for the one you've built...... i'm sure you'll discover something you didn't know :wink:

I spent a few days doing stare and compare on the OEM and my binaries, to the extent they looked the same to binwalk. I can build identical layouts - but things differ somewhere enough that the OEM firmware doesn't accept mine - or I can't shore-horn more modern codebases or firmwares into the space given :frowning:

The biggest challenge being that the zYx magic must be found within the amount of bytes allocated to the kernel partition, and you also need to squeeze in kernel and ramdisk.... I cannot get kernel+squash to even output a single printk kernel message.