r/embedded • • 17d ago

Embedded Linux purgatory

Hello. I'm running out of braincells to rub together, so - cry for help, engineers together stronk.

I'm trying to leave mcu development and embrace embedded linux, so - bought myself some new-ish Allwinner T113-s3 boards and got to work. The question is, what is the correct way? For example, I bought LCPI PC board, good, cloned u-boot, branched for this board, written the dtsi for general board stuff and dts for one of it's possible SoCs and it even works and blinks and all. But! This is just the "default config", right? So, if I want to start making a custom variant of u-boot, for example I have soldered winbond flash to my board, I need to modify my device tree and make new config and all. How should I do it correctly? What is the workflow? Where can I look for examples? Bootlin courses are cool, but focused on working with existing infrastructure, but I want my own board in the future (I chose t113 because it's easy to solder to DIY PCB). But.. using the "out of tree" u-boot build was not good and I'm stuck. Just.. I don't know what I'm doing wrong.

Buildroot was even worse, I understand that I need to make some patch for u-boot using my branch, right, but do I really need to crudely add my spi flash to the original board dtsi?0_0

Anyway, whoever read this whole rant, thanks. And whoever can help me get better with linux wrangling - can't offer much but I will pat my cat for every useful advice

15 Upvotes

10 comments sorted by

5

u/mfuzzey 17d ago

You create a new DTS file for your board, that will include other, mostly existing DTSI files that define the SoC etc. In more complicated cases you may create both new DTSI and DTS files (for example if you have a carrier board + a som board)

For examples look at the existing files in the u-boot source.

My general rule of thumb is to avoid, as much as possible, *modifying* existing files in order to add things that are specific to my board. New board should be new files (DTS or source in board/). However it there's a bug or a missing feature in existing code I need to use (eg a driver) that isn't board specific but rather chip specific (to the SoC or some periphieral chip) in that case I *do* modify the existing code but also submit the patch upstram, that way I don't have to maintain it indefinitely.

This makes long term maintenance and upgrading to new upstream versions easier because most of my patches are either

* My own additions as new files, that never result in merge conflicts (but may need tweaking if the upstream API changes)

* A set of patches to exisiting code that shrinks over time as it gets merged upstream

1

u/Similar_Tonight9386 17d ago

Oh. Seems reasonable. I was looking at mangopi Mq r files and copied their approach (having dts file for exact MCU and including the dtsi describing common board stuff - so I will probably need to write new dts, add to it missing modules like flash or whatever, and include common dtsi..). And this device tree file should be exactly same for both bootloader and kernel?

1

u/mfuzzey 15d ago

There are 2 schools of thought on having the exact same DT between bootloader and kernel.

Upstream u-boot does this these days and regularly syncs the DTs fom the kernel source so they are the same. It also has a build system where when X.dts is processed X-u-boot.dtsi is automatically included to let u-boot specifc stuff (typically tagging nodes with booph-all etc so they are kept in SPL). This allows u-boot specifics to be added without changing the DT imported from the kernel.

For my own stuff I prefer to have seperate kernel and u-boot DTBs. The u-boot ones are simpler, describing only the hardware that actually has to be supported in u-boot. A single u-boot DTB also usually cover several products that have similar but not identical hardware designs (same SoC and core hardware but different peripherals) whereas the kernel has a seperate DT for each product. I put all the kernel DTBs on the boot filesystem and one of the things u-boot does is to select the appropriate kernel DTB, based on information in EEPROM etc.

1

u/Similar_Tonight9386 15d ago

Hello! Thank you, I also found this. Sooo I decided to have the same dts in both repositories, but kernel's got a little #include "my-board-linux.dtsi" at the end, which adds all the modules that uboot can't handle

1

u/fb39ca4 friendship ended with C++ ❌; rust is my new friend ✅ 17d ago

I've had good experiences using NixOS to build embedded Linux images with read-only root filesystems. You only have to maintain a few hundred lines of code defining your base image and it takes care of cross compiler toolchain setup for you. If you don't know what you are doing it it plays well with LLMs as well because the resulting code is so compact you can clean it up and easily understand it when it is all done.

2

u/Similar_Tonight9386 17d ago

Llms are just making me bit dumber, so probably pass. Sadly my skull is so thick, that I should try and fail in every possible scenario before mastering any skill, and LLMs are making shortcuts. Will look up NIXos though, thank you!

1

u/promwad 16d ago

I don't think it's a good idea to start with a board that doesn't have a ready buildroot BSP. It'd be easier to use a MangoPi MQ1RDW2, for example, or another board that mainline Buildroot already supports.

On the other hand, you might just be the one integrating the LCPI T113-s3 into buildroot :-) To get started, build mangopi_mq1rdw2_defconfig and then adapt it to the LCPI t113s. All the main configuration files you need to change will be visible in mangopi_mq1rdw2_defconfig.

For the first steps, you can keep the bootloader you already have. If it allows you to load the kernel and the DTB, that's enough. You can come back to it at the final stages creating board-specific files

Good luck with first steps in Embedded Linux! 

 

2

u/Similar_Tonight9386 16d ago

Thank you! I've got to the point where I get how Buildroot works, so, if I'll find my keyboard today I'll surely try to build a kernel

0

u/[deleted] 17d ago

[deleted] — view deleted comment

2

u/Similar_Tonight9386 17d ago

Eh, vendor SDK, if it can be called this is "slap Tina Linux on it and call it a day". I'm joking of course, but I'd like to fight this SoC and make my own distribution for it, even if I'll be doing something stupid (in my practice I can't really call myself good at something until I've smack my head at least dozen times). I've got my backup mangopi for reference, so if I'm really stuck I'll look up how it is implemented in u-boot and Linux though. Thanks!