landley / toybox

toybox
http://landley.net/toybox
BSD Zero Clause License
2.42k stars 335 forks source link

[feature request] parsing kernel cmdline parameter when modprobe #522

Open mjiey opened 1 week ago

mjiey commented 1 week ago

Linux doc describes that modprobe supports two ways of passing parameter, and toybox modprobe seems to support one (modprobe command line). Could we also support reading from kernel command line? That would help a lot when using toybox across platforms.

Module parameters can be specified in two ways: via the kernel command line with a module name prefix, or via modprobe, e.g.:

(kernel command line) usbcore.blinkenlights=1 (modprobe command line) modprobe usbcore blinkenlights=1

reference: https://www.kernel.org/doc/html/v4.12/admin-guide/kernel-parameters.html

landley commented 1 week ago

On 10/7/24 09:13, mjiey wrote:

Linux doc describes that modprobe supports two ways of passing parameter, and toybox modprobe seems to support one (modprobe command line). Could we also support reading from kernel command line? That would help a lot when using toybox across platforms.

Does modprobe need to parse /proc/cmdline to get this? I thought the kernel did it internally (since the kernel already HAS this information). Your link says the kernel does it for static linking and has modprobe do it for dynamic linking which seems silly, but ok...

I don't see a command line option in man modprobe to not do this. (If it's also specified on the command line, does the command line one win? Is there a command line way to switch it off?)

Not hugely familiar with this area, I tend to build static kernels...

Rob

mjiey commented 5 days ago

I don't find a nice doc describing order of precedence except linux-util source code ... , and current implementation is that modprobe command line overrides kernel command line.

I think the general idea is modprobe command line > modprobed config > kernel boot parameter.

Jie

landley commented 3 days ago

On 10/13/24 23:02, mjiey wrote:

I don't find a nice doc describing order of precedence except linux-util source code ... , and current implementation is that modprobe command line overrides kernel command line.

Mostly it's a "what if we don't want to supply this argument at ALL" question (would thingy= on the command line sufficiently nerf it?), but I don't use modules enough to know if that comes up much. (Which is also the main reason modprobe.c is still in pending: I understand insmod enough to promote it, but not modprobe. It was submitted by some developers who have since moved on.)

I checked the man page for some way to switch off checking /proc/cmdline (which seems like it would only work when /proc is mounted, not always the case doing bringup from initramfs?) but didn't see an existing option.

Also, /proc/cmdline is space separated not NULL separated so needs to be re-parsed, and the kernel-parameters.html you pointed to says double quotes can be used to preserve spaces but are double quotes themselves escaped? (And nothing ELSE will have double quotes? /proc/mounts uses percent escapes, but I shouldn't expect consistency from proc...)

I think the general idea is modprobe command line > modprobed config > kernel boot parameter.

Understood. I'll take a stab at it, thanks.

Rob