[MT7620N] OpenWrt RAM boot works but stuck just before mounting the "RAM disk"

I'm porting OpenWrt to an MT7620N device with 32MB of memory. I want to start with RAM boot to test the new DTS. The device has a stock U-boot bootloader, which allows me to load my OpenWrt initramfs into its RAM.

It boots, however, the serial console never appears.

I looked up on the Internet, and https://gist.github.com/flipy/3156df102ee970fd5c6190a37a5f8b99 suggests that I should at least get these right after 8021q: 802.1Q VLAN Support v1.8:

[    2.062973] Registering SWP/SWPB emulation handler
[    2.073754][    2.089822] Freeing unused kernel memory: 8192K
[    2.127493] Run /init as init process
[    2.156950] init: Console is alive

But in my case, it stuck at 8021q: 802.1Q VLAN Support v1.8. I knew the kernel was still alive because when I unplugged the ethernet cable from the device, the serial console showed port 4 link down. And if I plugged it back in, the serial console showed port 4 link up.

Could anyone help me to identify and fix the problem? The boot log of my OpenWrt port is given here:

Automatic boot of image at addr 0x80A00000 ...
## Booting image at 80a00000 ...
   Image Name:   MIPS OpenWrt Linux-6.1.81
   Image Type:   MIPS Linux Kernel Image (lzma compressed)
   Data Size:    5489472 Bytes =  5.2 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, 32

Starting kernel ...

[    0.000000] Linux version 6.1.81 (rikka@wsl) (mipsel-openwrt-linux-musl-gcc (OpenWrt GCC 12.3.0 r25542-51b0ea8b0b) 12.3.0, GNU ld (GNU Binutils) 2.40.0) #0 Wed Mar 20 15:23:46 2024
[    0.000000] Board has DDR1
[    0.000000] Analog PMU set to hw control
[    0.000000] Digital PMU set to hw control
[    0.000000] SoC Type: MediaTek MT7620N ver:2 eco:6
[    0.000000] printk: bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 00019650 (MIPS 24KEc)
[    0.000000] MIPS: machine is EDUP EP-2913
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x0000000001ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000001ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000001ffffff]
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 8120
[    0.000000] Kernel command line: console=ttyS0,57600 rootfstype=squashfs,jffs2
[    0.000000] Dentry cache hash table entries: 4096 (order: 2, 16384 bytes, linear)
[    0.000000] Inode-cache hash table entries: 2048 (order: 1, 8192 bytes, linear)
[    0.000000] Writing ErrCtl register=00040040
[    0.000000] Readback ErrCtl register=00040040
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 20248K/32768K available (5776K kernel code, 607K rwdata, 1320K rodata, 4192K init, 218K bss, 12520K reserved, 0K cma-reserved)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 256
[    0.000000] CPU Clock: 580MHz
[    0.000000] clocksource: systick: mask: 0xffff max_cycles: 0xffff, max_idle_ns: 583261500 ns
[    0.000000] systick: enable autosleep mode
[    0.000000] systick: running - mult: 214748, shift: 32
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 6590553264 ns
[    0.000002] sched_clock: 32 bits at 290MHz, resolution 3ns, wraps every 7405115902ns
[    0.015527] Calibrating delay loop... 385.84 BogoMIPS (lpj=1929216)
[    0.087763] pid_max: default: 32768 minimum: 301
[    0.098078] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.112512] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.131248] cblist_init_generic: Setting adjustable number of callback queues.
[    0.145539] cblist_init_generic: Setting shift to 0 and lim to 1.
[    0.162304] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.181805] futex hash table entries: 256 (order: -1, 3072 bytes, linear)
[    0.195517] pinctrl core: initialized pinctrl subsystem
[    0.207363] NET: Registered PF_NETLINK/PF_ROUTE protocol family
[    0.231773] rt2880_gpio 10000600.gpio: registering 24 gpios
[    0.242833] rt2880_gpio 10000600.gpio: registering 24 irq handlers
[    0.257275] clocksource: Switched to clocksource systick
[    0.269630] NET: Registered PF_INET protocol family
[    0.279576] IP idents hash table entries: 2048 (order: 2, 16384 bytes, linear)
[    0.294914] tcp_listen_portaddr_hash hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.311668] Table-perturb hash table entries: 65536 (order: 6, 262144 bytes, linear)
[    0.327008] TCP established hash table entries: 1024 (order: 0, 4096 bytes, linear)
[    0.342248] TCP bind hash table entries: 1024 (order: 1, 8192 bytes, linear)
[    0.356282] TCP: Hash tables configured (established 1024 bind 1024)
[    0.369082] UDP hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.382011] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes, linear)
[    0.396242] NET: Registered PF_UNIX/PF_LOCAL protocol family
[    0.407483] PCI: CLS 0 bytes, default 32
[    0.415391] rt-timer 10000100.timer: maximum frequency is 1220Hz
[    1.165695] workingset: timestamp_bits=14 max_order=13 bucket_order=0
[    1.185695] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    1.197226] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    1.220025] Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled
[    1.233912] printk: console [ttyS0] disabled
[    1.242428] 10000c00.uartlite: ttyS0 at MMIO 0x10000c00 (irq = 20, base_baud = 2500000) is a Palmchip BK-3103
[    1.262089] printk: console [ttyS0] enabled
[    1.262089] printk: console [ttyS0] enabled
[    1.278668] printk: bootconsole [early0] disabled
[    1.278668] printk: bootconsole [early0] disabled
[    1.304021] spi spi0.0: force spi mode3
[    1.312308] spi-nor spi0.0: mx25l3205d (4096 Kbytes)
[    1.322392] 4 fixed-partitions partitions found on MTD device spi0.0
[    1.335116] OF: Bad cell count for /palmbus@10000000/spi@b00/flash@0/partitions
[    1.349728] OF: Bad cell count for /palmbus@10000000/spi@b00/flash@0/partitions
[    1.364662] Creating 4 MTD partitions on "spi0.0":
[    1.374264] 0x000000000000-0x000000030000 : "u-boot"
[    1.386241] 0x000000030000-0x000000040000 : "u-boot-env"
[    1.398414] 0x000000040000-0x000000050000 : "factory"
[    1.410233] OF: Bad cell count for /palmbus@10000000/spi@b00/flash@0/partitions
[    1.425290] 0x000000050000-0x000000400000 : "firmware"
[    1.452537] gsw: setting port4 to ephy mode
[    1.461159] mtk_soc_eth 10100000.ethernet: no mdio-bus child node found
[    1.474386] mtk_soc_eth 10100000.ethernet: mdio-bus disabled
[    1.485859] mtk_soc_eth 10100000.ethernet: loaded mt7620 driver
[    1.498508] mtk_soc_eth 10100000.ethernet eth0: mediatek frame engine at 0xb0100000, irq 5
[    1.515691] rt2880_wdt 10000120.watchdog: Initialized
[    1.527644] NET: Registered PF_INET6 protocol family
[    2.153187] Segment Routing with IPv6
[    2.160679] In-situ OAM (IOAM) with IPv6
[    2.168730] NET: Registered PF_PACKET protocol family
[    2.178949] 8021q: 802.1Q VLAN Support v1.8
[    3.069921] mtk_soc_eth 10100000.ethernet eth0: port 4 link up (100Mbps/Full duplex)
[  844.449817] mtk_soc_eth 10100000.ethernet eth0: port 4 link down
[  890.775952] mtk_soc_eth 10100000.ethernet eth0: port 4 link up (100Mbps/Full duplex)
[ 1552.402428] mtk_soc_eth 10100000.ethernet eth0: port 4 link down
[ 1554.000246] mtk_soc_eth 10100000.ethernet eth0: port 4 link up (100Mbps/Full duplex)

Device specs:

32MB device were dropped a long time ago, and those were using a kernel a lot smaller than the 6.1 you're trying to boot.

https://openwrt.org/supported_devices/432_warning

I read about this. But I still want to know if the latest 6.1 kernel boots on this device (without Luci). The SoC supports up to 16MB of SPI flash and 256MB of RAM, I have plenty of old PC DDR1 RAMs, and perhaps I can use them to upgrade the device memory. Soldering wont a problem for me, I'm an electrical engineer. This porting attempt is just for fun. If It does not make sense at all to run the latest OpenWrt on this device, then I will let go.

I'd probably go back in time, find the oldest release where the SoC was supported, and see if I could get it to boot, then go forward again.

It boots 19.07.0 but not 21.02.7. 21.02.7 failed with kernel panic

well, there's a reason why those devices were dropped :expressionless:

an initramfs requires more RAM than a regular image, since the image have to be stored in RAM too.

I could imagine you'd be able to boot an image off flash, running 19.07 and 21.02, if you had one.

1 Like

That's a really good point! I will try to replace the stock 4MB flash with an 8MB one (mx25l3205d tp W25Q64) and see if it boots from flash

Finally, I made it! RAM boot does not work at all, but flash installation does.

The following patch is required to add the new device definition:

diff --git a/target/linux/ramips/image/mt7620.mk b/target/linux/ramips/image/mt7620.mk
index 04c3262920..119b05e227 100644
--- a/target/linux/ramips/image/mt7620.mk
+++ b/target/linux/ramips/image/mt7620.mk
@@ -394,6 +394,16 @@ define Device/dovado_tiny-ac
 endef
 TARGET_DEVICES += dovado_tiny-ac
 
+define Device/edup_ep-2913
+  SOC := mt7620n
+  IMAGE_SIZE := 7872k
+  DEVICE_VENDOR := EDUP
+  DEVICE_MODEL := EP-2913
+  DEVICE_PACKAGES := kmod-usb2 kmod-usb-ohci
+  SUPPORTED_DEVICES += ep-2913
+endef
+TARGET_DEVICES += edup_ep-2913
+
 define Device/edimax_br-6208ac-v2
   SOC := mt7620a
   DEVICE_VENDOR := Edimax
diff --git a/target/linux/ramips/mt7620/base-files/etc/board.d/02_network b/target/linux/ramips/mt7620/base-files/etc/board.d/02_network
index 167bb47b69..6b90652927 100644
--- a/target/linux/ramips/mt7620/base-files/etc/board.d/02_network
+++ b/target/linux/ramips/mt7620/base-files/etc/board.d/02_network
@@ -42,6 +42,7 @@ ramips_setup_interfaces()
 	ampedwireless,b1200ex|\
 	buffalo,wmr-300|\
 	dlink,dch-m225|\
+	edup,ep-2913|\
 	edimax,ew-7476rpc|\
 	edimax,ew-7478ac|\
 	elecom,wrh-300cr|\

The DTS for the new device (target/linux/ramips/dts/mt7620n_edup_ep-2913.dts):

#include "mt7620n.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
#include <dt-bindings/leds/common.h>

/ {
	compatible = "edup,ep-2913", "ralink,mt7620n-soc";
	model = "EDUP EP-2913";

	aliases {
		led-boot = &led_power;
		led-failsafe = &led_power;
		led-running = &led_power;
		led-upgrade = &led_power;
	};

	chosen {
		bootargs = "console=ttyS0,57600";
	};

	leds {
		compatible = "gpio-leds";

		lan {
			function = LED_FUNCTION_LAN;
			color = <LED_COLOR_ID_BLUE>;
			gpios = <&gpio1 15 GPIO_ACTIVE_LOW>;
		};

		led_power: power {
			function = LED_FUNCTION_POWER;
			color = <LED_COLOR_ID_RED>;
			gpios = <&gpio1 14 GPIO_ACTIVE_LOW>;
		};
	};

	keys {
		compatible = "gpio-keys";

		reset {
			label = "reset";
			gpios = <&gpio0 2 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RESTART>;
		};

		// Switch near the leds
		option1 {
			label = "option1";
			gpios = <&gpio2 0 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RESTART>;
		};

		// Switch in the middle position 
		option2 {
			label = "option2";
			gpios = <&gpio2 1 GPIO_ACTIVE_LOW>;
			linux,code = <KEY_RESTART>;
		};
	};
};

&gpio1 {
	status = "okay";
};

&gpio2 {
	status = "okay";
};

&gpio3 {
	status = "okay";
};

&spi0 {
	status = "okay";

	// Stock flash mx25l3205d (4096 Kbytes) wont hold the latest OpenWrt image.
	// The only solution is to replace it with a bigger one, e.g. W25Q64 (8192 Kbytes).
	// You need to manually copy the first 0x50000 bytes (Bootloader) to the new flash,
	// then flash the sysupgrade.bin to address 0x50000.
	flash@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <48000000>;

		partitions {
			compatible = "fixed-partitions";
			#address-cells = <1>;
			#size-cells = <1>;

			partition@0 {
				label = "u-boot";
				reg = <0x0 0x30000>;
				read-only;
			};

			partition@30000 {
				label = "u-boot-env";
				reg = <0x30000 0x10000>;
				read-only;
			};

			partition@40000 {
				label = "factory";
				reg = <0x40000 0x10000>;
				read-only;

				nvmem-layout {
					compatible = "fixed-layout";
					#address-cells = <1>;
					#size-cells = <1>;

					eeprom_factory_0: eeprom@0 {
						reg = <0x0 0x200>;
					};

					macaddr_factory_4: macaddr@4 {
						reg = <0x4 0x6>;
					};
				};
			};

			partition@50000 {
				compatible = "denx,uimage";
				label = "firmware";
				reg = <0x50000 0x7b0000>;
			};
		};
	};
};

// The USB jack is not populated by default.
// You need to solder one,
// then connect the USB power pin to 5V
// by shorting the two pins of U??? near the USB jack.
&ehci {
	status = "okay";
};

&ohci {
	status = "okay";
};

&ethernet {
	nvmem-cells = <&macaddr_factory_4>;
	nvmem-cell-names = "mac-address";

	mediatek,portmap = "xxxxl";
};

&wmac {
	nvmem-cells = <&eeprom_factory_0>;
	nvmem-cell-names = "eeprom";
};

&state_default {
	default {
		groups = "ephy", "wled", "i2c", "wdt", "pa", "spi refclk";
		function = "gpio";
	};
};

kmod-usb2 and kmod-usb-ohci must be selected in the make menuconfig, otherwise USB wont work. Adding Luci is possible. The final firmware size is 6465kB.

Sysupgrade via Luci does not work due to memory limitations. The whole image must be uploaded to the device's RAM before flashing.

The serial console is 3.3V 8N1 57600.

This may help reduce memory usage at a cost of higher CPU performance penalty:

# From #10 of https://forum.archive.openwrt.org/viewtopic.php?id=41515
echo $((5*1024*1024)) > /sys/block/zram0/disksize
mkswap /dev/zram0
swapon /dev/zram0

Would it be possible to further shrink the firmware size?

1 Like

only by going backwars, release wise, assuming you use the same packages in every build.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.