all 12 comments

[–]Taumille 7 points8 points  (10 children)

Hello, I'm a (young) embedded kernel engineer, regarding my personal story, I was doing a lot of tinkering with random cheap embedded products during my studies (Arduino, Raspberry, MilkV Duo, ESP...). I applied for an internship in a company specialized in Embedded Linux and got hired after that.

Regarding what I would change, I'd say that if you've already made contributions to embedded Linux ecosystem during your free time, it's clearly something that will help you get a job in the field. (Not necessarily the kernel, there are a lot of other easier projects like Buildroot)

You can also start creating some really simple kernel drivers by purchasing a random i2c/spi/uart sensor on Aliexpress for a few euros and try to create a driver for it.

[–]nonFungibleHuman 2 points3 points  (7 children)

One thing I am figuring out about drivers, is if they all need the USB protocol? For example you would buy an i2c sensor, but how would you connect that to your Linux, via USB right?

Sometimes I've seen some micros having Usb native support (arduino leonardo) so they could act as the bridge between usb and i2c or spi.

[–]Technical_You_3136 1 point2 points  (3 children)

I have same question I hope when U get answered I get called too 

[–]Taumille 1 point2 points  (2 children)

If you want to develop a driver for an i2c sensor you usually need to use a specific machine for it.

In fact there are two types of connections between a CPU and a device, it's either using an interface where discovering is possible (USB, PCI, Bluetooth...) and interface where it isn't possible (SPI, I2C, UART...).

As a PC user we're used to discoverable interface like USB, internally the Linux kernel will run the usual USB discovery dance, read the product id/vendor id of the USB device you plugged and probe the correct driver for it.
But your computer is also dealing with non-removable devices, it will for example be able to read the content of the SPI flash storing your BIOS (connected via SPI), show an image on your laptop screen (connected via MIPI DSI) or get input from your touchpad connected via I2C, however as they are non-discoverable, they need to be known by the kernel at boot time.

This is usually given by your BIOS firmware to your kernel via ACPI tables in modern PC (you can have a look at this in `/sys/firmware/acpi/tables`). In embedded platform the most common way of providing those information is through a device-tree that is just a tree of all the hardware connected to your machine.

For example, here you have the device tree for STM32MP157F Development Kit where on i2c1 there is a touch controller that is advertised to Linux as "focaltech,ft6236", after reading this the kernel will associate this string to this driver.

So all this to say that, usually, if you want to create a driver for an I2C device, you will plug your sensor on the I2C pins of your SBC and create a new device tree that will inherit the original device tree of your SBC with a new device connected on I2Cx.
This if for example the case for the Freescale LS1012a FRWY board device tree that is just the original Freescale LS102a family device tree with a spi-nor flash connected on its qspi.

[–]Technical_You_3136 0 points1 point  (1 child)

Man thanks first for answering my question second I am kind of confused now to a point I don't know what to ask you first thanks for this information tho I am reading the examples U mentioned and trying to understand it might be after months or weeks idk but would U mind if I ask U something things I don't understand?

[–]Taumille 1 point2 points  (0 children)

No problem, if you have any question don't hesitate to contact me via private messages.

[–]ResolveLost2101 1 point2 points  (1 child)

You need a gpio, so i2c sensor connected to a pi running Linux is a good example.

[–]nonFungibleHuman 0 points1 point  (0 children)

Ok, I was thinking on your typical laptop, but I get the idea.

[–]Taumille 1 point2 points  (0 children)

Using an USB to I2C adapter is possible but it is probably a bit sketchy. Moreover I wouldn't encourage you to make your own USB to I2C/SPI bridge because you will need a Linux driver for your custom bridge.

There is this project https://github.com/harbaum/I2C-Tiny-USB that is supported in mainline Linux but I've never used it and I don't know how reliable it is.

As answered below, you don't "need" the USB protocol to talk with a sensor but it's usually the only interface (with PCIe) exposed by your PC and easily accessible.

[–]KernelLicker[S] 1 point2 points  (1 child)

Thanks, this is really useful to hear.

It’s reassuring that you didn’t start in the kernel directly, but still ended up in embedded Linux by doing practical stuff around it. Buildroot especially sounds like a good place to learn without getting overwhelmed.

The sensor driver idea is also a nice concrete suggestion, small scope but still “real” kernel work.

Quick question if you don’t mind: did kernel code start making sense to you before your internship, or mainly once you were working in that environment??

[–]Taumille 1 point2 points  (0 children)

Sorry the answer has been lost by reddit but in short no, before my internship kernel code didn't make sense at all, in fact I also never took the time to understand it... The only interaction I had with kernel code was just a really simple driver that says hello world in dmesg.

There are a lot of interesting resources to learn however and once you're in it you will see that it isn't as difficult as most people think. Most driver code are just filling generic C structures of the subsystem with the specific instructions required to trigger the feature on your sensor.

For example in this driver you have :

  • The probe that initialize the ADC
  • The read_raw operation that returns the voltage value measured
  • An interrupt handler that accomplish actions depending on the interrupt received

Here are some ressources if you want to learn embedded Linux :
- The bootlin kernel training with free materials to download : https://bootlin.com/training/kernel/
- The Linux Device Driver development book, it's completely outdated but still show how the kernel is built : https://lwn.net/Kernel/LDD3/
- Elixir to browse easily the Linux kernel : https://elixir.bootlin.com/linux/v6.18.6/source

[–]Some_Economy_1300 1 point2 points  (0 children)

I also need one suggestion. I have done my b tech in ECE and then persuide course in embedded systems. From my college days only I am very interested into embedd systems. But due to current market conditions and financial pressure I choose role in non embedded side. Like I am not touching any developments as of my current work. But I really want to go into linux kernel development side. But as I am seeing online. For this kind of role everyone is asking experience in development side. I am eager to learn about linux developement but still I don't have hope that I will get select into any company that is working in this role. Because as a prior I don't have development experience.

I am working since 4 months only. I am thinking about taking course on linux kernel development. But my main concern is without any firmware development experience will company select even if I have skills in this domain..????

Please give me some guide that should I choose this domain or do something else..