2

I'm making a hardware project that will run a GNU/Linux OS, and I have a question.(edit: it's ARM based)

How EXACTLY does the Linux kernel know what type of hardware is connected to the CPU, I mean how hoes it know that yeah this a a RAM and that is a drive ...etc.

ESPECIALLY for network interfaces, if the system has multiple Ethernet NICs and multiple WiFi transceivers how does it know which is which and how does it know how they are connected hardware-wise (maybe they are connected with multiplexer, maybe with I2C , SPI ...etc).

2
  • 1
    Your question is unclear to me, but I think one of the first things you should understand if you want to discuss the Linux kernel-to-hardware interface is the device tree. The device tree has been around for a while, so there are some references available. Here's a link to some device tree articles spanning perhaps a decade. Lots more to be had for the cost of a search.
    – Seamus
    Jul 19 at 5:32
  • quite useful, thank you a lot Jul 20 at 7:54

2 Answers 2

2

All this very low level work will of course depend on… the architecture.

For the most common (x86/IBM PC) the BIOS will help a lot for a good start. If you get one, look at your bootlog, it will start querying the BIOS :

BIOS-provided physical RAM map:

further down, you might notice something like :

BIOS-e820: [mem 0x00000000cff80000-0x00000000cff8dfff] ACPI data

which are tables provided by the BIOS on which the OS can rely in order to obtain additional infos about peripherals… (BIOSes are often known to be more or less broken on this)

On the other end you get ARM SoCs with each vendor supporting peripherals its own way (and most often as closed-source) and who, of course, never agreed on whatever BIOS equivalent. This situation led to some famous quotes from Linus Torvald :

I hope the SoC ARM designers die in an incredibly painful accident. […] Gaah, Guys this whole ARM thing is a fucking pain in the ass.

If your project is based on that sort of hardware… well… Good luck! You might well have to bruteforce on memory ranges. (Write and consider what happens)


Then come less architecture dependent information data. Those about devices standing on standard buses :

For ISA devices (nowadays mostly serial / parallel ports) you'll need to rely on some trial and error method reading a very limited number of usual port addresses to consider what it looks like.

For devices plugged into PCI buses, the PCI configuration space is a standard which enables the implementation of standard (arch independent) methods for enumerating and initializing.


In any case, if your hardware cannot rely on standardized methods for probing you will be on your own to answer your question as @telcoM suggests it :

On ARM, the standard seems to be that the designers (or reverse-engineers, as the case may be) of the hardware must describe it in the form of device tree data, which is then loaded by the hardware-specific bootloader along with the kernel file and possibly initramfs file. So if your hardware project uses an architecture that does not include a standardized, autoprobeable main bus like PCI or PCIe, then yes, you, the hardware designer will have to provide that information for the Linux kernel.

4
  • 3
    On ARM, the standard seems to be that the designers (or reverse-engineers, as the case may be) of the hardware must describe it in the form of device tree data, which is then loaded by the hardware-specific bootloader along with the kernel file and possibly initramfs file. So if your hardware project uses an architecture that does not include a standardized, autoprobeable main bus like PCI or PCIe, then yes, you, the hardware designer will have to provide that information for the Linux kernel.
    – telcoM
    Jul 17 at 12:50
  • It is ARM based, LOL, and it's a pain in the a$s. I need to know if the kernel knows how it's connected hardware-wise Jul 17 at 13:33
  • Thanks @telcoM for this valuable piece of info I just added in my answer.
    – MC68020
    Jul 17 at 13:36
  • 3
    @AbdAlhaleemBakkor : If you are working on a custom hardware project, the Linux kernel won't know more than what you will have described.
    – MC68020
    Jul 17 at 13:41
0

The x86 architecture describes standard PC components (interfaces including PCI, PCI-E, RAM, etc.) which the Linux kernel enumerates part of the boot process. Some buses allow to attach/detach devices on the fly, e.g. USB or SATA. Your question is not Linux/Unix specific.

1
  • 1
    it's ARM based (edited), so if you can provide some information about that it'd be great. also, it's linux related I think, I only care about running linux on it. Jul 17 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.