I've successfully booted my Openwrt initramfs. It trickier than I expected.
The uboot bootm command seem to only accept images with these two condition:
- Must have and uImage header. Uboot will verify checksum in the first 64 bytes (e.g.
0x81000040
). - The image type must be "Multi-File Image". The default
mkimage
parameters in openwrt'scommon-tp-link.mk
islinux
.
Those idea came when I tried to boot an sysupgrade image that have uImage header, but image type is MIPS Linux Kernel Image
:
## Booting image at 81000000 ...
Verifying Checksum at 0x81000040 ...OK
Wrong Image Type for bootm command
To confirm my hypothesis, I trimmed stock firmware down to only have the header and Multi-File Image
:
xpduyson@DESKTOP-9RMCMKP:~/openwrt/bin/targets/ath79/generic$ binwalk /mnt/r/tplink_wr941HPv2_bootm.bin
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 uImage header, header size: 64 bytes, header CRC: 0xAFF40B5C, created: 2017-12-22 09:13:19, image size: 1109236 bytes, Data Address: 0x80060000, Entry Point: 0x80060000, data CRC: 0x1CD39EAD, OS: Linux, CPU: MIPS, image type: Multi-File Image, compression type: lzma, image name: "MIPS OpenWrt Linux-3.3.8"
72 0x48 LZMA compressed data, properties: 0x6D, dictionary size: 8388608 bytes, uncompressed size: 3215376 bytes
uBoot accept that image and booted:
ath> tftp 0x81000000 tplink_wr941HPv2_bootm.bin
Trying eth0
eth0 link down
FAIL
Trying eth1
Using eth1 device
TFTP from server 192.168.1.10; our IP address is 192.168.1.1
Filename 'tplink_wr941HPv2_bootm.bin'.
Load address: 0x81000000
Loading: #################################################################
#################################################################
#################################################################
#########################
done
Bytes transferred = 1122475 (1120ab hex)
ath> bootm
## Booting image at 81000000 ...
Verifying Checksum at 0x81000040 ...OK
Uncompressing Multi-File Image ... OK
No initrd
## Transferring control to Linux (at address 80060000) ...
## Giving linux memsize in bytes, 67108864
Starting kernel ...
[ 0.000000] Linux version 3.3.8 (jji315@ubuntu) (gcc version 4.6.3 20120201 (prerelease) (Linaro GCC 4.6-2012.02) ) #1 Fri Dec 22 17:12:43 CST 2017
[ 0.000000] bootconsole [early0] enabled
[ 0.000000] CPU revision is: 00019750 (MIPS 74Kc)
[ 0.000000] SoC: Qualcomm Atheros QCA956X rev 0
[ 0.000000] Clocks: CPU:750.000MHz, DDR:400.000MHz, AHB:250.000MHz, Ref:25.000MHz
[ 0.000000] Determined physical RAM map:
[ 0.000000] memory: 04000000 @ 00000000 (usable)
[ 0.000000] Initrd not found or empty - disabling initrd
[ 0.000000] Zone PFN ranges:
[ 0.000000] Normal 0x00000000 -> 0x00004000
[ 0.000000] Movable zone start PFN for each node
[ 0.000000] Early memory PFN ranges
[ 0.000000] 0: 0x00000000 -> 0x00004000
[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
[ 0.000000] Kernel command line: board=WR941HP console=ttyS0,115200 mtdparts=spi0.0:64k(u-boot)ro,6912k(rootfs),1088k(kernel),64k(mib0),64k(art),8000k@0x10000(firmware) rootfstype=squashfs,jffs2 noinitrd
Based on that, I changed the image type from linux
to multi
in mkimage
command in common-tp-link.mk
:
define Build/uImageArcher
mkimage -A $(LINUX_KARCH) \
-O linux -T multi -C $(1) -a $(KERNEL_LOADADDR) \
-e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
-n '$(call toupper,$(LINUX_KARCH)) OpenWrt Linux-$(LINUX_VERSION)' -d $@ $@.new
@mv $@.new $@
endef
This is my device profile, need to overdrive KERNEL_INITRAMFS
to include uImage header:
define Device/tplink_tl-wr941hp-v2
$(Device/tplink-8mlzma)
SOC := tp9343
DEVICE_MODEL := TL-WR941HP
DEVICE_VARIANT := v2
TPLINK_BOARD_ID := TLWR941HPV2
SUPPORTED_DEVICES += tl-wr941hp-v2
KERNEL_INITRAMFS := kernel-bin | append-dtb | lzma | uImageArcher lzma
endef
TARGET_DEVICES += tplink_tl-wr941hp-v2
The Openwrt bootlog:
ath> bootm
## Booting image at 81000000 ...
Verifying Checksum at 0x81000040 ...OK
Uncompressing Multi-File Image ... OK
No initrd
## Transferring control to Linux (at address 80060000) ...
## Giving linux memsize in bytes, 67108864
Starting kernel ...
[ 0.000000] Linux version 4.19.101 (xpduyson@DESKTOP-9RMCMKP) (gcc version 8.3.0 (OpenWrt GCC 8.3.0 r12191-aca274091a)) #0 Thu Feb 6 10:36:15 2020
[ 0.000000] bootconsole [early0] enabled
[ 0.000000] CPU0 revision is: 00019750 (MIPS 74Kc)
[ 0.000000] MIPS: machine is TP-Link TL-WR941HP v2
[ 0.000000] SoC: Qualcomm Atheros TP9343 rev 0
[ 0.000000] Determined physical RAM map:
[ 0.000000] memory: 04000000 @ 00000000 (usable)
[ 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, VIPT, cache aliases, linesize 32 bytes
[ 0.000000] Zone ranges:
[ 0.000000] Normal [mem 0x0000000000000000-0x0000000003ffffff]
[ 0.000000] Movable zone start for each node
[ 0.000000] Early memory node ranges
[ 0.000000] node 0: [mem 0x0000000000000000-0x0000000003ffffff]
[ 0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000003ffffff]
[ 0.000000] random: get_random_bytes called from 0x804886c4 with crng_init=0
[ 0.000000] Built 1 zonelists, mobility grouping on. Total pages: 16256
[ 0.000000] Kernel command line: console=ttyS0,115200n8 rootfstype=squashfs,jffs2
[ 0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
[ 0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
[ 0.000000] Writing ErrCtl register=00000000
[ 0.000000] Readback ErrCtl register=00000000
[ 0.000000] Memory: 52020K/65536K available (3575K kernel code, 157K rwdata, 516K rodata, 8032K init, 199K bss, 13516K reserved, 0K cma-reserved)
[ 0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[ 0.000000] NR_IRQS: 51
[ 0.000000] CPU clock: 750.000 MHz
[ 0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 5096694524 ns
[ 0.000009] sched_clock: 32 bits at 375MHz, resolution 2ns, wraps every 5726622718ns
[ 0.008247] Calibrating delay loop... 373.55 BogoMIPS (lpj=1867776)
[ 0.074848] pid_max: default: 32768 minimum: 301
[ 0.079926] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[ 0.086903] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[ 0.098778] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[ 0.109201] futex hash table entries: 256 (order: -1, 3072 bytes)
[ 0.115738] pinctrl core: initialized pinctrl subsystem
[ 0.122423] NET: Registered protocol family 16
[ 0.156091] clocksource: Switched to clocksource MIPS
[ 0.162766] NET: Registered protocol family 2
[ 0.168227] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes)
[ 0.176398] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[ 0.183761] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[ 0.190489] TCP: Hash tables configured (established 1024 bind 1024)
[ 0.197381] UDP hash table entries: 256 (order: 0, 4096 bytes)
[ 0.203563] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[ 0.210577] NET: Registered protocol family 1
[ 0.423544] Crashlog allocated RAM at address 0x3f00000
[ 0.430833] workingset: timestamp_bits=30 max_order=14 bucket_order=0
[ 0.443323] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[ 0.449533] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[ 0.494216] io scheduler noop registered
[ 0.498413] io scheduler deadline registered (default)
[ 0.505905] pinctrl-single 1804002c.pinmux: 544 pins, size 68
[ 0.513284] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[ 0.520867] console [ttyS0] disabled
[ 0.524679] 18020000.uart: ttyS0 at MMIO 0x18020000 (irq = 9, base_baud = 1562500) is a 16550A
[ 0.533835] console [ttyS0] enabled
[ 0.533835] console [ttyS0] enabled
[ 0.541402] bootconsole [early0] disabled
[ 0.541402] bootconsole [early0] disabled
[ 0.559733] m25p80 spi0.0: gd25q64 (8192 Kbytes)
[ 0.564555] 4 fixed-partitions partitions found on MTD device spi0.0
[ 0.571191] Creating 4 MTD partitions on "spi0.0":
[ 0.576172] 0x000000000000-0x000000010000 : "u-boot"
[ 0.582248] 0x000000010000-0x0000007e0000 : "firmware"
[ 0.591606] 0x0000007e0000-0x0000007f0000 : "mib0"
[ 0.597594] 0x0000007f0000-0x000000800000 : "art"
[ 0.604574] libphy: Fixed MDIO Bus: probed
[ 0.967185] ag71xx 19000000.eth: Could not connect to PHY device. Deferring probe.
[ 1.646520] libphy: ag71xx_mdio: probed
[ 1.651334] libphy: ar8xxx-mdio: probed
[ 1.726495] switch0: Atheros AR8229 rev. 1 switch registered on mdio-bus.0
[ 1.813672] ag71xx 1a000000.eth: connected to PHY at fixed-0:00 [uid=00000000, driver=Generic PHY]
[ 1.823704] eth0: Atheros AG71xx at 0xba000000, irq 5, mode: gmii
[ 1.833397] NET: Registered protocol family 10
[ 1.844673] Segment Routing with IPv6
[ 1.848658] NET: Registered protocol family 17
[ 1.853328] 8021q: 802.1Q VLAN Support v1.8
[ 2.199738] ag71xx 19000000.eth: connected to PHY at mdio-bus.0:1f:04 [uid=004dd042, driver=Generic PHY]
[ 2.210617] eth1: Atheros AG71xx at 0xb9000000, irq 4, mode: mii
[ 2.283234] Freeing unused kernel memory: 8032K
[ 2.287952] This architecture does not have kernel memory protection.
[ 2.294603] Run /init as init process
[ 2.314074] init: Console is alive
[ 2.318082] init: - watchdog -
[ 2.331918] random: fast init done
[ 2.347231] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[ 2.357810] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[ 2.366641] init: - preinit -
[ 2.593375] random: jshn: uninitialized urandom read (4 bytes read)
[ 2.685913] random: jshn: uninitialized urandom read (4 bytes read)
[ 2.823716] random: jshn: uninitialized urandom read (4 bytes read)
[ 3.180311] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 3.186539] IPv6: ADDRCONF(NETDEV_UP): eth0.1: link is not ready
Press the [f] key and hit [enter] to enter failsafe mode
Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level
[ 4.257302] eth0: link up (1000Mbps/Full duplex)
[ 4.263053] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 4.282325] IPv6: ADDRCONF(NETDEV_CHANGE): eth0.1: link becomes ready
[ 7.375449] eth0: link down
[ 7.400929] procd: - early -
[ 7.404043] procd: - watchdog -
[ 7.958417] procd: - watchdog -
[ 7.962054] procd: - ubus -
[ 7.972879] urandom_read: 5 callbacks suppressed
[ 7.972888] random: ubusd: uninitialized urandom read (4 bytes read)
[ 8.015807] random: ubusd: uninitialized urandom read (4 bytes read)
[ 8.024119] procd: - init -
Please press Enter to activate this console.
[ 8.540306] kmodloader: loading kernel modules from /etc/modules.d/*
[ 8.598523] Loading modules backported from Linux version v5.4-rc8-0-gaf42d3466bdc
[ 8.606424] Backport generated by backports.git v5.4-rc8-1-0-g368e8c51
[ 8.670484] xt_time: kernel timezone is -0000
[ 8.834538] urngd: v1.0.2 started.
[ 8.841142] PPP generic driver version 2.4.2
[ 8.857249] NET: Registered protocol family 24
[ 9.009707] ieee80211 phy0: Atheros AR9561 Rev:0 mem=0xb8100000, irq=2
[ 9.086616] kmodloader: done loading kernel modules from /etc/modules.d/*
[ 9.133300] random: crng init done
[ 38.868525] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 38.875831] eth0: link up (1000Mbps/Full duplex)
[ 38.888405] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[ 38.926530] br-lan: port 1(eth0.1) entered blocking state
[ 38.932116] br-lan: port 1(eth0.1) entered disabled state
[ 38.938142] device eth0.1 entered promiscuous mode
[ 38.943101] device eth0 entered promiscuous mode
[ 38.979533] br-lan: port 1(eth0.1) entered blocking state
[ 38.985128] br-lan: port 1(eth0.1) entered forwarding state
[ 38.991186] IPv6: ADDRCONF(NETDEV_UP): br-lan: link is not ready
[ 39.078754] IPv6: ADDRCONF(NETDEV_UP): eth1: link is not ready
[ 39.936939] IPv6: ADDRCONF(NETDEV_CHANGE): br-lan: link becomes ready
BusyBox v1.31.1 () built-in shell (ash)
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
OpenWrt SNAPSHOT, r12191-aca274091a
-----------------------------------------------------
=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
root@OpenWrt:/#