diff --git a/README.md b/README.md index 07bf426..cd30563 100644 --- a/README.md +++ b/README.md @@ -1,249 +1,93 @@ -# Buildroot for STM32MP157 +# README: Adding a Custom Package in Buildroot -This repository contains the configuration and support files for building a custom Linux system using Buildroot for the STM32MP157-DK1 development board. +This README explains how to add a custom package to **Buildroot** so it appears in **menuconfig** and is built into the target filesystem. -## 🧠 What is Buildroot? +--- -[Buildroot](https://buildroot.org) is a simple, efficient, and powerful tool to generate embedded Linux systems through cross-compilation. +## 1. Create the Package Directory -## 🧩 Board Used - -- **STM32MP157-DK1** (or any STM32MP1-based development board) -- STMicroelectronics MPU - -## πŸ“ Repository Contents - -- `configs/stm32mp157_defconfig` - Custom Buildroot configuration file -- `board/stm32mp157/` - Post-build scripts and board-specific data -- `README.md` - Project documentation - -## πŸ”§ Requirements - -- Linux build host (Ubuntu 20.04+ recommended) -- Git, build-essential, cpio, rsync, unzip, wget, gcc, make -- Python3, libncurses-dev, bc, etc. -- Internet access to download packages - -## πŸš€ Getting Started - -### 1. Clone this repo and Buildroot +Navigate to the Buildroot `package` directory and create a folder for your package: ```bash -git clone https://github.com/buildroot/buildroot.git -cd buildroot -git checkout 2024.02 # or latest stable release -cp ../stm32mp157-buildroot/configs/stm32mp157_defconfig configs/ -make stm32mp157_defconfig +cd /package +mkdir mycustompkg +cd mycustompkg ``` -## πŸ› οΈ Build the Image +--- -```bash -make -``` -## πŸ“€ Output - -```bash -output/images/ -β”œβ”€β”€ zImage # Linux kernel -β”œβ”€β”€ rootfs.ext4 # Root filesystem -β”œβ”€β”€ boot.scr # U-Boot boot script -β”œβ”€β”€ sdcard.img # Full SD card image (optional) -``` -## πŸ’½ Flash to SD Card +## 2. Create Config.in -Insert your SD card and identify the correct device path (e.g., /dev/sdX). Then flash: +Create a file named `Config.in` inside the package directory: -```bash -sudo dd if=output/images/sdcard.img of=/dev/sdX bs=1M status=progress -sync +```text +config BR2_PACKAGE_MYCUSTOMPKG + bool "mycustompkg" + help + My custom package for Buildroot ``` -## πŸš€ Boot the STM32MP157-DK1 - -1-Insert the SD card. +This allows the package to appear in Buildroot's `menuconfig`. -2-Connect the USB-to-UART or HDMI display. +--- -3-Power on the board. +## 3. Create the Build Script (`.mk`) -4-You should see Linux boot messages. +Create `mycustompkg.mk` in the same folder: -## πŸ“œ Post-Build Script +```makefile +MYCUSTOMPKG_VERSION = 1.0 +MYCUSTOMPKG_SITE = $(TOPDIR)/package/mycustompkg +MYCUSTOMPKG_LICENSE = GPL-2.0+ +MYCUSTOMPKG_LICENSE_FILES = LICENSE -You can customize the root filesystem with a post-build.sh script: - -```bash -#!/bin/sh -echo "Customizing root filesystem..." -cp /path/to/local/script.sh $TARGET_DIR/usr/local/bin/ -chmod +x $TARGET_DIR/usr/local/bin/script.sh -``` -Add this script path under System configuration β†’ Custom scripts in make menuconfig. +define MYCUSTOMPKG_BUILD_CMDS + $(MAKE) -C $(@D) +endef -## βš™οΈ Customize Your Build +define MYCUSTOMPKG_INSTALL_TARGET_CMDS + $(INSTALL) -D -m 0755 $(@D)/mycustomprog $(TARGET_DIR)/usr/bin/mycustomprog +endef -```bash -make menuconfig +$(eval $(generic-package)) ``` -Here you can: - -1-Add BusyBox utilities - -2-Enable SSH (dropbear or OpenSSH) +> Replace `mycustomprog` with your actual executable or script. -3-Add Qt, Python, Node.js, or other packages +--- -4-Modify root password and hostname +## 4. Add the Package to Buildroot Tree -5-Enable systemd or other init systems +Edit `package/Config.in` in Buildroot and add: -## πŸ§ͺ Debugging - -``` -Username: root -Password: (none) +```text +source "package/mycustompkg/Config.in" ``` -## πŸ–ΌοΈ Screenshots (Optional) +--- -``` -U-Boot 2024.01 (Apr 29 2025 - 10:00:00 +0000) - -CPU: STM32MP157C Rev.B -DRAM: 512 MiB -NAND: 0 MiB -MMC: STM32 SD/MMC: 0 -In: serial -Out: serial -Err: serial -Net: No ethernet found. -Hit any key to stop autoboot: 0 -Booting Linux... - -Starting kernel ... - -[ 0.000000] Booting Linux on physical CPU 0x0 -[ 0.000000] Linux version 6.6.9 (buildroot@localhost) ... -[ 2.123456] Freeing unused kernel memory... -[ 3.456789] Welcome to Buildroot -stm32mp157 login: root -``` -``` -Welcome to Buildroot - -stm32mp157 login: root -# uname -a -Linux buildroot 6.6.9 #1 SMP Tue Apr 29 10:00:00 UTC 2025 armv7l GNU/Linux -# df -h -Filesystem Size Used Avail Use% Mounted on -/dev/root 32M 15M 17M 47% / -tmpfs 64M 0 64M 0% /tmp -``` -## 🧩 Important make menuconfig Options for STM32MP157 +## 5. Enable the Package in Menuconfig -### 1. Target Options +```bash +make menuconfig ``` -Target Architecture β†’ ARM (little endian) -Target Architecture Variant β†’ cortex-a7 +Navigate to your section (e.g., **Target packages β†’ Custom packages**) and enable **mycustompkg**. -Target ABI β†’ EABIhf (hard float) -``` +--- -### 2. Toolchain +## 6. Build Buildroot -If you’re not using an external toolchain, use Buildroot’s: -``` -Toolchain Type β†’ Buildroot toolchain -C library β†’ glibc or musl (default: musl for size) -Enable C++ support β†’ [*] -``` -If you want to use ST's toolchain (optional): -``` -Toolchain Type β†’ External toolchain -Toolchain β†’ Custom -Path β†’ /path/to/st-toolchain -``` - -### 3. System Configuration -``` -Root password β†’ (Optional) Set to "root" or leave empty -Enable root login with password β†’ [*] -System hostname β†’ stm32mp157 -Init system β†’ busybox or systemd (default: busybox) -``` -Post-build script: - -``` -Custom scripts to run β†’ board/stm32mp157/post-build.sh -``` -### 4. Kernel -``` -Linux Kernel β†’ [*] (enable) - β†’ Kernel Version β†’ Latest stable or specific tag (e.g., 6.6.9) - β†’ Kernel configuration β†’ Use a custom defconfig (e.g., linux-headers or stm32mp1_defconfig) - β†’ Kernel binary format β†’ zImage - β†’ Device Tree β†’ [*] stm32mp157c-dk1.dtb (or your variant) - β†’ Install kernel image to /boot β†’ [*] -``` -### 5. Bootloader (U-Boot) -``` -Bootloaders β†’ U-Boot β†’ [*] - β†’ Board β†’ st/stm32mp157-dk1 - β†’ U-Boot version β†’ 2024.01 or latest - β†’ Build system β†’ Kconfig -``` -### 6. Target Packages - -Enable based on your needs. For example: -``` -Networking applications β†’ [*] dropbear (SSH server) -``` -Filesystem Tools: -``` -Filesystem utilities β†’ [*] e2fsprogs, dosfstools, mtools -``` -Languages / Runtime: -``` -Interpreter languages and scripting β†’ [*] Python 3.x, Lua -``` -Debugging tools: -``` -Debugging, profiling and benchmarking β†’ [*] strace, gdb, ltrace -``` -Other Utilities: -``` -Text editors β†’ [*] nano, vim -``` -### 7. Filesystem Images -``` -Filesystem images β†’ [*] ext2/3/4 root filesystem - β†’ ext2/3/4 variant β†’ ext4 - β†’ Journaled β†’ [ ] - β†’ Image name β†’ rootfs.ext4 -``` -If you're using an SD card image: -``` -SD card image β†’ [*] - β†’ GPT partition table β†’ [*] - β†’ Populate boot and rootfs partitions β†’ [*] -``` -### 8. Host Utilities -``` -Host utilities β†’ [*] host-genimage, host-dtc, host-pkgconf +```bash +make ``` -## πŸ™‹ Author & Credits - -Developed by Sajad Mosayebi - - -This project is inspired by the open-source STM32 ecosystem and Buildroot community. - -Buildroot: https://buildroot.org -STM32MP1 Docs: https://wiki.st.com/stm32mpu +Buildroot will build and install your package into the target root filesystem. +--- +### Notes +- Ensure your package files are in the proper directory structure (`mycustompkg/Config.in` and `mycustompkg.mk`). +- You can include source files in the same directory or point to a remote site in the `.mk` file. +- This method allows full control over building, installing, and configuring custom software in Buildroot.