0
votes

I am working on a Linux device driver for a piece of hardware that relies on some configuration specific to each implementation. On the first boot-up, we require a user-space application to generate this configuration data through a calibration process. Naturally, I would store this configuration data in a file and read this file when the driver is loaded or the hardware is configured. Reading from a file from inside kernel-space, however, is highly discouraged.

All user-space/kernel-space interaction should occur through the sysfs interface. This confuses me a little bit for two reasons:

  1. The sysfs file-system is virtual, so every time the kernel is booted, the user (or user-space application) would have to write the configuration data to the sysfs filesystem for the kernel to use it.
  2. The driver probe function is run long before a user-space application would have the the ability to write to sysfs.

Are my assumptions about sysfs correct? How would I be able to get this configuration data to the kernel without having to rely on a user-space application to write it to sysfs?

1
Could you use a user-mode helper similar to firmware loading, or abuse the firmware request interface itself? - Ian Abbott
If it would be UEFI compatible platform, you are able to use EFI variable to store it as a lot of WiFi vendors do. Also possible to load file as firmware via native API. - 0andriy

1 Answers

0
votes

If use of the ramdisk is possible in your case, you could do the configuration in some script in this ramdisk, like for example:

# insmod module.ko
# cat config.file > /sys/sys_file

Such a solution will allow you to configure quite early your kernel module.