如何在Yocto生成的initramfs镜像中实现initramfs-tools功能
Since you can't use Debian's initramfs-tools on your ARMv6 Yocto setup, let's break down how to replicate each of your required steps using Yocto's built-in initramfs-framework-base:
1. Add an init-top Script to Load SPI Modules
Yocto's initramfs framework uses script directories similar to initramfs-tools. You'll need to create a custom script and package it into the initramfs:
Step 1: Create the SPI init-top script
Create a file named spi in recipes-core/initramfs-spi-setup/files/init-top/ with this content:
#!/bin/sh PREREQ="" prereqs() { echo "$PREREQ" } case "$1" in prereqs) prereqs exit 0 ;; esac # Load your SPI modules here (replace with your actual modules) modprobe spi-bcm2835 modprobe spidev
Make the script executable:
chmod +x recipes-core/initramfs-spi-setup/files/init-top/spi
Step 2: Create a recipe to package this script
Create recipes-core/initramfs-spi-setup/initramfs-spi-setup.bb:
SUMMARY = "SPI setup script for initramfs" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" SRC_URI = "file://init-top/spi" S = "${WORKDIR}" do_install() { install -d ${D}/usr/share/initramfs-tools/scripts/init-top install -m 0755 ${WORKDIR}/spi ${D}/usr/share/initramfs-tools/scripts/init-top/ } FILES_${PN} = "/usr/share/initramfs-tools/scripts/init-top/spi" # Ensure this is included in the initramfs IMAGE_INSTALL_append = " initramfs-spi-setup"
2. Add Modules to be Loaded by the Module Daemon
Instead of /etc/initramfs-tools/modules, Yocto uses modules-load.d configuration files to specify auto-loaded modules:
Step 1: Create a modules-load configuration file
Create recipes-core/initramfs-module-config/files/spi-modules.conf with:
# List your modules here, one per line spi-bcm2835 spidev
Step 2: Create a recipe for this config
Create recipes-core/initramfs-module-config/initramfs-module-config.bb:
SUMMARY = "Module load config for initramfs" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" SRC_URI = "file://spi-modules.conf" S = "${WORKDIR}" do_install() { install -d ${D}/etc/modules-load.d install -m 0644 ${WORKDIR}/spi-modules.conf ${D}/etc/modules-load.d/ } FILES_${PN} = "/etc/modules-load.d/spi-modules.conf" IMAGE_INSTALL_append = " initramfs-module-config"
3. Set the FRAMEBUFFER Environment Variable
To set FRAMEBUFFER=/dev/fb1 for Plymouth, add this to an initramfs startup script:
Step 1: Create a framebuffer setup script
Create recipes-core/initramfs-fb-setup/files/init-bottom/fb1 with:
#!/bin/sh PREREQ="" prereqs() { echo "$PREREQ" } case "$1" in prereqs) prereqs exit 0 ;; esac # Export the framebuffer variable for Plymouth export FRAMEBUFFER=/dev/fb1 # Persist the variable for post-initramfs use echo 'export FRAMEBUFFER=/dev/fb1' > ${ROOTFS}/etc/profile.d/fb1.sh
Make it executable:
chmod +x recipes-core/initramfs-fb-setup/files/init-bottom/fb1
Step 2: Create the recipe
Create recipes-core/initramfs-fb-setup/initramfs-fb-setup.bb:
SUMMARY = "Framebuffer setup script for initramfs" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" SRC_URI = "file://init-bottom/fb1" S = "${WORKDIR}" do_install() { install -d ${D}/usr/share/initramfs-tools/scripts/init-bottom install -m 0755 ${WORKDIR}/fb1 ${D}/usr/share/initramfs-tools/scripts/init-bottom/ # Install profile script to persist the variable install -d ${D}/etc/profile.d echo 'export FRAMEBUFFER=/dev/fb1' > ${D}/etc/profile.d/fb1.sh chmod 0644 ${D}/etc/profile.d/fb1.sh } FILES_${PN} = " \ /usr/share/initramfs-tools/scripts/init-bottom/fb1 \ /etc/profile.d/fb1.sh \ " IMAGE_INSTALL_append = " initramfs-fb-setup"
Update Your Existing Image Recipe
Modify your rpi-basic-image.bb to include these new packages:
include recipes-core/images/rpi-basic-image.bb BASEPACKS = " \ base-passwd \ busybox \ initramfs-live-boot \ initramfs-framework-base \ udev \ ${ROOTFS_BOOTSTRAP_INSTALL} \ " IMAGE_INSTALL = " \ ${BASEPACKS} \ plymouth plymouth-set-default-theme \ initramfs-spi-setup \ initramfs-module-config \ initramfs-fb-setup \ " # Do not pollute the initrd image with rootfs features IMAGE_FEATURES = "splash" SPLASH = "plymouth" IMAGE_LINGUAS = "" LICENSE = "MIT" IMAGE_FSTYPES = "${INITRAMFS_FSTYPES}" IMAGE_ROOTFS_SIZE = "8192" IMAGE_OVERHEAD_FACTOR = "1.0" IMAGE_ROOTFS_EXTRA_SPACE = "0" IMAGE_ROOTFS_MAXSIZE = "12288" CMDLINE_append = " quiet splash nomodeset plymouth.ignore-serial-consoles consoleblank=0 fbcon=map:1" # Add fbcon=map:1 to ensure console uses fb1 if needed BAD_RECOMMENDATIONS += "busybox-syslog"
Key Notes for ARMv6/U-boot
- Double-check that your kernel config enables the required SPI and framebuffer modules for ARMv6.
- For debugging, add
ls /dev/fb*to your framebuffer setup script to confirm/dev/fb1exists in the initramfs. - Ensure U-boot correctly passes your modified kernel command line to the kernel.
内容的提问来源于stack exchange,提问作者mozcelikors

