Mt7621, bootargs (command line) from Bootloader

Yes, agreed! I'm finding that on boot the values in the (writeable) u_env partition are being reset ... so I may be mistaken where the read is from, rather that somehow OpenWrt is forcing a reset (of the variables). Will keep digging, let you know what I find. The biggest issue is finding where all this is inside Linux - not so easy :frowning_face:.

Thanks!

OK, made some good progress! Let me try to explain - I think I only have one nitpicky item left :grinning_face_with_smiling_eyes:.

First, an observation. I was pulling my hair out, as I would set u-boot environment variables, and they seemed to be disappearing. Then I found it! In the serial logs, if I changed the boot_part value (dual partition router), and rebooted, I see (for example),

sync bootargs for ALT
..Erasing NAND Flash...
ranand_erase: start:80000, len:20000
.Writing to NAND Flash...
done

Well, dang it - there it is! Linksys u-boot is overwriting my environment, with it's defaults! But interestingly enough, bootargs is set as follows,

bootargs=console=ttyS1,115200n8 root=/dev/mtdblock6 ro rootfstype=jffs2 init=/sbin/init

Very close to what I want, and ... root is adjusted (automatically, by Linksys u-boot) to mtdblock6 or mtdblock8, depending on the value of boot_part. Sweet! So now I just need to have used in my router, to set the rootfs (ubi).

Then, I found how to get root set (and named to ubi, mounted), based on the root device in the command line. It takes 3 things,

  1. kernel configuration (kernel_menuconfig), Extend dtb kernel arguments with bootloader arguments. This allows me to read / use the input from u-boot.
  2. include the patch, 202-linksys-find-active-root.patch. As it says right in it (and I just need the same)
The WRT1900AC among other Linksys routers uses a dual-firmware layout.
Dynamically rename the active partition to "ubi".
  1. OK, so the command line is read in (appended) from u-boot, I can use that information, just need to handle it. It turns out this just requires CONFIG_MANGLE_BOOTARGS. This extracts the mtdblock number, and uses it to (dyanmically) set ubi (rootfs). Great!

Checked, and confirmed to be working (on both partitions). Just a couple minor questions now,

  • How to set CONFIG_MANGLE_BOOTARGS for this target (and not the entire family)?
  • I end up with two consoles ... one from the u-boot command line (as above), the other from the kernel configuration. And with 2 of them enabled (Kernel command line), I see output like,
[    4.157449] Run /sbin/init as init process
[    4.157449] Run /sbin/init as init process
[    4.165604]   with arguments:
[    4.165604]   with arguments:
[    4.171513]     /sbin/init
[    4.171513]     /sbin/init
[    4.176902]   with environment:
[    4.176902]   with environment:
[    4.183161]     HOME=/
[    4.183161]     HOME=/
[    4.187850]     TERM=linux
[    4.187850]     TERM=linux
[    4.193238]     mangled_fs=jffs2
[    4.193238]     mangled_fs=jffs2

So everything is double output (to console). I'd remove the OpenWrt configured one, but it seems that the console provided by u-boot is output only, not input. Huh?

By all means yell if this all seems crazy :stuck_out_tongue_winking_eye:. Thanks!

BTW, much of this I found from the ea3500, looking through that code. It's also a dual partition Linksys router.

OK, seems to be working - some testing done here. And adding @jmsmuy, so we're all on the same page.

I think all that is still open is,

The second of these is very minor, not worth holding any thing up. It only shows up in the console, not kernel log ... so without a serial port, you won't even be able to see it.

The first is the one I would like to fix (if needed, perhaps not) - any thoughts on how to set a configuration parameter (e.g. CONFIG_MANGLE_BOOTARGS), only for a specific target?

Thanks!

And one update to above - I did go back, given these "final" settings .. see if kernel v5.4 was working. Nope. It doesn't properly retrieve the command line from u-boot (but v5.10 does). Not sure if that's a known issue or not.

Wondering if this patch is causing the grief, 0001-MIPS-cmdline-Clean-up-boot_command_line-initializati.patch

1 Like

Found it - woohoo :smiley:. Two patch issues with the 5.4 kernel ...

  1. This patch needs to be removed - it blows away arcs_cmdline, which is actually what we need! It appears it was already found and removed for 5.10, but not back to 5.4.
  2. Then, also apply this one - seems to be missing in v5.4 (was a correction in 5.5).

With these two patches - 5.4 kernel seems to work also. @jmsmuy, care to give 5.4 a try?

Thanks!

2 Likes

Sure! Send me the bin and I'll flash and test it :slight_smile:

I can confirm it's working :slight_smile:

1 Like

Excellent, thanks! So the issue was the bootargs being removed (by that first, very old, patch).

PR created,

2 Likes

Do I have the the same eproblem with my Xiaomi Mi Router AC2100 (round black one) same CPU MT7621

part of the log file ...
4.808445] /dev/root: Can't open blockdev
[ 4.812560] VFS: Cannot open root device "(null)" or unknown-block(0,0): error -6
[ 4.820023] Please append a correct "root=" boot option; here are the available partitions:
[ 4.828363] 1f00 512 mtdblock0
[ 4.828368] (driver?)
[ 4.834890] 1f01 256 mtdblock1
[ 4.834893] (driver?)
[ 4.841429] 1f02 256 mtdblock2
[ 4.841432] (driver?)
[ 4.847969] 1f03 256 mtdblock3
[ 4.847972] (driver?)
[ 4.854493] 1f04 256 mtdblock4
[ 4.854497] (driver?)
[ 4.861033] 1f05 256 mtdblock5
[ 4.861036] (driver?)
[ 4.867578] 1f06 256 mtdblock6
[ 4.867581] (driver?)
[ 4.874101] 1f07 4096 mtdblock7
[ 4.874105] (driver?)
[ 4.880640] 1f08 4096 mtdblock8
[ 4.880644] (driver?)
[ 4.887165] 1f09 120320 mtdblock9
[ 4.887168] (driver?)
[ 4.893715] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
[ 4.901978] Rebooting in 1 seconds..Text Dokumebnt
...
the router boots periodically
thanks a lot for your Help.

Sure looks like it - I get this as the command line is not processed / used.

Hi Arrmo
I have little experience as far as terminal operation is concerned and I am not a developer, but as far as compiling is concerned I have no experience. I loaded the kernel file "openwrt-21.02.0-rc1-ramips-mt7621-xiaomi_mi-router-ac2100-squashfs-kernel1.bin", but still the same behavior. I also don't know where to get the source to generate the 2 BIN files. Is there a simple (how-to) or a download where I can download a corrected version for the said router type?
General question, since this error happens on a different type of router than your described "Linksys ea7300", do I have to create a new post even if the same behavior is on another router?
I would be very grateful if you could help me :wink:
cheers Cristian

Hi,

Are you able to capture a serial log, and poste it to pastebin (putting the link here)?

Hi Arrmo

Here you should find the Log file I uploaded
pastbin

Thanks! OK, two things. I see in the log,
Kernel command line: console=ttyS0,115200n8 rootfstype=squashfs,jffs2

So no root partition sent there. And, in target/linux/ramips/dts/mt7621_xiaomi_nand_128m.dtsi, the ubi partition is set to mtd9 => also matches from the log you sent,

[    2.697626] 0x000000a00000-0x000007f80000 : "ubi"

[ 3.494953] UBI: auto-attach mtd9
[ 3.498311] ubi0: attaching mtd9
[ 4.715913] ubi0: scanning is finished
[ 4.736817] ubi0: attached mtd9 (name "ubi", size 117 MiB)
[ 4.742336] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[ 4.749200] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[ 4.755975] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[ 4.762923] ubi0: good PEBs: 940, bad PEBs: 0, corrupted PEBs: 0
[ 4.768921] ubi0: user volume: 0, internal volumes: 1, max. volumes count: 128
[ 4.776130] ubi0: max/mean erase counter: 3/2, WL threshold: 4096, image sequence number: 674944404
[ 4.785152] ubi0: available PEBs: 916, total reserved PEBs: 24, PEBs reserved for bad PEB handling: 20
[ 4.794463] ubi0: background thread "ubi_bgt0d" started, PID 489

So seems you need to somehow flash to mtd9 => it's expecting to find rootfs there.

Ok, silly question, but couldn't you just the kernel command-line hack?

image

and then add
CMDLINE := console=ttyS0,115200 root=<device> rootfstype=squashfs,jffs2
to the device define?

Yes, that may work as well. I need dual partition to work, so have to pass it in from U-Boot.

Thanks!

Hi Arrmo
Thank you very much for your help. Now I have to work my way through the software and its structure. How to change the boot partition via the serial interface, or how to find out to change the boot partition...
Unfortunately, I don't have an SSH connection to send an "ls" or other LINUX command. I have to do everything via the serial interface. (The only connection I have)
Cris

NP, yell if questions. I don't have that HW here, so can't try it in parallel - sorry!

that's very kind of you, thank you.
p.s. Greetings to Canada from Switzerland.
cheers Cris

1 Like