Skip to content
Skills Library
Programming · Building & coding

embedded-linux-patterns

/embedded-linux-patterns

Embedded Linux patterns: Yocto layer and recipe hierarchy, kernel config fragments, device tree GPIO and interrupt properties, out-of-tree module Makefiles, sysfs attributes, and QEMU testing before hardware. Use when customizing a Linux image or writing a driver for an ARM board.

Licence
MIT
Last repository change
09.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 09.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Embedded Linux patterns: Yocto layer and recipe hierarchy, kernel config fragments, device tree GPIO and interrupt properties, out-of-tree module Makefiles, sysfs attributes, and QEMU testing before hardware. Use when customizing a Linux image or writing a driver for an ARM board.

Original author description

Embedded Linux patterns: Yocto layer and recipe hierarchy, kernel config fragments, device tree GPIO and interrupt properties, out-of-tree module Makefiles, sysfs attributes, and QEMU testing before hardware. Use when customizing a Linux image or writing a driver for an ARM board.

How it works

  1. Knowledge Base
  2. Pattern 1: Yocto Layer and Recipe Hierarchy
  3. Pattern 2: Kernel Configuration Fragment
  4. Pattern 3: Device Tree GPIO and Interrupt Properties
  5. Pattern 4: Kernel Module Makefile
  6. Pattern 5: Sysfs Attribute in Kernel Driver
  7. Pattern 6: QEMU Testing Before Hardware
  8. Anti-Patterns
  9. References
Original SKILL.md headings · 171 lines, 556 words
SKILL.md preview
---
name: "embedded-linux-patterns"
description: "Embedded Linux patterns: Yocto layer and recipe hierarchy, kernel config fragments, device tree GPIO and interrupt properties, out-of-tree module Makefiles, sysfs attributes, and QEMU testing before hardware. Use when customizing a Linux image or writing a driver for an ARM board."
---

# embedded-linux-patterns

## Knowledge Base

Patterns for Yocto, Buildroot, device trees, and kernel modules on ARM SoCs.

---

## Pattern 1: Yocto Layer and Recipe Hierarchy

```
Layers (priority, low to high):
  poky/meta                   # Core: glibc, busybox, gcc toolchain
  poky/meta-poky              # Poky distribution configuration
  meta-openembedded/meta-oe   # Extended packages (Python, Qt, etc.)
  meta-raspberrypi            # BSP: kernel, u-boot, machine configs
  meta-myproject              # Project-specific: your app, config
```

`bblayers.conf` adds layers. `local.conf` sets `MACHINE`, `DISTRO`, and `BB_NUMBER_THREADS`.

```bash
# Common BitBake operations:
bitbake core-image-minimal          # Build minimal console image
bitbake -s | grep myapp             # Check recipe is found
bitbake myapp -c cleanall && bitbake myapp  # Rebuild from scratch
bitbake myapp -e | grep ^S=         # Show S (source dir) variable
devtool modify myapp                # Unpack source for development
devtool finish myapp meta-myproject # Write changes back to recipe
```

---

## Pattern 2: Kernel Configuration Fragment

Instead of editing `.config` directly, use a config fragment in a `.bbappend`:

```bitbake
# meta-myproject/recipes-kernel/linux/linux-%.bbappend
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI += "file://my-features.cfg"
```

```
# files/my-features.cfg
CONFIG_CAN=y
CONFIG_CAN_RAW=y
CONFIG_SPI=y
CONFIG_SPI_SPIDEV=y
CONFIG_I2C_CHARDEV=y
# CONFIG_MODULES is not set   ← explicit disable
```

Apply with: `bitbake linux-imx -c menuconfig` then `bitbake linux-imx -c savedefconfig`.

---

## Pattern 3: Device Tree GPIO and Interrupt Properties

```dts
/* GPIO: <&gpioN pin_num active_level> */
/* IRQ:  <&intc GIC_SPI irq_num IRQ_TYPE_EDGE_RISING> */

mysensor@48 {
    compatible = "ti,ads1115";
    reg = <0x48>;

    /* Active-low interrupt from sensor, connected to PA3 */
    interrupt-parent = <&gpioa>;
    interrupts = <3 IRQ_TYPE_EDGE_FALLING>;

    /* Reset GPIO: active low, initially deasserted */
    reset-gpios = <&gpiob 5 GPIO_ACTIVE_LOW>;
};
```

Kernel driver reads: `gpiod_get(dev, "reset", GPIOD_OUT_HIGH)` — matches `reset-gpios` property.
IRQ: `platform_get_irq(pdev, 0)` or `irq_of_parse_and_map(np, 0)`.

---

## Pattern 4: Kernel Module Makefile

```makefile
# Makefile for out-of-tree kernel module
KDIR ?= /lib/modules/$(shell uname -r)/build

obj-m += mydriver.o
mydriver-objs := mydriver_core.o mydriver_spi.o

all:
	$(MAKE) -C $(KDIR) M=$(PWD) modules

clean:
	$(MAKE) -C $(KDIR) M=$(PWD) clean

# Cross-compile:
# make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- KDIR=/path/to/kernel
```

---

## Pattern 5: Sysfs Attribute in Kernel Driver

Expose sensor data via `/sys/bus/platform/devices/mydev/temperature`:

```c
static ssize_t temperature_show(struct device *dev,
                                 struct device_attribute *attr, char *buf)
{
    struct mydev_priv *priv = dev_get_drvdata(dev);
    int32_t temp_mC = mydev_read_temperature(priv);
    return sysfs_emit(buf, "%d\n", temp_mC);
}
static DEVICE_ATTR_RO(temperature);

static struct attribute *mydev_attrs[] = {
    &dev_attr_temperature.attr,
    NULL,
};
ATTRIBUTE_GROUPS(mydev);

/* Add to platform_driver: */
.driver = {
    .name        = "mydev",
    .dev_groups  = mydev_groups,
    .of_match_table = mydev_of_match,
},
```

Read from userspace: `cat /sys/bus/platform/devices/mydev.0/temperature`

---

## Pattern 6: QEMU Testing Before Hardware

```bash
# Test ARM userspace binary on x86 host (requires binfmt_misc + qemu-user)
apt install qemu-user-static
qemu-arm-static -L /usr/arm-linux-gnueabihf ./myapp

# Full system emulation with Yocto image:
runqemu qemuarm nographic core-image-minimal

# Boot custom kernel + rootfs:
qemu-system-arm \
  -M virt -cpu cortex-a15 \
  -kernel zImage \
  -dtb virt.dtb \
  -initrd rootfs.cpio.gz \
  -append "console=ttyAMA0 root=/dev/ram" \
  -nographic
```

---

## Anti-Patterns

- **Editing `.config` directly in Yocto**: it gets overwritten on next build. Use config fragments.
- **`compatible = "linux,generic-..."` in DTS**: use a specific compatible string matching your driver's `of_match_table`.
- **Kernel module without `devm_` APIs**: manual resource management leaks on error paths in `probe`.
- **Cross-compiling without sysroot**: linking against host libraries causes ABI mismatch. Always use `--sysroot` or Yocto SDK.

## References

- Yocto Project Reference Manual: docs.yoctoproject.org
- Linux Device Drivers, 3rd Ed. (Corbet, Rubini, Hartman) — ldd3
- Device Tree specification: devicetree.org/specifications/
- U-Boot documentation: u-boot.readthedocs.io

Versions

The database has no other skills named embedded-linux-patterns.

Database snapshot: 13.11.2026 · package version de4ad4b541dc (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100qemu-for-kernel-development
    QEMU kernel development skill for driver and kernel testing. Use when booting custom kernels in QEMU, Buildroot/Yocto rootfs, virtio devices, or NFS root for driver iteration. Activates on queries about QEMU kernel dev, Buildroot QEMU, virtio block, kernel module test QEMU, or -append root=
  • 90embedded-linux
    Use when controlling, testing, inspecting, or debugging network-connected embedded Linux boards (ARM, ARM64, RISC-V, Buildroot, Yocto, OpenWrt, BusyBox/Dropbear) via the embedded-linux-mcp server or SSH.
  • 100qemu-for-kernel-development
    Use when booting custom kernels in QEMU, building Buildroot or Yocto rootfs, attaching virtio devices, or iterating kernel modules over NFS or 9p root. Not for KVM management: use qemu-kvm.
  • 100linux-kernel-module-development
    Develop production-grade Linux Kernel Modules (LKM), character device drivers (`cdev`), and hardware control abstractions in C. Implement file operations (`open`, `read`, `write`, `unlocked_ioctl`), kernel memory allocators (`kmalloc`, `vmalloc`), spinlocks, mutexes, interrupt…
  • 100platform-device-model
    Platform device model skill for Linux driver binding. Use when implementing platform_driver probe/remove, sysfs attributes, device properties, or deferred probe. Activates on queries about platform_device, platform_driver, driver model, sysfs, probe remove, or Linux device bus.
  • 100raspberry-pi-rust-embedded
    Production-grade embedded Rust guidelines for Raspberry Pi (bare-metal no_std and Linux embedded std/rppal/embedded-hal). Use when developing low-latency hardware control apps, embedded Rust drivers, Linux GPIO/SPI/I2C/UART software, real-time interrupt handlers, and memory-safe…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.