From the course: Linux Device Drivers: Reading, Writing, and Debugging

Solution: Work with loadable modules

(upbeat music) - [Instructor] Let's talk about some solutions or answers for these challenges. First one was, can an ethernet driver be a loadable kernel module? It can, and it frequently is built that way, but it can't be if you need the ethernet driver at the beginning. And a case is if you're using an NFS root file system instead of initramf or something, it is possible to boot a Linux kernel where its file system comes from the network. Well, you can't go out on the network to get your ethernet driver, all right. So that's a common case during embedded Linux development, little devices and stuff, but for desktops and servers, they're usually modules. Number two, can support for the initial RAM file system image be a loadable module? Well, it turns out, no. It's not a tri-state variable, for one thing. You either you have support or you don't. Can't even make it a module. And it doesn't even make sense to make it a module because the initial RAM file system is only used at the beginning of boot time. Number three, what are the steps in being able to use a loadable kernel module after editing one of its source files like you're doing development? Well, you need to rebuild the loadable module. You need to make the .ko file. If you're trying to get that installed and work from the lib modules directory, then you could do a make modules_install to put it up there and get debtmod to run again. So you've made a change. It was already being used presumably, so you rmmod it, and then you insert the new one either with insmod or modprobe depending on how you did that. Number four, what are the steps in being able to use a static kernel module after editing one of its source files? So this is in the kernel source tree. That's the only place these could be. You don't need to make modules. You just need to make the new kernel, like make bzImage, 'cause that's when it'll compile the parts that need to be statically linked in. And then you can update the kernel in your boot directory with make install and then reboot and then boot your kernel. Number five, how many modules are currently dynamically loaded in your kernel? We'll do an lsmod, pipe it into wc -l and subtract one. The minus one is because lsmod produces a header line. And number six, what are the module parameters for the module bluetooth? Well, modinfo -p bluetooth will list what they are. If you do have the bluetooth module loaded, what are the values of its parameters? Well, you can cat 'em all from /sys/module/bluetooth/parameters/*. Let's just take a quick look at the bluetooth. So if we do modinfo -p bluetooth, we see it has three parameters. If we change directory to /sys/module/bluetooth/parameters/ and we do a list, there they are. If we cat 'em all, we see, no, no, yes. There you go. I hope you had great success with those.

Contents