How to create intermediate image that allows normal sysupgrade image to be installed

Hello

I have an old NAS device, D-Link DNS-323, for which I am trying to create an OpenWrt image. I have now a factory image and a initramfs-kernel image but neither allows me to flash a sysupgrade image.

Note, I am working on top of 21.02 at the moment because later versions create too big a kernel image to be accepted by the vendor firmware.

I reckon this not that uncommon situation and I am missing something simply. Does platform.sh play a role in this? It effectively is default_do_upgrade "$1"

My image Makefile is such:

define Build/rename_tmp
	mv $@ $(KDIR_TMP)/$1
endef

define Build/cpiogz
	( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9n > $@.new )
	mv $@.new $@
endef

define Build/uRamdisk
	mkimage -A arm -O linux -T ramdisk -C gzip \
		-e $(RAMDISK_LOADADDR) -a $(RAMDISK_LOADADDR) \
		-n "Maukka ramdisk" -d $@ $@.new
	mv $@.new $@
endef

define Build/dns323-fw
	$(eval _kernel=$(KDIR_TMP)/$(word 1,$(1)))
	$(eval _rootfs=$(KDIR_TMP)/$(word 2,$(1)))
	$(STAGING_DIR_HOST)/bin/dns323-fw \
		-m -p 7 -c 1 -l 1 \
		-u 1 -v 4 -t 0 \
		-k $(_kernel) -i $(_rootfs) $@.new
	mv $@.new $@
endef

define Device/Default
  PROFILES := Default
#  DEVICE_DTS = orion5x-$(lastword $(subst _, ,$(1)))
#  KERNEL_DEPENDS = $$(wildcard $(DTS_DIR)/$$(DEVICE_DTS).dts)
#  KERNEL := kernel-bin | append-dtb | uImage none
  KERNEL := kernel-bin | uImage none
  KERNEL_NAME := zImage
  KERNEL_SUFFIX  := -uImage
  BLOCKSIZE := 64k
  IMAGES := sysupgrade.bin
  IMAGE/sysupgrade.bin := sysupgrade-tar | append-metadata
endef

define Device/dlink_dns323
  DEVICE_VENDOR := D-Link
  DEVICE_MODEL := DNS-323
  DEVICE_PACKAGES := kmod-gpio-button-hotplug kmod-usb2
  IMAGE_SIZE := 7872k
  IMAGES := sysupgrade.bin factory.bin kernel.img rootfs.img
  IMAGE/sysupgrade.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | append-rootfs |\
  	pad-rootfs | append-metadata | check-size
  IMAGE/factory.bin := append-kernel | pad-to $$$$(BLOCKSIZE) | rename_tmp part_1 | cpiogz | uRamdisk | pad-rootfs | rename_tmp part_2 | dns323-fw part_1 part_2
  IMAGE/kernel.img := append-kernel | pad-to $$$$(BLOCKSIZE)
  IMAGE/rootfs.img := cpiogz | uRamdisk | pad-rootfs
endef
TARGET_DEVICES += dlink_dns323

cat /proc/mtd

dev:    size   erasesize  name
mtd0: 00010000 00002000 "MTD1"
mtd1: 00010000 00010000 "MTD2"
mtd2: 007b0000 00010000 "firmware"
mtd3: 00030000 00010000 "u-boot"

mount # factory image

none on / type tmpfs (rw,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate)
none on /tmp type tmpfs (rw,nosuid,nodev,noatime,mode=1777)
none on /dev type tmpfs (rw,nosuid,relatime)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,mode=600,ptmxmode=000)
debugfs on /sys/kernel/debug type debugfs (rw,noatime)

mount # initramfs-kernel

none on / type tmpfs (rw,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate)
none on /tmp type tmpfs (rw,nosuid,nodev,noatime,mode=1777)
none on /dev type tmpfs (rw,nosuid,relatime)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,mode=600,ptmxmode=000)
debugfs on /sys/kernel/debug type debugfs (rw,noatime)

sysupgrade -n openwrt-orion5x-dlink_dns323-squashfs-sysupgrade.bin

Thu Oct 13 19:21:03 UTC 2022 upgrade: Commencing upgrade. Closing all shell sessions.
killall: telnetd: no process killed
Thu Oct 13 19:21:04 UTC 2022 upgrade: Sending TERM to remaining processes ... ntpd ubusd urngd uhttpd logd rpcd mdadm netifd
Thu Oct 13 19:21:07 UTC 2022 upgrade: Sending KILL to remaining processes ...
[  295.395824] sh (1314): drop_caches: 3
Thu Oct 13 19:21:08 UTC 2022 upgrade: Switching to ramdisk...
Thu Oct 13 19:21:12 UTC 2022 upgrade: Performing system upgrade...
[  299.306321] sh (1314): drop_caches: 3
Could not open mtd device: image
Can't open device for writing!
cat: write error: Broken pipe
sysupgrade abort[  299.357323] reboot: Restarting system
 ** LOADER **
 ** MARVELL BOARD: RD-88F5181-POS-NAS LE

Reviving this - did you ever get a working image?

The work on the dns323 has been on halt for quite some time now. I cannot really remember where I got exactly and I'd have to refresh myself on that. Are in interested in the dns323 device in particular or just creating that intermediate image? For another device I created an intermediate image where there is a initramfs kernel instead of normal kernel and I use that to flash the normal sysupgrade image.