apm821xx: prepare WNDR4700 for 6.6 - add preliminary u-boot-env access
authorChristian Lamparter <chunkeey@gmail.com>
Sat, 23 Mar 2024 10:26:23 +0000 (11:26 +0100)
committerChristian Lamparter <chunkeey@gmail.com>
Fri, 5 Apr 2024 07:26:26 +0000 (09:26 +0200)
With the default BUILD_BOT configuration on a linux 6.6 kernel,
the WNDR4700's kernel no longer fits into the alloted ~3.5MiB,
even with LZMA compression.

Bigger kernels are possible, but there's a problem with Netgear's
"bootcmd":

> if loadn_dniimg 0 0x180000 0x4e0000 && chk_dniimg 0x4e0000; then nand read 0x800000 0x180000 0x20000;bootm 0x500000 - 0x800040;else fw_recovery; fi"

This loads the dni-image starting offset 0x180000 from the NAND
flash (which is the DTB partition) to 0x4e0000 in the RAM. It then
checks whenever the provided image is "valid". If it is then it
reads the DTB again to 0x800000 in the RAM and starts the extraction
and boot process. (If the image wasn't valid then it starts the
automated firmware recovery).

The issues here are that first: the kernel image gets "squeezed"
between 0x500040 and 0x7fffff... And second, the decompressor
only has area 0x0 - 0x500000 for decompression.

Hence the image now requires to update the bootcmd by providing
new values (which have been successfully tested with the original
Netgear WNDR4700 v1.0.0.56 firmware) for the RAM locations and
make full use of the fact that loadn_dniimg loads the DTB as well.

This needs to be done only once. Just connect a serial adapter to
interface with uboot and overwrite (and save) the new bootcmd.

WARNING: The serial port needs a TTL/RS-232 3.3v level converter!

Steps:
 0. Power-off the WNDR4700
 1. Connect the serial interface (you need to open the WNDR4700)
 2. Power-up the WNDR4700
 3. Monitor the boot-sequence and hit "Enter"-key when it says:

  "Hit any key to stop autoboot" (Be quick, you have a ~2 second window)

 4. in the Prompt enter the following commands (copy & paste)

 setenv bootcmd "if loadn_dniimg 0 0x180000 0xce0000 && chk_dniimg 0xce0000; then bootm 0xd00000 - 0xce0040;else fw_recovery; fi"
 saveenv
 run bootcmd

Note: This new bootcmd will also unbrick devices that were bricked
by the bigger 4.19-6.1 kernels.

Note2: This method was tested with a WNDR4700. A big kernel with most
debug features enabled on v6.6.22 measured 4.30 MiB when compressed
with lzma. The uncompressed kernel is 12.34 MiB. This is over the 3 MiB,
the device reserves for the kernel... But it booted! For bigger kernels,
the device needs repartitioning of the the ubi partition due to the
kernel+dtb not fitting into the partition.

Note3: For initramfs development. I would advice to load the initramfs
images to 0x800000 (or higher). i.e.: tftp 800000 wndr4700.bin

Note4: the fw_recovery uboot command to transfer the factory image to
the flash still works.

Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
package/boot/uboot-envtools/files/apm821xx
target/linux/apm821xx/base-files/etc/uci-defaults/05_fix-compat-version
target/linux/apm821xx/dts/netgear-wndr4700.dts
target/linux/apm821xx/image/nand.mk

index e73aaab7a0d73a4856d24ae20a39458797c8beb1..1076f931bb7cc008651d039b25e05f6aace3ccc4 100644 (file)
@@ -19,6 +19,10 @@ netgear,wndap620|\
 netgear,wndap660)
        ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x4000" "0x4000" "4"
        ;;
+netgear,wndr4700)
+       ubootenv_add_uci_config "/dev/mtd0" "0x40000" "0x20000" "0x20000" "1"
+       ubootenv_add_uci_config "/dev/mtd0" "0x60000" "0x20000" "0x20000" "1"
+       ;;
 wd,mybooklive)
        ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x1000" "1"
        ubootenv_add_uci_config "/dev/mtd1" "0x1000" "0x1000" "0x1000" "1"
index 0be0b6112a3e4765a3024105e07715a7aa6073f0..d34b4051be3d7d73be45344282c738cc5b008e80 100644 (file)
@@ -3,7 +3,8 @@
 case "$(board_name)" in
 meraki,mx60|\
 netgear,wndap620|\
-netgear,wndap660)
+netgear,wndap660|\
+netgear,wndr4700)
        uci set system.@system[0].compat_version="2.0"
        uci commit system
        ;;
index 0788037981d85749cc4f1474cbdb40fdc4ba160e..851a3192b39b8434d4504d8b3a702a532b4d7f7c 100644 (file)
                        partition@0 {
                                label = "uboot";
                                reg = <0x00000000 0x00180000>;
+                               compatible = "fixed-partitions";
                                read-only;
+
+                               partition@40000 {
+                                       label = "u-boot-env-main";
+                                       compatible = "u-boot,env-redundant-count";
+                                       reg = <0x00040000 0x20000>; /* one block is 128k */
+                                       read-only;
+                               };
+
+/*
+ * Causes u_boot_env: probe of 4e4000000.ndfc:nand:partitions:partition@0:partition@60000
+ * failed with error -17
+ *
+ *                             partition@60000 {
+ *                                     label = "u-boot-env-redundant";
+ *                                     compatible = "u-boot,env-redundant-count";
+ *                                     reg = <0x00060000 0x20000>;
+ *                                     read-only;
+ *                             };
+ */
                        };
 
                        partition@180000 {
 
                                partition@0 {
                                        label = "kernel";
-                                       reg = <0x00000000 0x00380000>;
+                                       reg = <0x00000000 0x00480000>;
 
                                        compatible = "fixed-partitions";
                                        #address-cells = <1>;
                                 */
                                };
 
-                               partition@380000 {
+                               partition@480000 {
                                        label = "ubi";
-                                       reg = <0x00380000 0x014e0000>;
+                                       reg = <0x00480000 0x013e0000>;
                                };
                        };
 
index 469bf58c1d107d9c139f90c87c4ee54142aded69..69eb386126a9c025c6d4832134df9847c85bbda3 100644 (file)
@@ -105,7 +105,7 @@ define Device/netgear_wndr4700
   IMAGE_SIZE := 24960k
   IMAGES := factory.img sysupgrade.bin
   ARTIFACTS := device-tree.dtb
-  KERNEL_SIZE := 3584k
+  KERNEL_SIZE := 4608k
   # append a fake/empty rootfs to fool netgear's uboot
   # CHECK_DNI_FIRMWARE_ROOTFS_INTEGRITY in do_chk_dniimg()
   KERNEL := kernel-bin | lzma -d16 | uImage lzma | pad-offset $$(BLOCKSIZE) 64 | \
@@ -119,5 +119,8 @@ define Device/netgear_wndr4700
   NETGEAR_HW_ID := 29763875+128+256
   UBINIZE_OPTS := -E 5
   SUPPORTED_DEVICES += wndr4700
+  DEVICE_COMPAT_VERSION := 2.0
+  DEVICE_COMPAT_MESSAGE := kernel and ubi partitions had to be resized. \
+       Upgrade via sysupgrade mechanism is not possible.
 endef
 TARGET_DEVICES += netgear_wndr4700