diff mbox series

ramips: use ARTIFACTS for initramfs-factory of I-O DATA WN-AX1167GR

Message ID 20221123032409.840-1-musashino.open@gmail.com
State Accepted
Delegated to: Daniel Golle
Headers show
Series ramips: use ARTIFACTS for initramfs-factory of I-O DATA WN-AX1167GR | expand

Commit Message

INAGAKI Hiroshi Nov. 23, 2022, 3:24 a.m. UTC
Use ARTIFACTS to generate initramfs-based factory image of I-O DATA
WN-AX1167GR instead of redundant recipe which generate on
KERNEL_INITRAMFS.

Note:

WN-AX1167GR has 2x OS images on stock firmware.

stock log:

flash manufacture id: c2, device id 20 18
MX25L12805D(c2 2018c220) (16384 Kbytes)
mtd .name = raspi, .size = 0x01000000 (16M) .erasesize = 0x00010000 (64K) .numeraseregions = 0
Creating 10 MTD partitions on "raspi":
0x000000000000-0x000001000000 : "ALL"
0x000000000000-0x000000030000 : "Bootloader"
0x000000030000-0x000000040000 : "Config "
0x000000040000-0x000000050000 : "Factory"
0x000000050000-0x000000060000 : "iNIC_rf"
0x000000060000-0x0000007e0000 : "Kernel"
0x000000800000-0x000000f80000 : "app"
0x000000f90000-0x000000fa0000 : "Key"
0x000000fa0000-0x000000fb0000 : "backup"
0x000000fb0000-0x000001000000 : "storage"

1st image is "Kernel" and 2nd is "app" when booted from 1st image.
In OpenWrt, those 2x partitions are combined to "firmware" with
undefined (empty) areas (0x7e0000-0x7fffff, 0xf80000-0xf8ffff).

The size of an OS image partition is 0x780000 (7680 KiB = 7.5 MiB), so
check-size for initramfs-factory image needs to be called with the size.

Signed-off-by: INAGAKI Hiroshi <musashino.open@gmail.com>
---
 target/linux/ramips/image/mt7621.mk | 24 +++++-------------------
 1 file changed, 5 insertions(+), 19 deletions(-)

Comments

Daniel Golle Nov. 29, 2022, 2:07 a.m. UTC | #1
On Wed, Nov 23, 2022 at 12:24:09PM +0900, INAGAKI Hiroshi wrote:
> Use ARTIFACTS to generate initramfs-based factory image of I-O DATA
> WN-AX1167GR instead of redundant recipe which generate on
> KERNEL_INITRAMFS.
> 
> Note:
> 
> WN-AX1167GR has 2x OS images on stock firmware.
> 
> stock log:
> 
> flash manufacture id: c2, device id 20 18
> MX25L12805D(c2 2018c220) (16384 Kbytes)
> mtd .name = raspi, .size = 0x01000000 (16M) .erasesize = 0x00010000 (64K) .numeraseregions = 0
> Creating 10 MTD partitions on "raspi":
> 0x000000000000-0x000001000000 : "ALL"
> 0x000000000000-0x000000030000 : "Bootloader"
> 0x000000030000-0x000000040000 : "Config "
> 0x000000040000-0x000000050000 : "Factory"
> 0x000000050000-0x000000060000 : "iNIC_rf"
> 0x000000060000-0x0000007e0000 : "Kernel"
> 0x000000800000-0x000000f80000 : "app"
> 0x000000f90000-0x000000fa0000 : "Key"
> 0x000000fa0000-0x000000fb0000 : "backup"
> 0x000000fb0000-0x000001000000 : "storage"
> 
> 1st image is "Kernel" and 2nd is "app" when booted from 1st image.
> In OpenWrt, those 2x partitions are combined to "firmware" with
> undefined (empty) areas (0x7e0000-0x7fffff, 0xf80000-0xf8ffff).
> 
> The size of an OS image partition is 0x780000 (7680 KiB = 7.5 MiB), so
> check-size for initramfs-factory image needs to be called with the size.
> 
> Signed-off-by: INAGAKI Hiroshi <musashino.open@gmail.com>
> ---
>  target/linux/ramips/image/mt7621.mk | 24 +++++-------------------
>  1 file changed, 5 insertions(+), 19 deletions(-)
> 
> diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk
> index 943fc62ecd..0e3f1cf0f5 100644
> --- a/target/linux/ramips/image/mt7621.mk
> +++ b/target/linux/ramips/image/mt7621.mk
> @@ -49,23 +49,6 @@ define Build/haier-sim_wr1800k-factory
>    $(CP) $(1) $(BIN_DIR)/
>  endef
>  
> -define Build/iodata-factory
> -	$(eval fw_size=$(word 1,$(1)))
> -	$(eval fw_type=$(word 2,$(1)))
> -	$(eval product=$(word 3,$(1)))
> -	$(eval factory_bin=$(word 4,$(1)))
> -	if [ -e $(KDIR)/tmp/$(KERNEL_INITRAMFS_IMAGE) -a "$$(stat -c%s $@)" -lt "$(fw_size)" ]; then \
> -		$(CP) $(KDIR)/tmp/$(KERNEL_INITRAMFS_IMAGE) $(factory_bin); \
> -		$(STAGING_DIR_HOST)/bin/mksenaofw \
> -			-r 0x30a -p $(product) -t $(fw_type) \
> -			-e $(factory_bin) -o $(factory_bin).new; \
> -		mv $(factory_bin).new $(factory_bin); \
> -		$(CP) $(factory_bin) $(BIN_DIR)/; \
> -	else \
> -		echo "WARNING: initramfs kernel image too big, cannot generate factory image (actual $$(stat -c%s $@); max $(fw_size))" >&2; \
> -	fi
> -endef
> -
>  define Build/iodata-mstc-header
>  	( \
>  		data_size_crc="$$(dd if=$@ ibs=64 skip=1 2>/dev/null | gzip -c | \
> @@ -972,10 +955,13 @@ define Device/iodata_wn-ax1167gr
>    $(Device/dsa-migration)
>    $(Device/uimage-lzma-loader)
>    IMAGE_SIZE := 15552k
> -  KERNEL_INITRAMFS := $$(KERNEL) | \
> -	iodata-factory 7864320 4 0x1055 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_PREFIX)-factory.bin
>    DEVICE_VENDOR := I-O DATA
>    DEVICE_MODEL := WN-AX1167GR
> +ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
> +  ARTIFACTS := initramfs-factory.bin
> +  ARTIFACT/initramfs-factory.bin := append-image initramfs-kernel.bin | \

Please use 'append-image-stage' so this will work also with the
ImageBuilder where initramfs is not being generated/present.

> +	check-size 7680k | senao-header -r 0x30a -p 0x1055 -t 4
> +endif
>    DEVICE_PACKAGES := kmod-mt7603 kmod-mt76x2
>  endef
>  TARGET_DEVICES += iodata_wn-ax1167gr
> -- 
> 2.36.1.windows.1
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
INAGAKI Hiroshi Nov. 29, 2022, 12:30 p.m. UTC | #2
Hi Daniel,

thank you for your review.

On 2022/11/29 11:07, Daniel Golle wrote:
> On Wed, Nov 23, 2022 at 12:24:09PM +0900, INAGAKI Hiroshi wrote:
...
>> @@ -972,10 +955,13 @@ define Device/iodata_wn-ax1167gr
>>     $(Device/dsa-migration)
>>     $(Device/uimage-lzma-loader)
>>     IMAGE_SIZE := 15552k
>> -  KERNEL_INITRAMFS := $$(KERNEL) | \
>> -	iodata-factory 7864320 4 0x1055 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_PREFIX)-factory.bin
>>     DEVICE_VENDOR := I-O DATA
>>     DEVICE_MODEL := WN-AX1167GR
>> +ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
>> +  ARTIFACTS := initramfs-factory.bin
>> +  ARTIFACT/initramfs-factory.bin := append-image initramfs-kernel.bin | \
> Please use 'append-image-stage' so this will work also with the
> ImageBuilder where initramfs is not being generated/present.

Oh, I didn't know it. Then, should I remove ifneq-endif switch for IB?

>
>> +	check-size 7680k | senao-header -r 0x30a -p 0x1055 -t 4
>> +endif
>>     DEVICE_PACKAGES := kmod-mt7603 kmod-mt76x2
>>   endef
>>   TARGET_DEVICES += iodata_wn-ax1167gr
>> -- 
>> 2.36.1.windows.1
>>
>>
>> _______________________________________________
>> openwrt-devel mailing list
>> openwrt-devel@lists.openwrt.org
>> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Daniel Golle Nov. 29, 2022, 1:04 p.m. UTC | #3
On Tue, Nov 29, 2022 at 09:30:25PM +0900, INAGAKI Hiroshi wrote:
> Hi Daniel,
> 
> thank you for your review.
> 
> On 2022/11/29 11:07, Daniel Golle wrote:
> > On Wed, Nov 23, 2022 at 12:24:09PM +0900, INAGAKI Hiroshi wrote:
> ...
> > > @@ -972,10 +955,13 @@ define Device/iodata_wn-ax1167gr
> > >     $(Device/dsa-migration)
> > >     $(Device/uimage-lzma-loader)
> > >     IMAGE_SIZE := 15552k
> > > -  KERNEL_INITRAMFS := $$(KERNEL) | \
> > > -	iodata-factory 7864320 4 0x1055 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_PREFIX)-factory.bin
> > >     DEVICE_VENDOR := I-O DATA
> > >     DEVICE_MODEL := WN-AX1167GR
> > > +ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
> > > +  ARTIFACTS := initramfs-factory.bin
> > > +  ARTIFACT/initramfs-factory.bin := append-image initramfs-kernel.bin | \
> > Please use 'append-image-stage' so this will work also with the
> > ImageBuilder where initramfs is not being generated/present.
> 
> Oh, I didn't know it. Then, should I remove ifneq-endif switch for IB?

Yes, you should also drop the ifneq-endif for IB.

> 
> > 
> > > +	check-size 7680k | senao-header -r 0x30a -p 0x1055 -t 4
> > > +endif
> > >     DEVICE_PACKAGES := kmod-mt7603 kmod-mt76x2
> > >   endef
> > >   TARGET_DEVICES += iodata_wn-ax1167gr
> > > -- 
> > > 2.36.1.windows.1
> > > 
> > > 
> > > _______________________________________________
> > > openwrt-devel mailing list
> > > openwrt-devel@lists.openwrt.org
> > > https://lists.openwrt.org/mailman/listinfo/openwrt-devel
INAGAKI Hiroshi Nov. 29, 2022, 2:10 p.m. UTC | #4
On 2022/11/29 22:04, Daniel Golle wrote:
> On Tue, Nov 29, 2022 at 09:30:25PM +0900, INAGAKI Hiroshi wrote:
>> Hi Daniel,
>>
>> thank you for your review.
>>
>> On 2022/11/29 11:07, Daniel Golle wrote:
>>> On Wed, Nov 23, 2022 at 12:24:09PM +0900, INAGAKI Hiroshi wrote:
>> ...
>>>> @@ -972,10 +955,13 @@ define Device/iodata_wn-ax1167gr
>>>>      $(Device/dsa-migration)
>>>>      $(Device/uimage-lzma-loader)
>>>>      IMAGE_SIZE := 15552k
>>>> -  KERNEL_INITRAMFS := $$(KERNEL) | \
>>>> -	iodata-factory 7864320 4 0x1055 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_PREFIX)-factory.bin
>>>>      DEVICE_VENDOR := I-O DATA
>>>>      DEVICE_MODEL := WN-AX1167GR
>>>> +ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
>>>> +  ARTIFACTS := initramfs-factory.bin
>>>> +  ARTIFACT/initramfs-factory.bin := append-image initramfs-kernel.bin | \
>>> Please use 'append-image-stage' so this will work also with the
>>> ImageBuilder where initramfs is not being generated/present.
>> Oh, I didn't know it. Then, should I remove ifneq-endif switch for IB?
> Yes, you should also drop the ifneq-endif for IB.

Okay, I'll drop ifneq-endif and send the next version.

BTW, when I compiled images of WN-AX1167GR only with 
'append-image-stage', the following errors were printed and 
compilation failed.

-------
cp 
"/openwrt/user/git/musashino-build/openwrt/bin/targets/ramips/mt7621/openwrt-ramips-mt7621-iodata_wn-ax1167gr-initramfs-kernel.bin" 
"/openwrt/user/git/musashino-build/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/tmp/openwrt-ramips-mt7621-iodata_wn-ax1167gr-initramfs-factory.bin.stripmeta"
fwtool -s /dev/null -t 
"/openwrt/user/git/musashino-build/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/tmp/openwrt-ramips-mt7621-iodata_wn-ax1167gr-initramfs-factory.bin.stripmeta" 
|| :
Data not found
fwtool -i /dev/null -t 
"/openwrt/user/git/musashino-build/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/tmp/openwrt-ramips-mt7621-iodata_wn-ax1167gr-initramfs-factory.bin.stripmeta" 
|| :
Data not found
dd 
if="/openwrt/user/git/musashino-build/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/tmp/openwrt-ramips-mt7621-iodata_wn-ax1167gr-initramfs-factory.bin.stripmeta" 
of="/openwrt/user/git/musashino-build/openwrt/staging_dir/target-mipsel_24kc_musl/image/ramips-mt7621-iodata_wn-ax1167gr-initramfs-kernel.bin"
dd: failed to open 
'/openwrt/user/git/musashino-build/openwrt/staging_dir/target-mipsel_24kc_musl/image/ramips-mt7621-iodata_wn-ax1167gr-initramfs-kernel.bin': 
No such file or directory
make[5]: *** [Makefile:230: 
/openwrt/user/git/musashino-build/openwrt/build_dir/target-mipsel_24kc_musl/linux-ramips_mt7621/tmp/openwrt-ramips-mt7621-iodata_wn-ax1167gr-initramfs-factory.bin] 
Error 1
make[5]: Leaving directory 
'/openwrt/user/git/musashino-build/openwrt/target/linux/ramips/image'
make[4]: *** [Makefile:23: install] Error 2
make[4]: Leaving directory 
'/openwrt/user/git/musashino-build/openwrt/target/linux/ramips'
make[3]: *** [Makefile:11: install] Error 2
make[3]: Leaving directory 
'/openwrt/user/git/musashino-build/openwrt/target/linux'
time: target/linux/install#28.28#3.36#18.20
     ERROR: target/linux failed to build.
make[2]: *** [target/Makefile:30: target/linux/install] Error 1
make[2]: Leaving directory '/openwrt/user/git/musashino-build/openwrt'
make[1]: *** [target/Makefile:24: 
/openwrt/user/git/musashino-build/openwrt/staging_dir/target-mipsel_24kc_musl/stamp/.target_install] 
Error 2
make[1]: Leaving directory '/openwrt/user/git/musashino-build/openwrt'
make: *** 
[/openwrt/user/git/musashino-build/openwrt/include/toplevel.mk:231: 
world] Error 2
-------

This seems to be caused by "image" directory in 
staging_dir/target-mipsel_24kc_musl/ not existing, and when I created 
that folder manually the build succeeded.

-------
user@hostmachine:/openwrt/user/git/musashino-build/openwrt$ mkdir 
staging_dir/target-mipsel_24kc_musl/image
user@hostmachine:/openwrt/user/git/musashino-build/openwrt$ make -j8 V=s
...
(completed without errors)
-------

Should I add a patch to create "image" directory before copying?

>
>>>> +	check-size 7680k | senao-header -r 0x30a -p 0x1055 -t 4
>>>> +endif
>>>>      DEVICE_PACKAGES := kmod-mt7603 kmod-mt76x2
>>>>    endef
>>>>    TARGET_DEVICES += iodata_wn-ax1167gr
>>>> -- 
>>>> 2.36.1.windows.1
>>>>
>>>>
>>>> _______________________________________________
>>>> openwrt-devel mailing list
>>>> openwrt-devel@lists.openwrt.org
>>>> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Daniel Golle Nov. 29, 2022, 3:30 p.m. UTC | #5
On Tue, Nov 29, 2022 at 11:10:22PM +0900, INAGAKI Hiroshi wrote:
> [...]
> This seems to be caused by "image" directory in
> staging_dir/target-mipsel_24kc_musl/ not existing, and when I created that
> folder manually the build succeeded.
> 
> -------
> user@hostmachine:/openwrt/user/git/musashino-build/openwrt$ mkdir
> staging_dir/target-mipsel_24kc_musl/image
> user@hostmachine:/openwrt/user/git/musashino-build/openwrt$ make -j8 V=s
> ...
> (completed without errors)
> -------
> 
> Should I add a patch to create "image" directory before copying?

I've sent out a patch adding this to include/image-commands.mk.
Can you check if that fixes the issue for you?
INAGAKI Hiroshi Nov. 29, 2022, 3:44 p.m. UTC | #6
On 2022/11/30 0:30, Daniel Golle wrote:
> On Tue, Nov 29, 2022 at 11:10:22PM +0900, INAGAKI Hiroshi wrote:
>> [...]
>> This seems to be caused by "image" directory in
>> staging_dir/target-mipsel_24kc_musl/ not existing, and when I created that
>> folder manually the build succeeded.
>>
>> -------
>> user@hostmachine:/openwrt/user/git/musashino-build/openwrt$ mkdir
>> staging_dir/target-mipsel_24kc_musl/image
>> user@hostmachine:/openwrt/user/git/musashino-build/openwrt$ make -j8 V=s
>> ...
>> (completed without errors)
>> -------
>>
>> Should I add a patch to create "image" directory before copying?
> I've sent out a patch adding this to include/image-commands.mk.
> Can you check if that fixes the issue for you?

Thank you for your fix!
I tested compilation with your patch and the following steps, the 
issue was solved :)

$ make clean      # to delete manually created "image" directory
$ make -j8 V=s

I'll prepare v2 patch.
diff mbox series

Patch

diff --git a/target/linux/ramips/image/mt7621.mk b/target/linux/ramips/image/mt7621.mk
index 943fc62ecd..0e3f1cf0f5 100644
--- a/target/linux/ramips/image/mt7621.mk
+++ b/target/linux/ramips/image/mt7621.mk
@@ -49,23 +49,6 @@  define Build/haier-sim_wr1800k-factory
   $(CP) $(1) $(BIN_DIR)/
 endef
 
-define Build/iodata-factory
-	$(eval fw_size=$(word 1,$(1)))
-	$(eval fw_type=$(word 2,$(1)))
-	$(eval product=$(word 3,$(1)))
-	$(eval factory_bin=$(word 4,$(1)))
-	if [ -e $(KDIR)/tmp/$(KERNEL_INITRAMFS_IMAGE) -a "$$(stat -c%s $@)" -lt "$(fw_size)" ]; then \
-		$(CP) $(KDIR)/tmp/$(KERNEL_INITRAMFS_IMAGE) $(factory_bin); \
-		$(STAGING_DIR_HOST)/bin/mksenaofw \
-			-r 0x30a -p $(product) -t $(fw_type) \
-			-e $(factory_bin) -o $(factory_bin).new; \
-		mv $(factory_bin).new $(factory_bin); \
-		$(CP) $(factory_bin) $(BIN_DIR)/; \
-	else \
-		echo "WARNING: initramfs kernel image too big, cannot generate factory image (actual $$(stat -c%s $@); max $(fw_size))" >&2; \
-	fi
-endef
-
 define Build/iodata-mstc-header
 	( \
 		data_size_crc="$$(dd if=$@ ibs=64 skip=1 2>/dev/null | gzip -c | \
@@ -972,10 +955,13 @@  define Device/iodata_wn-ax1167gr
   $(Device/dsa-migration)
   $(Device/uimage-lzma-loader)
   IMAGE_SIZE := 15552k
-  KERNEL_INITRAMFS := $$(KERNEL) | \
-	iodata-factory 7864320 4 0x1055 $(KDIR)/tmp/$$(KERNEL_INITRAMFS_PREFIX)-factory.bin
   DEVICE_VENDOR := I-O DATA
   DEVICE_MODEL := WN-AX1167GR
+ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
+  ARTIFACTS := initramfs-factory.bin
+  ARTIFACT/initramfs-factory.bin := append-image initramfs-kernel.bin | \
+	check-size 7680k | senao-header -r 0x30a -p 0x1055 -t 4
+endif
   DEVICE_PACKAGES := kmod-mt7603 kmod-mt76x2
 endef
 TARGET_DEVICES += iodata_wn-ax1167gr