Is af_packet.ko supposed to automatically load? - linux

I had an issue with trying to get the wpa_supplicant to run on board running a custom Embedded Linux distribution. After some debugging it turned out that it was because the domain type PF_PACKET was not supported by the kernel:
drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
This is supported by the af_packet module and loading it beforehand fixed the problem. I noticed that it also has the alias "pf-net-17" and it appears that the kernel can load this module at runtime if requested from user-space via the alias. I tested this in another Embedded Linux distribution and sure enough this seems to be the case. It was loaded after the supplicant was called.
Does anyone know why this functionality is not working in the first setup? Maybe I missed a kernel setting?

There are basically 2 reasons why this worked on another system and not on your board:
the PF_PACKET was configured to be built in the kernel or not as a module.
The af_packet module was automatically loaded at runtime, either as a dependancy to another module or as a module to be automatically loaded at boot
I suggest that you read this document about module loading which is quite concise, yet complete and precise.
A way to fix your problem would be to make sure that depmod was run for your target system so that the module dependancy for your build is updated of load the af_packet module automatically at boot.
Another place to look at is udev, which is meant to load modules according to the devices detected by the kernel. Maybe this is also missing/misconfigured in your system.

Related

How can I build u-boot and OpenWRT so that they are ready for production?

EDIT: As stated in the comments, the question seems too broad to answer, so I'll leave the explanation of the problem and the questions, because they haven't changed, but I have changed the title (it doesn't seem good yet, but it's better than before) so they are more in tune.
What lead me to the question
I want to compile OpenWRT for my board. At the moment I am compiling it to a beagle bone black, and it's quite straight forward since there are tutorials available for that, but it got me thinking. How would I build it for a completely bare board? Like it or not BBB comes with u-boot and a version of linux (Amstrong if I'm not mistaken) so when I build OpenWRT for it maybe many things have already been taken care of for me.
I know that I need to first set up the board to boot from somehere, then it must have the bootloader and finally the kernel (there is the SPL and all that, but ok, let' leave it aside for now).
Hypothetical system
Let's imagine I have a hardware similar to the beaglebone, except it has a dipswitch connected to the boot pins in order to select from where I'm going to boot my device from. Imagine I have set it to boot from ethernet, which means that on startup a bootloader located in ROM will receive a binary file and store it in flash, all that via TFTP.
The questions
At this point I imagine that the binary file given via TFTP is the bootloader, am I right?
So after that I'd need to give the bootloader the kernel?
Does this mean that it is a 2 step process? First load the bootloader an dthen the kernel?
Is it possible to compile both at the same time and load it into the microprocessor?
Does OpenWRT build u-boot as well or do I need to compile it separately? I know it downloads the kernel and compiles it.
How would I build this for production? Imagining that I have to build u-boot and openwrt separately, would I create a script that compiles both and then does the entire process of downloading it into the microprocessor?
Is it possible to pre-configure the kernel so that it doesn't need to be configured after the code is downloaded? I mean, for example, compile it with initialization scripts instead of connecting to the device and configuring this. Is it possible or do I have to connect to the board and configure it manually?
PS: Sorry for such basic questions, but it's my first time compiling the kernel for real, and I've only worked with microcontrollers and RTOSs at most
Let's try to answer the queries one by one
At this point I imagine that the binary file given via TFTP is the bootloader, am I right?
No, It should be the firmware(kernel+HLOS). TFTP is available in uboot or only after SBL(Secondary boot loader) is loaded into memory.
So after that I'd need to give the bootloader the kernel?
bootloader needs to be present in the memory and if required it can get the firmware from ethernet, This can be simply done by changing the uboot env(bootcmd), can also be configured at compile time.
Does this mean that it is a 2 step process? First load the bootloader an dthen the kernel?
Yes, bootloader needs to be loaded earlier, but if you designing a custom board, you can combine the images in a big file and then flash/load that file at once.
Is it possible to compile both at the same time and load it into the microprocessor?
Does OpenWRT build u-boot as well or do I need to compile it separately? I know it downloads the kernel and compiles it.
Yes, Openwrt is very flexible and it compiling uboot, kernel, userspace package at once and create a desired image(based upon user configuration).
How would I build this for production? Imagining that I have to build u-boot and openwrt separately, would I create a script that compiles both and then does the entire process of downloading it into the microprocessor?
You can configure the openwrt to generate the appropriate image(based upon the flash and system requirement) and then flash that image in production(so, simple).
Is it possible to pre-configure the kernel so that it doesn't need to be configured after the code is downloaded? I mean, for example, compile it with initialization scripts instead of connecting to the device and configuring this. Is it possible or do I have to connect to the board and configure it manually?
Yes, use make kernel_menuconfig to configure the kernel parameter at compile time.
Hope, I have answered all the queries!!!

How to make a built-in device driver in linux

I know how to make loadable kernel modules in Linux.
But i want that loadable kernel module to be a part of the kernel , and after booting that driver should automatically load, like most of the other general driver.
How to do that?
There are two ways to do for your query
1) building your module as statically compiled along with kernel(your source code should reside in kernel tree ),so while building build it static which come as a part of kernel,
so when kernel boots your module will be loaded.
2)Same as above but while building build as dynamic loadable module so that wheneever required you can load it.
to illustrate above concept you can try below link for simple helloworld example.
http://www.agusbj.staff.ugm.ac.id/abjfile/Chap8.pdf
You have to configure modprobe to load automatically driver after kernel boot. Here an example of configuration.
If you want to a built-in module, you must re-compile the kernel, and set Y in the configuration file on all modules that you want inside the kernel

Inspecting variables of a running Linux kernel module

I have a crashed Linux system, where a special kernel module is loaded that does not respond to its assigned interrupt anymore. Is it possible to access the Internals of that specific module to see what has happened? Can it be done in a running system or do I need to modify the kernel, the module? Any hints are welcome.

Using lirc for arm cortex A8

Neaded your help on lirc.
I want to use lirc for decoding of ir signals. I am using a custom board based on Cortex A8 with 2.6.37 kernel and IR is received thru’ serial port. I can see UART interrupts coming properly when I press the button of the IR remote.
But when I try to run the configure script with device=all or device=serial and run make and make install as mentioned in the installation page on lirc.org, It sends me an error that the kernel configuration is invalid.
But still I am able to generate the .ko files(lirc_dev and lirc_serial) needed for loading the kernel modules but not able to insert lirc_serial module as I am using a port having mmio and the port used by lirc is io mapped.
My virtual adddress is 0xfa022000 and physical address is 0x48022000(using ttyO1).
Can I use lirc for this address.
Do I need to make any change in the code?
Also I cannot install directly on the board I am using as I could not build the kernel source code on the board due to minimal things present on the board.So am running the setup on some other machine and cross compiling for arm.
So I could not have the configuration files placed at the right locations also the node(/dev/lirc0) is not made.
Shall I make the node manually or will inserting the modules do the work?
Also do I need to have the configuration files at proper location before inserting the modules?
Also does it have any dependency with the kernel version?
Please suggest me the steps for cross compiling and loading the kernel modules on my own and also let me know which all conf files or other files are required to be present for making the things work.
I would really be very thankful to you for the help.
I have been trying it for the past 2 weeks.
Regards
Harman.
/dev/lirc0 should be created automatically if lirc_serial is loaded successfully. If it's not created, module was not loaded correctly.
lirc_serial does work with mmio - see 'iommap' module's param. You'll need to set it to 1 for mmio to work.
You'll also need to use 'io' and 'irq' params to setup your address and irq.
I'm using UDOO board with Cortex A9 CPU and could get my mmio and irq information from /proc/tty/driver/IMX-uart.
My kernel is newer though - it's 3.0.35 and I'm not sure if all of that will work in your case.
I was eventually able to load lirc_serial, but it still didn't work, so I had to connect my IR receiver directly to GPIO and write my own kernel driver based on lirc_rpi to make it working: http://funny-embeddings.blogspot.com/2013/12/udoo-adding-ir-and-building-lirc-kernel.html

Profiling Linux Kernel Modules

I am interested in profiling a module for the Linux Kernel. I tried it this way:
Built the kernel with CONFIG_PROFILING=y
Booted the kernel with profile=2
Reset the profiler by echo 123 > /proc/profile
The module was successfully loaded by a dedicated daemon
Run a user-space app that is using the module through specific ioctl calls. The test app worked as expected so the module was working OK.
Read the profiling info using readprofile -p /proc/profile -m System.map where System.app was generated along with the kernel.
So far, so good. Almost everything worked as expected. What did not work however, is that I didn't get any info about my module, i.e. there was no mention of any function from the module.
However, on second thoughts, I remebered that I forgot to recompile the module using the CONFIG_PROFILING=y.
So, my question is: Did the module not show up in the profiling log because it had not been compiled with the CONFIG_PROFILING=y or is there some other more obvious reason that I don't know of?
If one wonders, why I am asking rather than trying it straight away, that is because, I can't do it at home and I'd rather like to hear what the knowledgable would say before I get access to the code again.
It doesn't seem possible for modules to be profiled in this way as they are loaded dynamically, which means that they are missing from the System.map file.
A solution would be to build the driver into the kernel. Unfortunately, this does not always work as the system may be designed to run only with the driver built into a module.
I suggest that using oprofile should work.

Resources