Passing parameter to kernel module

Hello everybody,

I am currently working on some customization of ath9k module. I want to pass some parameter to the module which is recognized by module_param().

I have been succeeded in passing parameter by write: [mod_name] param=[value], but I want to ask if I can have the param value from a command-line result ? I seems that in /etc/module.d/**** is not bash scripts, i can not perform bash script in these files.

Thanks!

You have to write a file for example mymoduleparam.conf with a the following content

option modulename param=1

Put these file into /etc/modules.d/ and now your module gets alwasys loaded with the defined parameters.

You can enable ATAG support in your kernel, it will allow you to provide a custom command line at boot which then you can choose to append to the one provided by the bootloader or to replace the bootloader with the one you provided.

While it seems a little "strange" to me, you might be able to "hook" the early procd scripts if you want to modify the parameters on-the-fly.

Be aware that many services won't be running and file systems may not be mounted yet, especially for the early load of modules.

Note the location of the kmodloader lines, relative to init lines. (This is from an EA8300, details of your device will vary):

[    2.886168] Run /sbin/init as init process
[    3.284253] init: Console is alive
[    3.284491] init: - watchdog -
[    4.431784] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    4.502021] dwc3 8a00000.dwc3: Failed to get clk 'ref': -2
[    4.649926] dwc3 6000000.dwc3: Failed to get clk 'ref': -2
[    4.794976] xhci-hcd xhci-hcd.0.auto: xHCI Host Controller
[    4.795050] xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 1
[    4.799603] xhci-hcd xhci-hcd.0.auto: hcc params 0x0228f665 hci version 0x100 quirks 0x0000000002010010
[    4.807019] xhci-hcd xhci-hcd.0.auto: irq 97, io mem 0x08a00000
[    4.817205] hub 1-0:1.0: USB hub found
[    4.822248] hub 1-0:1.0: 1 port detected
[    4.826430] xhci-hcd xhci-hcd.0.auto: xHCI Host Controller
[    4.830111] xhci-hcd xhci-hcd.0.auto: new USB bus registered, assigned bus number 2
[    4.835449] xhci-hcd xhci-hcd.0.auto: Host supports USB 3.0 SuperSpeed
[    4.843076] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
[    4.850136] hub 2-0:1.0: USB hub found
[    4.857896] hub 2-0:1.0: 1 port detected
[    4.861823] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
[    4.865480] xhci-hcd xhci-hcd.1.auto: new USB bus registered, assigned bus number 3
[    4.870976] xhci-hcd xhci-hcd.1.auto: hcc params 0x0220f665 hci version 0x100 quirks 0x0000000002010010
[    4.878375] xhci-hcd xhci-hcd.1.auto: irq 98, io mem 0x06000000
[    4.888506] hub 3-0:1.0: USB hub found
[    4.893604] hub 3-0:1.0: 1 port detected
[    4.897748] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
[    4.901464] xhci-hcd xhci-hcd.1.auto: new USB bus registered, assigned bus number 4
[    4.906789] xhci-hcd xhci-hcd.1.auto: Host supports USB 3.0 SuperSpeed
[    4.914425] usb usb4: We don't know the algorithms for LPM for this host, disabling LPM.
[    4.921489] hub 4-0:1.0: USB hub found
[    4.929207] hub 4-0:1.0: config failed, hub doesn't have any ports! (err -19)
[    4.935112] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[    4.946667] init: - preinit -
[    6.019484] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[    6.019608] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[    9.361313] mount_root: loading kmods from internal overlay
[    9.376307] kmodloader: loading kernel modules from //etc/modules-boot.d/*
[    9.377164] kmodloader: done loading kernel modules from //etc/modules-boot.d/*

Thanks for your kindly reply, I have been doing so already, the only thing I want is, in your example, param=somethings that from UCI config, not a constant.

Thanks for you reply, i dont want change that parameter on the fly. I just want every time system boots, it will take some value from file.
For example, I want to change the CAC time for DFS radar detection. I write the value in UCI config, and then reboot system, cfg80211 module will take that CAC time.
I have managed to do this by modifying cfg80211 module by adding a parameter, then I wrote the script in /etc/module.d/xxxx with cfg80211 CAC_TIME=10 (for example). And it works.
Now I want that the CAC time could be configured through luci pages.

Then you probably expect it to respond to changes during run time. To do that, you'd probably need to shut down the wireless subsystems, unload the modules (in the proper order), change the module parameter(s), reload the modules, then reload the wireless subsystem and network.

Except that unloading modules is not trivial...

1 Like

As others pointed out, you will probably have to reboot the system, or at least reload the modules. Can't you just write a new "/etc/modules.d/xxx" file (containing a constant value) each time the parameter is changed?

1 Like

I think this is the compromisation I can make for now...