Discussion:
[PATCH] apm821xx: switch MR24's initramfs to multi-image method
(too old to reply)
Christian Lamparter
2018-03-18 21:51:07 UTC
Permalink
The recent change to switch to gcc 7.3 broke the image
generation code, as the kernel would no longer fit into
KERNEL_SIZE.

This patch fixes the issue by reworking the initramfs
creation and packaging, which will get rid of the
KERNEL_SIZE check in the process.

This new initramfs can be loaded through the MR24 U-boot
in the following way:

=> setenv ipaddr 192.168.1.1
=> setenv bootargs console=ttyS0,$baudrate
=> tftpboot c00000 192.168.1.2:meraki_mr24-initramfs-kernel.bin
[...]
Load address: 0xc00000
Loading: ################################################ [...]
done
Bytes transferred = 5952544 (5ad420 hex)
=> bootm $fileaddr
\## Booting kernel from Legacy Image at 00c00000 ...
...

For more information and the latest flashing guide:
please visit the OpenWrt Wiki Page for the MR24:
<https://openwrt.org/toh/meraki/mr24#flashing>

Cc: Hauke Mehrtens <***@hauke-m.de>
Signed-off-by: Christian Lamparter <***@gmail.com>
Signed-off-by: Chris Blake <***@gmail.com>
---
target/linux/apm821xx/image/Makefile | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/target/linux/apm821xx/image/Makefile b/target/linux/apm821xx/image/Makefile
index 82a857a4d0..4e6b6e4995 100644
--- a/target/linux/apm821xx/image/Makefile
+++ b/target/linux/apm821xx/image/Makefile
@@ -75,13 +75,9 @@ define Device/meraki_mr24
BLOCKSIZE := 63k
IMAGES := sysupgrade.tar
DTB_SIZE := 64512
- KERNEL_SIZE := 1984k
IMAGE_SIZE := 8191k
KERNEL := kernel-bin | lzma | uImage lzma | MerakiAdd-dtb | MerakiNAND
- KERNEL_INITRAMFS := copy-file $(KDIR)/vmlinux | lzma | uImage lzma | \
- check-size $$(KERNEL_SIZE) | \
- MerakiAdd-dtb | pad-to 2047k | MerakiAdd-initramfs | \
- MerakiNAND
+ KERNEL_INITRAMFS := kernel-bin | lzma | dtb | MuImage-initramfs lzma
IMAGE/sysupgrade.tar := sysupgrade-tar | append-metadata
UBINIZE_OPTS := -E 5
SUPPORTED_DEVICES += mr24
@@ -123,7 +119,7 @@ define Build/create-uImage-dtb
@mv $@.new $@
endef

-define Build/wndr4700-specialImage
+define Build/MuImage-initramfs
rm -rf $@.fakerd $@.new

dd if=/dev/zero of=$@.fakerd bs=32 count=1 conv=sync
@@ -170,7 +166,7 @@ define Device/netgear_wndr4700
KERNEL_SIZE := 1920k
KERNEL := dtb | kernel-bin | lzma | uImage lzma | pad-offset $$(BLOCKSIZE) 64 | \
append-uImage-fakeroot-hdr
- KERNEL_INITRAMFS := kernel-bin | gzip | dtb | wndr4700-specialImage gzip
+ KERNEL_INITRAMFS := kernel-bin | gzip | dtb | MuImage-initramfs gzip
IMAGE/factory.img := create-uImage-dtb | append-kernel | pad-to 2M | append-ubi | \
netgear-dni | check-size $$$$(IMAGE_SIZE)
IMAGE/sysupgrade.tar := sysupgrade-tar | append-metadata
--
2.16.2
Hauke Mehrtens
2018-03-20 22:19:06 UTC
Permalink
Post by Christian Lamparter
The recent change to switch to gcc 7.3 broke the image
generation code, as the kernel would no longer fit into
KERNEL_SIZE.
This patch fixes the issue by reworking the initramfs
creation and packaging, which will get rid of the
KERNEL_SIZE check in the process.
This new initramfs can be loaded through the MR24 U-boot
=> setenv ipaddr 192.168.1.1
=> setenv bootargs console=ttyS0,$baudrate
=> tftpboot c00000 192.168.1.2:meraki_mr24-initramfs-kernel.bin
[...]
Load address: 0xc00000
Loading: ################################################ [...]
done
Bytes transferred = 5952544 (5ad420 hex)
=> bootm $fileaddr
\## Booting kernel from Legacy Image at 00c00000 ...
...
<https://openwrt.org/toh/meraki/mr24#flashing>
---
target/linux/apm821xx/image/Makefile | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/target/linux/apm821xx/image/Makefile b/target/linux/apm821xx/image/Makefile
index 82a857a4d0..4e6b6e4995 100644
--- a/target/linux/apm821xx/image/Makefile
+++ b/target/linux/apm821xx/image/Makefile
@@ -75,13 +75,9 @@ define Device/meraki_mr24
BLOCKSIZE := 63k
IMAGES := sysupgrade.tar
DTB_SIZE := 64512
- KERNEL_SIZE := 1984k
IMAGE_SIZE := 8191k
KERNEL := kernel-bin | lzma | uImage lzma | MerakiAdd-dtb | MerakiNAND
- KERNEL_INITRAMFS := copy-file $(KDIR)/vmlinux | lzma | uImage lzma | \
- check-size $$(KERNEL_SIZE) | \
- MerakiAdd-dtb | pad-to 2047k | MerakiAdd-initramfs | \
- MerakiNAND
+ KERNEL_INITRAMFS := kernel-bin | lzma | dtb | MuImage-initramfs lzma
IMAGE/sysupgrade.tar := sysupgrade-tar | append-metadata
UBINIZE_OPTS := -E 5
SUPPORTED_DEVICES += mr24
@@ -123,7 +119,7 @@ define Build/create-uImage-dtb
@mv $@.new $@
endef
-define Build/wndr4700-specialImage
+define Build/MuImage-initramfs
@@ -170,7 +166,7 @@ define Device/netgear_wndr4700
KERNEL_SIZE := 1920k
KERNEL := dtb | kernel-bin | lzma | uImage lzma | pad-offset $$(BLOCKSIZE) 64 | \
append-uImage-fakeroot-hdr
- KERNEL_INITRAMFS := kernel-bin | gzip | dtb | wndr4700-specialImage gzip
+ KERNEL_INITRAMFS := kernel-bin | gzip | dtb | MuImage-initramfs gzip
IMAGE/factory.img := create-uImage-dtb | append-kernel | pad-to 2M | append-ubi | \
netgear-dni | check-size $$$$(IMAGE_SIZE)
IMAGE/sysupgrade.tar := sysupgrade-tar | append-metadata
I test compiled this, but now I have the same problem on the wndr4700,
the meraki_mr24 seams to be fine.

WARNING: Image file
/home/hauke/openwrt/lede/build_dir/target-powerpc_464fp_musl/linux-apm821xx_nand/netgear_wndr4700-kernel.bin
is too big


later on it failes becasue
/home/hauke/openwrt/lede/build_dir/target-powerpc_464fp_musl/linux-apm821xx_nand/netgear_wndr4700-kernel.bin
does not exists.

Hauke
Christian Lamparter
2018-03-21 17:44:34 UTC
Permalink
Post by Hauke Mehrtens
Post by Christian Lamparter
The recent change to switch to gcc 7.3 broke the image
generation code, as the kernel would no longer fit into
KERNEL_SIZE.
This patch fixes the issue by reworking the initramfs
creation and packaging, which will get rid of the
KERNEL_SIZE check in the process.
This new initramfs can be loaded through the MR24 U-boot
=> setenv ipaddr 192.168.1.1
=> setenv bootargs console=ttyS0,$baudrate
=> tftpboot c00000 192.168.1.2:meraki_mr24-initramfs-kernel.bin
[...]
Load address: 0xc00000
Loading: ################################################ [...]
done
Bytes transferred = 5952544 (5ad420 hex)
=> bootm $fileaddr
\## Booting kernel from Legacy Image at 00c00000 ...
...
<https://openwrt.org/toh/meraki/mr24#flashing>
---
target/linux/apm821xx/image/Makefile | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/target/linux/apm821xx/image/Makefile b/target/linux/apm821xx/image/Makefile
index 82a857a4d0..4e6b6e4995 100644
--- a/target/linux/apm821xx/image/Makefile
+++ b/target/linux/apm821xx/image/Makefile
@@ -75,13 +75,9 @@ define Device/meraki_mr24
BLOCKSIZE := 63k
IMAGES := sysupgrade.tar
DTB_SIZE := 64512
- KERNEL_SIZE := 1984k
IMAGE_SIZE := 8191k
KERNEL := kernel-bin | lzma | uImage lzma | MerakiAdd-dtb | MerakiNAND
- KERNEL_INITRAMFS := copy-file $(KDIR)/vmlinux | lzma | uImage lzma | \
- check-size $$(KERNEL_SIZE) | \
- MerakiAdd-dtb | pad-to 2047k | MerakiAdd-initramfs | \
- MerakiNAND
+ KERNEL_INITRAMFS := kernel-bin | lzma | dtb | MuImage-initramfs lzma
IMAGE/sysupgrade.tar := sysupgrade-tar | append-metadata
UBINIZE_OPTS := -E 5
SUPPORTED_DEVICES += mr24
@@ -123,7 +119,7 @@ define Build/create-uImage-dtb
@mv $@.new $@
endef
-define Build/wndr4700-specialImage
+define Build/MuImage-initramfs
@@ -170,7 +166,7 @@ define Device/netgear_wndr4700
KERNEL_SIZE := 1920k
KERNEL := dtb | kernel-bin | lzma | uImage lzma | pad-offset $$(BLOCKSIZE) 64 | \
append-uImage-fakeroot-hdr
- KERNEL_INITRAMFS := kernel-bin | gzip | dtb | wndr4700-specialImage gzip
+ KERNEL_INITRAMFS := kernel-bin | gzip | dtb | MuImage-initramfs gzip
IMAGE/factory.img := create-uImage-dtb | append-kernel | pad-to 2M | append-ubi | \
netgear-dni | check-size $$$$(IMAGE_SIZE)
IMAGE/sysupgrade.tar := sysupgrade-tar | append-metadata
I test compiled this, but now I have the same problem on the wndr4700,
the meraki_mr24 seams to be fine.
WARNING: Image file
/home/hauke/openwrt/lede/build_dir/target-powerpc_464fp_musl/linux-apm821xx_nand/netgear_wndr4700-kernel.bin
is too big
later on it failes becasue
/home/hauke/openwrt/lede/build_dir/target-powerpc_464fp_musl/linux-apm821xx_nand/netgear_wndr4700-kernel.bin
does not exists.
the WNDR4700 will need its own patch then.
The KERNEL_SIZE restriction is due to the kernel partition size:
<https://github.com/openwrt/openwrt/blob/master/target/linux/apm821xx/dts/netgear-wndr4700.dts#L182>
And these definitions are the same for netgear's original dts.

In theory, the size could be easily changed (since wndr4700's u-boot
does not care much about the NAND's partitioning. As it gets the size
from the kernel's uimage header). What this will break however is the
ability to sysupgrade directly from an existing installation.

As for shrinking the kernel by moving drivers into modules:
There is some potential.

1. The libATA + sata_dwc_460ex could be compiled as a module.
This would be at the cost of ledtrig-disk. As this ledtrigger cannot
really be built as a module since the Kconfig option is a boolean.
The WNDR4700 has a dedicated hdd activity LED, so people will notice
this.

2. make the crypto4xx a module again.
This however would require to revert the following patch again:
|kernel: drop crypto-hw-ppc4xx
|If any of the ppc4xx targets are restored, this should be built into the
|kernel instead
|
|Signed-off-by: Felix Fietkau <***@nbd.name>
|
<https://git.openwrt.org/?p=openwrt/openwrt.git;a=commit;h=5b92dca09fb0414775c75f51b3ce8c99ad63292f>
(So, this requires an ACK/OK from Felix first.)

There are also a few more lesser things, like disabling
PM+SUSPEND+PPC4XX_CPM, SATA PMP, MTD LED trigger, LZO support,
and PCIEAER. And if the MX60(W) was converted like the MR24,
the CONFIG_RD_GZIP + CONFIG_ZLIB_* + CONFIG_DECOMPRESS_GZIP
could be disabled too.

Regards,
Christian
Christian Lamparter
2018-03-26 15:25:32 UTC
Permalink
This patch cleans and reworks the WNDR4700 dts to increase the
now combined dtb+kernel partition to 3.5 MiB. This has become
necessary due to the switch to GCC 7.3 and the ever increasing
kernel binary size.

The dtb+kernel partition was combined in order to finally
fix the problem with out-of-sync device-trees. From now
on, the kernel and device-tree will always be updated together.

Upgrade Note:
Existing installations will have to use the TFTP firmware
recovery option in order to install the update. Affected users
are advised to make a backup of their existing configuration
prior to running sysupgrade:
<https://openwrt.org/docs/guide-user/installation/generic.backup#backup_openwrt_configuration>
Due to the repartitioning of the NAND, the generated backup
should be placed on either the internal HDD, an attached
USB-Stick or on another PC (externally).

To manually trigger the firmware recovery, the reset button has
to be pressed (and hold) during boot. U-boot will enter the "Upgrade
Mode" and starts a tftpserver listening on 192.168.1.1 for a
tftp client from one of the four LAN/Ethernet ports to connect and
upload the new system: (enable tftp binary mode!).
openwrt-apm821xx-nand-netgear_wndr4700-squashfs-factory.img

Cc: Hauke Mehrtens <***@hauke-m.de>
Signed-off-by: Christian Lamparter <***@gmail.com>
---
target/linux/apm821xx/dts/netgear-wndr4700.dts | 38 ++++++++++++++------------
target/linux/apm821xx/image/Makefile | 18 ++++++++----
2 files changed, 33 insertions(+), 23 deletions(-)

diff --git a/target/linux/apm821xx/dts/netgear-wndr4700.dts b/target/linux/apm821xx/dts/netgear-wndr4700.dts
index 96cf97c45c..4a252cf0b8 100644
--- a/target/linux/apm821xx/dts/netgear-wndr4700.dts
+++ b/target/linux/apm821xx/dts/netgear-wndr4700.dts
@@ -160,75 +160,79 @@
#address-cells = <1>;
#size-cells = <1>;

- partition0,***@0x00000000 {
+ partition0,***@0 {
label = "NAND 128MiB 3,3V 8-bit";
reg = <0x00000000 0x08000000>;
read-only;
};

- partition0,***@0x00000000 {
+ partition0,***@0 {
label = "uboot";
reg = <0x00000000 0x00180000>;
read-only;
};

- partition0,***@0x00180000 {
+ partition0,***@180000 {
label = "device-tree";
reg = <0x00180000 0x00020000>;
};

- partition0,***@0x001a0000 {
+ partition0,***@180000 {
label = "kernel";
- reg = <0x001a0000 0x001e0000>;
+ reg = <0x00180000 0x00380000>;
/*
- * will also contain a fake/empty
- * rootfs to fool Netgear's uboot
- * rootfs integrety checks.
+ * device-tree is @ 0x00180000 - 0x001fffff
+ * kernel starts from 0x200000.
+ * this is coded into netgear's u-boot.
+ *
+ * this partition will also contain a
+ * fake/empty rootfs at the end to fool
+ * Netgear's uboot rootfs integrety checks.
*/
};

- partition0,***@0x00380000 {
+ partition0,***@500000 {
label = "ubi";
- reg = <0x00380000 0x01660000>;
+ reg = <0x00500000 0x014e0000>;
};

- partition0,***@0x019e0000 {
+ partition0,***@19e0000 {
label = "config";
reg = <0x019e0000 0x00080000>;
read-only;
};

- partition0,***@0x01a60000 {
+ partition0,***@1a60000 {
label = "pot";
reg = <0x01a60000 0x00080000>;
read-only;
};

- partition0,***@0x01ae0000 {
+ partition0,***@1ae0000 {
label = "traffic_meter";
reg = <0x01ae0000 0x00300000>;
read-only;
};

- partition0,***@0x01de0000 {
+ partition0,***@1de0000 {
label = "language";
reg = <0x01de0000 0x001c0000>;
read-only;
};

- partition0,***@0x01fa0000 {
+ partition0,***@1fa0000 {
label = "ecos";
reg = <0x01fa0000 0x06020000>;
read-only;
};

- partition0,***@0x07fc0000 {
+ partition0,***@7fc0000 {
label = "wifi_data";
reg = <0x07fc0000 0x00040000>;
read-only;
};

- partition0,***@0x00180000 {
+ partition0,***@180000 {
label = "firmware";
reg = <0x00180000 0x01860000>;
read-only;
diff --git a/target/linux/apm821xx/image/Makefile b/target/linux/apm821xx/image/Makefile
index 4e6b6e4995..4cfbea4cbd 100644
--- a/target/linux/apm821xx/image/Makefile
+++ b/target/linux/apm821xx/image/Makefile
@@ -21,6 +21,11 @@ define Build/dtb
$(call Image/BuildDTB,../dts/$(DEVICE_DTS).dts,$@.dtb,,--space $(DTB_SIZE))
endef

+define Build/prepend-dtb
+ cat "$@.dtb.uimage" "$@" > "$@.new"
+ mv "$@.new" "$@"
+endef
+
define Build/export-dtb
cp $(IMAGE_KERNEL).dtb $@
endef
@@ -115,8 +120,7 @@ define Build/create-uImage-dtb
-$(STAGING_DIR_HOST)/bin/mkimage -A $(LINUX_KARCH) \
-O linux -T kernel -C none \
-n '$(call toupper,$(LINUX_KARCH)) $(VERSION_DIST) Linux-$(LINUX_VERSION)' \
- -d $(IMAGE_KERNEL).dtb $@.new
- @mv $@.new $@
+ -d "$@.dtb" "$@.dtb.uimage"
endef

define Build/MuImage-initramfs
@@ -163,11 +167,13 @@ define Device/netgear_wndr4700
DTB_SIZE := 131008
IMAGE_SIZE := 24960k
IMAGES := factory.img sysupgrade.tar kernel.dtb
- KERNEL_SIZE := 1920k
- KERNEL := dtb | kernel-bin | lzma | uImage lzma | pad-offset $$(BLOCKSIZE) 64 | \
- append-uImage-fakeroot-hdr
+ KERNEL_SIZE := 3584k
+ # append a fake/empty rootfs to fool netgear's uboot
+ # CHECK_DNI_FIRMWARE_ROOTFS_INTEGRITY in do_chk_dniimg()
+ KERNEL := kernel-bin | lzma | uImage lzma | pad-offset $$(BLOCKSIZE) 64 | \
+ append-uImage-fakeroot-hdr | dtb | create-uImage-dtb | prepend-dtb
KERNEL_INITRAMFS := kernel-bin | gzip | dtb | MuImage-initramfs gzip
- IMAGE/factory.img := create-uImage-dtb | append-kernel | pad-to 2M | append-ubi | \
+ IMAGE/factory.img := append-kernel | pad-to $$$$(KERNEL_SIZE) | append-ubi | \
netgear-dni | check-size $$$$(IMAGE_SIZE)
IMAGE/sysupgrade.tar := sysupgrade-tar | append-metadata
IMAGE/kernel.dtb := export-dtb | uImage none
--
2.16.3
Loading...