[Solved] How to Build a Pure RAM Firmware?

Hello,

I have an idea to run Openwrt in full RAM which is loaded via TFTP protocol from remote during booting.
How can I build the image to make this working?
I tried to load initramfs via TFTP, and can see the initialization logs and my router is flashing to indicate something is working. But it ended up with kernel PANIC. I guess the problem comes from the mounting file system, but not quite sure.

Could someone give me some hint to make it running?

Thank you.

The question is why run out of RAM? What exactly is it you are trying to do?

Some hardware context would be helpful and error log output.

I'm trying to have only uboot in ROM and load image via TFTP from network.

Please check in "make menuconfig" the options under "Target image", there you can find the option "ramdisk"

The uimage-initramfs is what you're trying to find.

1 Like

Hi.
I've generated the ramdisk, however it does not seems to be the final stage.
The following are the log

bootm 0x80800000


## Booting image at 80800000 ...

   Image Name:   MIPS OpenWrt Linux-5.4.137

   Created:      2021-08-04   6:42:30 UTC

   Image Type:   MIPS Linux Kernel Image (lzma compressed)

   Data Size:    4840796 Bytes =  4.6 MB

   Load Address: 80060000

   Entry Point:  80060000

   Verifying Checksum ... OK

   Uncompressing Kernel Image ... OK

No initrd

## Transferring control to Linux (at address 80060000) ...

## Giving linux memsize in bytes, 134217728



Starting kernel ...



[    0.000000] Linux version 5.4.137 (gwei4@5CD01567MZ) (gcc version 8.4.0 (OpenWrt GCC 8.4.0 r17252-b37f0dde78)) #0 Wed Aug 4 06:42:30 2021

[    0.000000] printk: bootconsole [early0] enabled

[    0.000000] CPU0 revision is: 00019374 (MIPS 24Kc)

[    0.000000] MIPS: machine is Netgear WNDR3800

[    0.000000] SoC: Atheros AR7161 rev 2

[    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-0x0000000007ffffff]

[    0.000000] Movable zone start for each node

[    0.000000] Early memory node ranges

[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000007ffffff]

[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000007ffffff]

[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 32480

[    0.000000] Kernel command line: root=/dev/ram0 rootfstype=ramfs console=ttyS0,115200 root=31:02 rootfstype=jffs2 init=/sbin/init mtdparts=ar7100-nor0:256k(uboot),128k(env),6144k(rootfs),64k(caldata),1024k(uImage)

[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes, linear)

[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes, linear)

[    0.000000] Writing ErrCtl register=00000000

[    0.000000] Readback ErrCtl register=00000000

[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off

[    0.000000] Memory: 119440K/131072K available (4927K kernel code, 183K rwdata, 1128K rodata, 3864K init, 196K bss, 11632K 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] random: get_random_bytes called from start_kernel+0x358/0x54c with crng_init=0

[    0.000000] CPU clock: 680.000 MHz

[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 5621354254 ns

[    0.000007] sched_clock: 32 bits at 340MHz, resolution 2ns, wraps every 6316128254ns

[    0.007797] Calibrating delay loop... 452.19 BogoMIPS (lpj=2260992)

[    0.074058] pid_max: default: 32768 minimum: 301

[    0.078822] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)

[    0.086120] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes, linear)

[    0.097997] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns

[    0.107861] futex hash table entries: 256 (order: -1, 3072 bytes, linear)

[    0.114738] pinctrl core: initialized pinctrl subsystem

[    0.120846] NET: Registered protocol family 16

[    0.431394] PCI host bridge /ahb/apb/pcie-controller@17010000 ranges:

[    0.437852]  MEM 0x0000000010000000..0x0000000016ffffff

[    0.443079]   IO 0x0000000000000000..0x0000000000000000

[    0.466181] PCI host bridge to bus 0000:00

[    0.470283] pci_bus 0000:00: root bus resource [mem 0x10000000-0x16ffffff]

[    0.477199] pci_bus 0000:00: root bus resource [io  0x0000]

[    0.482760] pci_bus 0000:00: root bus resource [??? 0x00000000 flags 0x0]

[    0.489537] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]

[    0.497962] pci 0000:00:11.0: [168c:ff1d] type 00 class 0x020000

[    0.503992] pci 0000:00:11.0: reg 0x10: [mem 0x00000000-0x0000ffff]

[    0.510542] pci 0000:00:12.0: [168c:ff1d] type 00 class 0x020000

[    0.516592] pci 0000:00:12.0: reg 0x10: [mem 0x00000000-0x0000ffff]

[    0.523444] pci_bus 0000:00: busn_res: [bus 00-ff] end is updated to 00

[    0.530090] pci 0000:00:11.0: BAR 0: assigned [mem 0x10000000-0x1000ffff]

[    0.536865] pci 0000:00:12.0: BAR 0: assigned [mem 0x10010000-0x1001ffff]

[    0.543747] workqueue: max_active 576 requested for napi_workq is out of range, clamping between 1 and 512

[    0.556981] clocksource: Switched to clocksource MIPS

[    0.563005] NET: Registered protocol family 2

[    0.567587] IP idents hash table entries: 2048 (order: 2, 16384 bytes, linear)

[    0.575339] tcp_listen_portaddr_hash hash table entries: 512 (order: 0, 4096 bytes, linear)

[    0.583745] TCP established hash table entries: 1024 (order: 0, 4096 bytes, linear)

[    0.591409] TCP bind hash table entries: 1024 (order: 0, 4096 bytes, linear)

[    0.598462] TCP: Hash tables configured (established 1024 bind 1024)

[    0.604937] UDP hash table entries: 256 (order: 0, 4096 bytes, linear)

[    0.611497] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes, linear)

[    0.618715] NET: Registered protocol family 1

[    0.623107] PCI: CLS 0 bytes, default 32

[    2.586988] random: fast init done

[    4.762418] workingset: timestamp_bits=14 max_order=15 bucket_order=1

[    4.774934] squashfs: version 4.0 (2009/01/31) Phillip Lougher

[    4.780802] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.

[    4.802249] ar7100-usb-phy 18030000.usb-phy: phy reset is missing

[    4.809285] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled

[    4.816212] printk: console [ttyS0] disabled

[    4.820580] 18020000.uart: ttyS0 at MMIO 0x18020000 (irq = 10, base_baud = 10625000) is a 16550A

[    4.829379] printk: console [ttyS0] enabled

[    4.829379] printk: console [ttyS0] enabled

[    4.837720] printk: bootconsole [early0] disabled

[    4.837720] printk: bootconsole [early0] disabled

[    4.852901] spi-nor spi0.0: mx25l12805d (16384 Kbytes)

[    4.858143] 4 fixed-partitions partitions found on MTD device spi0.0

[    4.864475] Creating 4 MTD partitions on "spi0.0":

[    4.869275] 0x000000000000-0x000000050000 : "u-boot"

[    4.875103] 0x000000050000-0x000000070000 : "u-boot-env"

[    4.881283] 0x000000070000-0x000000ff0000 : "firmware"

[    4.890104] 2 uimage-fw partitions found on MTD device firmware

[    4.896022] Creating 2 MTD partitions on "firmware":

[    4.901037] 0x000000000000-0x00000018c440 : "kernel"

[    4.906822] 0x00000018c440-0x000000f80000 : "rootfs"

[    4.912603] mtd: device 4 (rootfs) set to be root filesystem

[    4.919862] 1 squashfs-split partitions found on MTD device rootfs

[    4.926054] 0x000000400000-0x000000f80000 : "rootfs_data"

[    4.932341] 0x000000ff0000-0x000001000000 : "art"

[    4.938376] Realtek RTL8366S ethernet switch driver version 0.2.2

[    4.944527] rtl8366s rtl8366s: cannot find mdio node phandle

[    4.950249] rtl8366s rtl8366s: using GPIO pins 5 (SDA) and 7 (SCK)

[    4.956503] rtl8366s rtl8366s: RTL8366 ver. 1 chip found

[    5.011216] libphy: rtl8366s: probed

[    5.042330] libphy: Fixed MDIO Bus: probed

[    5.423738] ag71xx 19000000.eth: connected to PHY at fixed-0:00 [uid=00000000, driver=Generic PHY]

[    5.433308] eth0: Atheros AG71xx at 0xb9000000, irq 4, mode: rgmii

[    5.778595] ag71xx 1a000000.eth: connected to PHY at rtl8366s:04 [uid=001cc960, driver=Generic PHY]

[    5.788270] eth1: Atheros AG71xx at 0xba000000, irq 5, mode: rgmii

[    5.794606] i2c /dev entries driver

[    5.800333] NET: Registered protocol family 10

[    5.809274] Segment Routing with IPv6

[    5.813036] NET: Registered protocol family 17

[    5.817587] 8021q: 802.1Q VLAN Support v1.8

[    5.835723] Freeing unused kernel memory: 3864K

[    5.840281] This architecture does not have kernel memory protection.

[    5.846697] Run /init as init process

[    6.219604] init: Console is alive

[    6.223236] init: - watchdog -

[    6.252519] kmodloader: loading kernel modules from /etc/modules-boot.d/*

[    6.300812] usbcore: registered new interface driver usbfs

[    6.306346] usbcore: registered new interface driver hub

[    6.311790] usbcore: registered new device driver usb

[    6.322856] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver

[    6.331029] ehci-fsl: Freescale EHCI Host controller driver

[    6.338069] ehci-platform: EHCI generic platform driver

[    6.942496] ehci-platform 1b000000.usb: EHCI Host Controller

[    6.948179] ehci-platform 1b000000.usb: new USB bus registered, assigned bus number 1

[    6.956118] ehci-platform 1b000000.usb: irq 3, io mem 0x1b000000

[    6.986996] ehci-platform 1b000000.usb: USB 2.0 started, EHCI 1.00

[    6.993979] hub 1-0:1.0: USB hub found

[    6.998170] hub 1-0:1.0: 2 ports detected

[    7.006732] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver

[    7.014590] ohci-platform: OHCI generic platform driver

[    7.020092] ohci-platform 1c000000.usb: Generic Platform OHCI controller

[    7.026832] ohci-platform 1c000000.usb: new USB bus registered, assigned bus number 2

[    7.034775] ohci-platform 1c000000.usb: irq 14, io mem 0x1c000000

[    7.111823] hub 2-0:1.0: USB hub found

[    7.115957] hub 2-0:1.0: 2 ports detected

[    7.121474] kmodloader: done loading kernel modules from /etc/modules-boot.d/*

[    7.139168] init: - preinit -

[    7.385675] random: jshn: uninitialized urandom read (4 bytes read)

[    7.507183] random: jshn: uninitialized urandom read (4 bytes read)

[    7.773285] random: jshn: uninitialized urandom read (4 bytes read)

[    8.155269] eth0: link up (1000Mbps/Full duplex)

[    8.161113] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes 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

[   12.307295] eth0: link down

[   12.321479] procd: - early -

[   12.324450] procd: - watchdog -

[   12.879711] procd: - watchdog -

[   12.883234] procd: - ubus -

[   12.893995] urandom_read: 5 callbacks suppressed

[   12.894003] random: ubusd: uninitialized urandom read (4 bytes read)

[   12.935774] random: ubusd: uninitialized urandom read (4 bytes read)

[   12.945139] procd: - init -

Please press Enter to activate this console.

[   13.528249] kmodloader: loading kernel modules from /etc/modules.d/*

[   13.740856] Loading modules backported from Linux version v5.10.42-0-g65859eca4dff

[   13.748487] Backport generated by backports.git v5.10.42-1-0-gbee5c545

[   13.809764] xt_time: kernel timezone is -0000

[   13.827888] ath9k_pci_owl_loader 0000:00:11.0: enabling device (0000 -> 0002)

[   13.835216] ath9k_pci_owl_loader 0000:00:12.0: enabling device (0000 -> 0002)

[   13.842709] ath9k_pci_owl_loader 0000:00:11.0: Direct firmware load for ath9k-eeprom-pci-0000:00:11.0.bin failed with error -2

[   13.854123] ath9k_pci_owl_loader 0000:00:11.0: Falling back to sysfs fallback for: ath9k-eeprom-pci-0000:00:11.0.bin

[   13.877780] ath9k_pci_owl_loader 0000:00:12.0: Direct firmware load for ath9k-eeprom-pci-0000:00:12.0.bin failed with error -2

[   13.889211] ath9k_pci_owl_loader 0000:00:12.0: Falling back to sysfs fallback for: ath9k-eeprom-pci-0000:00:12.0.bin

[   14.015225] urngd: v1.0.2 started.

[   14.099407] PPP generic driver version 2.4.2

[   14.109788] NET: Registered protocol family 24

[   14.180513] ath9k_pci_owl_loader 0000:00:11.0: fixup device configuration

[   14.214921] pci 0000:00:11.0: [168c:0029] type 00 class 0x028000

[   14.221007] pci 0000:00:11.0: reg 0x10: [mem 0x10000000-0x1000ffff]

[   14.227317] pci 0000:00:11.0: PME# supported from D0 D3hot

[   14.233446] pci 0000:00:11.0: BAR 0: assigned [mem 0x10000000-0x1000ffff]

[   14.277722] ath9k 0000:00:11.0: enabling device (0000 -> 0002)

[   14.307327] CPU 0 Unable to handle kernel paging request at virtual address 000000d8, epc == 8032b5d4, ra == 8032b614

[   14.317923] Oops[#1]:

[   14.320194] CPU: 0 PID: 688 Comm: kmodloader Not tainted 5.4.137 #0

[   14.326439] $ 0   : 00000000 00000001 00000000 86cf4900

[   14.331650] $ 4   : 00000010 86cf4e00 00000000 00000927

[   14.336863] $ 8   : 00000000 805296bc 00000010 00000000

[   14.342075] $12   : 000c214e eb402f06 00000402 00000114

[   14.347288] $16   : 00000001 00000010 86cf4e80 8731fa48

[   14.352500] $20   : 00000000 86d0ac00 8725c0a8 00000100

[   14.357713] $24   : 00000010 8033b33c

[   14.362926] $28   : 8731e000 8731f9c0 00000018 8032b614

[   14.368139] Hi    : 000c214e

[   14.371006] Lo    : eb402f06

[   14.373884] epc   : 8032b5d4 add_dr+0x10/0x30

[   14.378230] ra    : 8032b614 devres_add+0x20/0x44

[   14.382919] Status: 1000fc02 KERNEL EXL

[   14.386835] Cause : 00800008 (ExcCode 02)

[   14.390825] BadVA : 000000d8

[   14.393692] PrId  : 00019374 (MIPS 24Kc)

[   14.397595] Modules linked in: ath9k(+) ath9k_common pppoe ppp_async iptable_nat ath9k_hw ath xt_state xt_nat xt_conntrack xt_REDIRECT xt_MASQUERADE xt_FLOWOFFLOAD pppox ppp_generic nf_nat nf_flow_table_hw nf_flow_table nf_conntrack mac80211 ipt_REJECT cfg80211 ath9k_pci_owl_loader xt_time xt_tcpudp xt_multiport xt_mark xt_mac xt_limit xt_comment xt_TCPMSS xt_LOG slhc nf_reject_ipv4 nf_log_ipv4 nf_defrag_ipv6 nf_defrag_ipv4 iptable_mangle iptable_filter ip_tables crc_ccitt compat ledtrig_usbport nf_log_ipv6 nf_log_common ip6table_mangle ip6table_filter ip6_tables ip6t_REJECT x_tables nf_reject_ipv6 sha256_generic libsha256 seqiv jitterentropy_rng drbg hmac ghash_generic gf128mul gcm ctr cmac ccm ohci_platform ohci_hcd fsl_mph_dr_of ehci_platform ehci_fsl ehci_hcd gpio_button_hotplug usbcore nls_base usb_common aead cryptomgr crypto_null crypto_hash

[   14.472665] Process kmodloader (pid: 688, threadinfo=(ptrval), task=(ptrval), tls=77e09ec8)

[   14.480988] Stack : 800019a0 800019a0 00000010 8731fa48 86cf4e00 8032b71c 00000001 86d0ac00

[   14.489327]         8066c678 87da9d40 800019a0 00000006 8731fa48 8032b838 00000006 00000000

[   14.497664]         00000000 00000000 800019a0 80004668 80600000 80395d58 8725c080 87fc29a8

[   14.506004]         8731fa48 87261f24 00000006 8731fa40 8731fa48 87764020 00000cc0 00000005

[   14.514342]         00000006 00000008 04a151b7 677dfa4c 8731fa4c 8725c080 80004668 87fc1ec0

[   14.522680]         ...

[   14.525114] Call Trace:

[   14.527553] [<8032b5d4>] add_dr+0x10/0x30

[   14.531556] [<8032b71c>] devm_kmalloc+0x70/0xac

[   14.536074] [<8032b838>] devm_kmemdup+0x28/0x5c

[   14.540608] [<80395d58>] of_get_mac_address+0x254/0x344

[   14.545918] [<872620f4>] ath_start_rfkill_poll+0x550/0x6c8 [ath9k]

[   14.552129] Code: 00a21026  0002102b  00020336 <8c8200c8> 248300c4  ac8500c8  aca30000  aca20004  ac450000

[   14.561861]

[   14.563398] ---[ end trace 661f1726c7b7f44c ]---

[   14.568012] Kernel panic - not syncing: Fatal exception

[   14.573219] Rebooting in 1 seconds..

IIRC, some wifi driver required to have their calibration data properly loaded, otherwise they will cause kernel panic which is what seems to happening here.

Try to disable the pcie node in your device tree first to see if it boot up then working towards to make it correctly extract the required calib/firmware file.

no that's kmod-ath9k wifi driver that blows up for some reason or another.

Since it is a module, you can just remove it from the build

see the last line before the kernel panic, it's ath9k kernel module that is trying to enable the wifi chip.

[   14.277722] ath9k 0000:00:11.0: enabling device (0000 -> 0002)

[   14.307327] CPU 0 Unable to handle kernel paging request at virtual address 000000d8, epc == 8032b5d4, ra == 8032b614

[   14.317923] Oops[#1]:
1 Like

Hello,
Sorry for late response. I went for a vacation since last post.

I tried to remove it in during make menuconfig, however found it not changable.

of_get_mac_address

This is the source of problem. Crash during loading dts.
You have to attach it to the kernel image, do not know how.

That function was supposedly fixed in several commits 5-10 days ago. (later the the OP
Most recent fix being:

A simple question, how can I apply this patch?

patch < file.patch

--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c

when I applied "patch < file.patch", it couldn't find the file to patch.

the paths have to match, if not, remove the paths in the patch file and use cwd, or provide absolut ones.
soft linking would work too.

there's probably a parameter for it as well.

Could you make it more clear? I don't know to which extend should I remove the path?
At least I need to know where to find or put the file of_net.c
Thanks

so it matches the location of the of_net.c

slow and dirty - find / -name of_net.c

since it is changing a couple lines in a file and deleting others, you can also do this manually if you find the right file.
As you can see from the github interface, the commit is editing these two patch files
target/linux/generic/pending-5.10/683-of_net-add-mac-address-to-of-tree.patch
target/linux/generic/pending-5.4/683-of_net-add-mac-address-to-of-tree.patch

The below are the result of searching of_net.c

xxx@XXXX:~/openwrt$ find ~/openwrt -name of_net.c
/home/xxx/openwrt/build_dir/toolchain-x86_64_gcc-8.4.0_musl/linux-5.4.128/drivers/of/of_net.c
/home/xxx/openwrt/build_dir/toolchain-mips_24kc_gcc-7.5.0_musl/linux-4.14.221/drivers/of/of_net.c
/home/xxx/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/linux-5.4.137/drivers/of/of_net.c
/home/xxx/openwrt/build_dir/toolchain-mips_24kc_gcc-8.4.0_musl/linux-5.4.137/drivers/of/of_net.c

I guess the x86 one and linux-4.14 one are not relevant, should I patch both

/home/xxx/openwrt/build_dir/target-mips_24kc_musl/linux-ath79_generic/linux-5.4.137/drivers/of/of_net.c

and

/home/xxx/openwrt/build_dir/toolchain-mips_24kc_gcc-8.4.0_musl/linux-5.4.137/drivers/of/of_net.c

?

It has already been applied to the current master.
Just update the git repo to the HEAD