【buildroot】【2. 使用buildroot创建一个bsp工程,并在qemu中允许linux5.4x】

发布于:2025-09-05 ⋅ 阅读:(19) ⋅ 点赞:(0)

一、目标

本篇的目标是 使用 Buildroot 的 BR2_EXTERNAL 功能创建一个我们自己的 bsp 板子, 名字叫做 lotus.

使用 qemu 跑 linux5.4x

1.1 BR2_EXTERNAL 介绍

BR2_EXTERNAL 是 Buildroot 提供的一个强大机制,它允许你将自定义的配置、软件包、内核配置、板级支持等与官方的 Buildroot 代码树完全分离开。这样做的好处非常明显:

  • 隔离与维护:你的项目特定文件不会被污染,易于管理和版本控制(例如,可以放在独立的 Git 仓库中)。

  • 复用与升级:你可以轻松地切换或升级 Buildroot 的版本,而无需修改或移动你的项目文件。只需在编译时指向你的外部树路径即可。

  • 结构清晰:强制形成一个清晰、规范的项目结构。

二、创建一个lotus的工程

2.1 在git仓库里面创建项目结构

这个不用多说了, 都会哈。


git clone https://gitee.com/xxx/lotus_bsp.git

cd lotus_bsp

1. 初始化主项目 Git 仓库

# 初始化Git仓库
git init

# 创建.gitignore文件,忽略不必要的文件
cat > .gitignore << 'EOF'
# Buildroot输出目录
/buildroot/output/

# 镜像输出目录
/images/

# 编辑器文件
*.swp
*~
.*.swp
.*.un~

# 临时文件
*.tmp
*.log

# 备份文件
*.bak
*.old

# 编译生成的文件
*.o
*.a
*.so
*.d
*.deps
EOF

# 添加初始文件并提交
git add .
git commit -m "Initial commit: Lotus project structure"

2.添加 Buildroot 作为子模块

# 删除之前手动克隆的buildroot目录(如果存在)
rm -rf buildroot

# 添加Buildroot作为子模块
git submodule add https://git.buildroot.net/buildroot buildroot

# 初始化并更新子模块
git submodule update --init --recursive

3. 配置子模块相关设置

1.创建子模块配置文件
# 创建.gitmodules文件(通常由git submodule add自动生成,但我们可以自定义配置)
cat > .gitmodules << 'EOF'
[submodule "buildroot"]
	path = buildroot
	url = https://git.buildroot.net/buildroot
	branch = master
EOF
2. 创建子模块管理脚本
# 创建一个脚本用于方便地更新子模块
cat > update_submodules.sh << 'EOF'
#!/bin/bash

echo "Updating Buildroot submodule..."
git submodule update --init --recursive

echo "Checking out Buildroot stable branch..."
cd buildroot
git checkout $(git describe --tags --abbrev=0)

echo "Buildroot submodule updated to latest stable release."
EOF

chmod +x update_submodules.sh

3. 创建项目文档说明
# 创建README文件说明项目结构
cat > README.md << 'EOF'
# Lotus Project

基于Buildroot的嵌入式Linux项目。

4. 提交完成子模块配置
# 添加子模块相关文件
git add .
git add .gitmodules
git add buildroot  # 这实际上添加的是对子模块commit的引用

# 提交子模块配置
git commit -m "Add Buildroot as submodule"

4. 子模块管理

  • 更新到最新稳定版:./update_submodules.sh

  • 查看子模块状态:git submodule status

  • 更新子模块:git submodule update --remote

5.创建实用的 Git 钩子和脚本

1. 创建克隆后初始化脚本
mkdir -p scripts

cat > scripts/setup_project.sh << 'EOF'
#!/bin/bash

echo "Setting up Lotus project..."

# 确保子模块初始化
if [ ! -d "buildroot/.git" ]; then
    echo "Initializing Buildroot submodule..."
    git submodule update --init --recursive
fi

# 检查Buildroot版本
cd buildroot
BUILDROOT_VERSION=$(git describe --tags --abbrev=0)
echo "Buildroot version: $BUILDROOT_VERSION"

# 创建images目录如果不存在
cd ..
mkdir -p images

echo "Project setup complete!"
EOF

chmod +x scripts/setup_project.sh
2. 创建 Git 钩子确保子模块状态
mkdir -p .githooks

cat > .githooks/post-merge << 'EOF'
#!/bin/bash

# 在merge后自动更新子模块
echo "Updating submodules after merge..."
git submodule update --init --recursive
EOF

chmod +x .githooks/post-merge

# 配置Git使用自定义钩子目录
git config core.hooksPath .githooks

6. 创建项目结构

# 在 lotus_bsp 目录下创建
mkdir buildroot_external images

# 创建 BR2_EXTERNAL 所需的目录结构
mkdir -p buildroot_external/{board/lotus,configs,package/helloworld/src}

最终的项目结构确认

lotus_bsp/
├── .git/                      # Git仓库数据
├── .githooks/                 # Git钩子
│   └── post-merge
├── buildroot/                 # Buildroot子模块
├── buildroot_external/        # 我们的外部项目树 (BR2_EXTERNAL)
│   ├── board/lotus/           # lotus板级支持包
│   ├── configs/
│   ├── package/helloworld/    # 自定义helloworld软件包
├── images/                    # 存放最终镜像
├── scripts/                   # 实用脚本
│   └── setup_project.sh
├── .gitignore                # .gitignore忽略
├── .gitmodules 
├── README.md
└── update_submodules.sh

7. 如何使用这个仓库

1. 克隆项目(对于其他开发者)
# 递归克隆(推荐)
git clone --recursive <your-repository-url> lotus_bsp

cd lotus_bsp
# 或者如果已经克隆,初始化子模块
git submodule update --init --recursive

2. 日常开发工作流
# 1. 更新子模块到最新稳定版本
./update_submodules.sh

# 2. 进行开发修改
# 修改 buildroot_external/ 中的文件

# 3. 提交更改
git add .
git commit -m "Update lotus board configuration"

# 4. 如果需要更新Buildroot版本
cd buildroot
git checkout 2024.02.1  # 切换到特定版本
cd ..
git add buildroot
git commit -m "Update Buildroot to 2024.02.1"
3. 查看子模块状态
# 查看子模块状态
git submodule status

# 查看子模块的远程更新
cd buildroot
git fetch
git log --oneline HEAD..origin/master
cd ..
4.重要的 Git 命令参考
# 更新子模块到远程最新
git submodule update --remote

# 查看子模块差异
git diff --submodule

# 进入子模块进行开发
cd buildroot
git checkout -b feature-branch
# 进行修改...
git commit -a -m "Buildroot changes"
cd ..
git add buildroot
git commit -m "Update Buildroot submodule reference"

这样的配置确保了:

  1. 版本控制:主项目和Buildroot都有明确的版本管理

  2. 可重复构建:任何人都能获得完全相同的开发环境

  3. 易于维护:清晰的子模块管理策略

  4. 团队协作:标准的Git工作流程

8. 选择 buildroot 的版本

我们的目标是 使用 qemu 跑arm64 linux 5.4.x 的内核。

根据 Buildroot版本与Linux内核调试对应关系的介绍,我们这里选择 Buildroot 2020.02.9 版本。 根据我实际的测试发现 该版本 qemu 编译上有点问题, 但是这些问题在 2020.05.1
有解决, 所以我最终选择了 2020.05.1

leo@leo ~/data_4t/github/lotus_bsp/buildroot
$ git checkout -b 2020.05.1.local 2020.05.1

2.2 创建 helloworld 软件包

1. 编写 helloworld 程序

# 创建helloworld源码
cat > buildroot_external/package/helloworld/src/helloworld.c << 'EOF'
#include <stdio.h>

int main() {
    printf("Hello, Lotus Board!\\n");
    return 0;
}
EOF
# 创建Makefile
cat > buildroot_external/package/helloworld/src/Makefile << 'EOF'
CC=gcc
CFLAGS=-Wall

helloworld: helloworld.c
	$(CC) $(CFLAGS) -o $@ $^

clean:
	rm -f helloworld

.PHONY: clean
EOF

2. 创建软件包配置

cat > buildroot_external/package/helloworld/Config.in << 'EOF'
config BR2_PACKAGE_HELLOWORLD
	bool "helloworld"
	help
	  Simple Hello World program for Lotus board.

	  https://example.com
EOF

创建 .mk 文件:

cat > buildroot_external/package/helloworld/helloworld.mk << 'EOF'
################################################################################
#
# helloworld
#
################################################################################

HELLOWORLD_VERSION = 1.0
HELLOWORLD_SITE = $(BR2_EXTERNAL_LOTUS_PROJECT_PATH)/package/helloworld/src
HELLOWORLD_SITE_METHOD = local

define HELLOWORLD_BUILD_CMDS
	$(MAKE) CC="$(TARGET_CC)" -C $(@D)
endef

define HELLOWORLD_INSTALL_TARGET_CMDS
	$(INSTALL) -D -m 0755 $(@D)/helloworld $(TARGET_DIR)/usr/bin/helloworld
endef

$(eval $(generic-package))
EOF

2.3 创建 lotus 板级支持

1. 创建根文件系统覆盖层

# 创建根文件系统覆盖层结构
mkdir -p buildroot_external/board/lotus/rootfs_overlay/etc

# 创建一个简单的inittab确保helloworld可以运行
cat > buildroot_external/board/lotus/rootfs_overlay/etc/inittab << 'EOF'
::sysinit:/etc/init.d/rcS
::respawn:/sbin/getty -L ttyAMA0 115200 vt100
# 在启动时运行我们的helloworld程序
::once:/usr/bin/helloworld
tty1::respawn:/sbin/getty -L tty1 115200 vt100
EOF

2. 创建后处理脚本

# 创建post-image脚本,用于拷贝生成的镜像
cat > buildroot_external/board/lotus/post-image.sh << 'EOF'
#!/bin/bash

echo "Copying images to project images directory..."
cp ${BINARIES_DIR}/rootfs.tar ${BR2_EXTERNAL_LOTUS_PROJECT_PATH}/../images/lotus-rootfs.tar
cp ${BINARIES_DIR}/zImage ${BR2_EXTERNAL_LOTUS_PROJECT_PATH}/../images/lotus-zImage

echo "Lotus board images ready in ../images/"
EOF

# 给脚本执行权限
chmod +x buildroot_external/board/lotus/post-image.sh

2.3 创建 BR2_EXTERNAL 核心文件

1. 创建 external.desc

cat > buildroot_external/external.desc << 'EOF'
name: LOTUS_PROJECT
desc: Lotus Board Project
EOF

2. 创建 Config.in

cat > buildroot_external/Config.in << 'EOF'
# Main menu for Lotus project external tree

source "$BR2_EXTERNAL_LOTUS_PROJECT_PATH/package/helloworld/Config.in"

menu "Lotus Board Options"

config BR2_LOTUS_ENABLE_DEBUG
	bool "Enable debug features"
	help
	  Enable additional debug features for Lotus board.

endmenu
EOF

3. 创建 external.mk

cat > buildroot_external/external.mk << 'EOF'
# Lotus project external makefile

LOTUS_VERSION = 1.0.0

# Add global definitions here
EOF

2.4 创建 Defconfig 配置文件

vim buildroot_external/configs/lotus_defconfig

leo@leo ~/data_4t/github/lotus_bsp
$ cp buildroot/configs/qemu_aarch64_virt_defconfig  ./buildroot_external/configs/lotus_defconfig 

这里我们默认使用 qemu_aarch64_virt_defconfig 配置

另外需要选择:

# 使用我们的lotus配置
make lotus_defconfig

make menuconfig

Toolchain
	Enable C++ support

Host utilities
	host cmake

2.5 编译和运行

1. 设置环境并配置

cd ~/lotus_bsp/buildroot


# 设置BR2_EXTERNAL环境变量
export BR2_EXTERNAL=../buildroot_external

# 使用我们的lotus配置
make lotus_defconfig

2. 可选:检查配置

# 检查helloworld包是否已选中
make menuconfig

3. 开始编译

# 开始编译(使用4个线程加速)
make -j4

2.6 测试运行

编译完成后,你可以用QEMU测试(如果选择了支持QEMU的配置):

系统启动后,你应该能看到输出:

Hello, Lotus Board!

验证 helloworld 程序
在QEMU中或者在实际硬件上运行:



# 手动运行helloworld程序
helloworld
# 输出: Hello, Lotus Board!

这个完整的项目包含了:

  1. 项目结构:清晰的目录组织

  2. 自定义软件包:完整的helloworld程序包

  3. 板级支持:根文件系统覆盖层和后处理脚本

  4. 配置系统:通过defconfig整合所有配置

  5. 编译运行:完整的编译和测试流程

现在你有一个可以直接运行的基础项目框架,可以在此基础上继续开发更复杂的功能。

三、编译遇到的错解决记录

1. host-m4 1.4.18 Building

In file included from /usr/include/signal.h:328,
                 from ./signal.h:52,
                 from c-stack.c:49:
c-stack.c:55:26: error: missing binary operator before token "("
   55 | #elif HAVE_LIBSIGSEGV && SIGSTKSZ < 16384
      |                          ^~~~~~~~
  CC       fcntl.o
  CC       fflush.o
  CC       fpurge.o
  CC       freadahead.o
  CC       fseek.o
  CC       fseeko.o
  CC       mbrtowc.o
make[5]: *** [Makefile:1915: c-stack.o] Error 1
make[5]: *** Waiting for unfinished jobs....
  CC       obstack.o
make[4]: *** [Makefile:1674: all] Error 2
make[3]: *** [Makefile:1572: all-recursive] Error 1
make[2]: *** [Makefile:1528:all] 错误 2
make[1]: *** [package/pkg-generic.mk:269:/home/leo/data_4t/github/lotus_bsp/buildroot/output/build/host-m4-1.4.18/.stamp_built] 错误 2

解决办法: 将 m4 的版本升级到 1.4.19

leo@leo ~/data_4t/github/lotus_bsp/buildroot/package/m4
$ git status  .
位于分支 2020.05.1.local
尚未暂存以备提交的变更:
  (使用 "git add/rm <文件>..." 更新要提交的内容)
  (使用 "git restore <文件>..." 丢弃工作区的改动)
	删除:     0001-fflush-adjust-to-glibc-2.28-libio.h-removal.patch
	删除:     0002-fflush-be-more-paranoid-about-libio.h-change.patch
	修改:     m4.hash
	修改:     m4.mk
diff --git a/package/m4/m4.hash b/package/m4/m4.hash
index e665fc149f..27f4cffa3d 100644
--- a/package/m4/m4.hash
+++ b/package/m4/m4.hash
@@ -1,4 +1,7 @@
 # Locally calculated after checking pgp signature
 sha256 f2c1e86ca0a404ff281631bdc8377638992744b175afb806e25871a24a934e07        m4-1.4.18.tar.xz
+
+sha256  63aede5c6d33b6d9b13511cd0be2cac046f2e70fd0a07aa9573a04a82783af96        m4-1.4.19.tar.xz
+
 # License files, locally calculated
 sha256 8ceb4b9ee5adedde47b31e975c1d90c73ad27b6b165a1dcd80c7c545eb65b903        COPYING
diff --git a/package/m4/m4.mk b/package/m4/m4.mk
index 849e7f4a54..3a12092971 100644
--- a/package/m4/m4.mk
+++ b/package/m4/m4.mk
@@ -4,7 +4,7 @@
 #
 ################################################################################
 
-M4_VERSION = 1.4.18
+M4_VERSION = 1.4.19
 M4_SOURCE = m4-$(M4_VERSION).tar.xz
 M4_SITE = $(BR2_GNU_MIRROR)/m4
 M4_LICENSE = GPL-3.0+

2. host-fakeroot-1.20.2

libfakeroot.c: In function ‘fremovexattr’:
libfakeroot.c:101:42: error: ‘_STAT_VER’ undeclared (first use in this function)
  101 | #define INT_NEXT_FSTAT(a,b) NEXT_FSTAT64(_STAT_VER,a,b)


libtool: link: /usr/bin/ranlib .libs/libmacosx.a
make[4]: *** [Makefile:652:libfakeroot.lo] 错误 1
make[4]: *** 正在等待未完成的任务....
libtool: link: ( cd ".libs" && rm -f "libmacosx.la" && ln -s "../libmacosx.la" "libmacosx.la" )
make[3]: *** [Makefile:670:all-recursive] 错误 1
make[2]: *** [Makefile:445:all] 错误 2
make[1]: *** [package/pkg-generic.mk:269:/home/leo/data_4t/github/lotus_bsp/buildroot/output/build/host-fakeroot-1.20.2/.stamp_built] 错误 2
make: *** [Makefile:84:_all] 错误 2

修复:

  • 0005.fix-glibc-compatibility.patch
leo@leo ~/data_4t/github/lotus_bsp/buildroot/package/fakeroot
$ cat 0005.fix-glibc-compatibility.patch

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Your Name <your.email@example.com>
Date: 四, 28 82025 18:37:33 +0800
Subject: [PATCH] Fix _STAT_VER undefined error for glibc compatibility

This patch resolves compilation issues with newer glibc versions
by providing proper _STAT_VER definitions based on architecture.

Signed-off-by: Your Name <your.email@example.com>
---
--- host-fakeroot-1.20.2.org/libfakeroot.c	2025-08-28 18:34:33.752845811 +0800
+++ host-fakeroot-1.20.2/libfakeroot.c	2025-08-28 18:36:52.640434605 +0800
@@ -59,6 +59,14 @@
 #include "config.h"
 #include "communicate.h"
 
+#ifndef _STAT_VER
+#if defined(__x86_64__)
+#define _STAT_VER 1
+#else
+#define _STAT_VER 0
+#endif
+#endif
+
 #ifdef __APPLE__
 /* The *xattr functions are currently disabled on __APPLE__ since the prototypes
    are all different from the Linux versions and there is, as of yet, no
-- 
2.25.1

rm output/build/host-fakeroot-1.20.2 -rf

make -j 40

3.host-qemu-4.2.0/

make[3]: 对“all”无需做任何事。
  AR      libvhost-user.a
  LINK    qemu-ga
  BUILD   pc-bios/optionrom/multiboot.img
  BUILD   pc-bios/optionrom/linuxboot.img
  BUILD   pc-bios/optionrom/linuxboot_dma.img
  BUILD   pc-bios/optionrom/kvmvapic.img
  BUILD   pc-bios/optionrom/pvh.img
/usr/bin/ld: Error: unable to disambiguate: -nopie (did you mean --nopie ?)
/usr/bin/ld: Error: unable to disambiguate: -nopie (did you mean --nopie ?)
/usr/bin/ld: Error: unable to disambiguate: -nopie (did you mean --nopie ?)
make[3]: *** [Makefile:53:linuxboot.img] 错误 1
/usr/bin/ld: Error: unable to disambiguate: -nopie (did you mean -make[3]: *** 正在等待未完成的任务....
-nopie ?)
make[3]: *** [Makefile:53:linuxboot_dma.img] 错误 1
make[3]: *** [Makefile:53:multiboot.img] 错误 1
make[3]: *** [Makefile:53:kvmvapic.img] 错误 1
/usr/bin/ld: Error: unable to disambiguate: -nopie (did you mean --nopie ?)
make[3]: *** [Makefile:50:pvh.img] 错误 1
make[2]: *** [Makefile:542:pc-bios/optionrom/all] 错误 2
make[2]: *** 正在等待未完成的任务....
make[1]: *** [package/pkg-generic.mk:269:/home/leo/data_4t/github/lotus_bsp/buildroot/output/build/host-qemu-4.2.0/.stamp_built] 错误 2
make: *** [Makefile:84:_all] 错误 2

修复:

package/qemu/0004-fix.patch

commit 131775d189ea7e6bbb44dc69b0937a8f0915dea7 (HEAD -> master)
Author: lotus <lotus@lotus.email.co>
Date:   Mon Sep 1 15:45:49 2025 +0800

    fix qemu.
    
    Signed-off-by: lotus <lotus@lotus.email.co>

diff --git a/configure b/configure
index 6099be1d..77ce0100 100755
--- a/configure
+++ b/configure
@@ -2045,7 +2045,6 @@ EOF
   # check we support --no-pie first...
   if compile_prog "-Werror -fno-pie" "-no-pie"; then
     CFLAGS_NOPIE="-fno-pie"
-    LDFLAGS_NOPIE="-nopie"
   fi
 
   if compile_prog "-fPIE -DPIE" "-pie"; then
diff --git a/roms/ipxe/src/arch/i386/Makefile b/roms/ipxe/src/arch/i386/Makefile
index b7c2792d..035ebfbd 100644
--- a/roms/ipxe/src/arch/i386/Makefile
+++ b/roms/ipxe/src/arch/i386/Makefile
@@ -80,8 +80,8 @@ CFLAGS                        += -Ui386
 ifeq ($(CCTYPE),gcc)
 PIE_TEST = [ -z "`$(CC) -fno-PIE -no-pie -x c -c /dev/null -o /dev/null 2>&1`" ]
 PIE_FLAGS := $(shell $(PIE_TEST) && $(ECHO) '-fno-PIE -no-pie')
-PIE_TEST2 = [ -z "`$(CC) -fno-PIE -nopie -x c -c /dev/null -o /dev/null 2>&1`" ]
-PIE_FLAGS2 := $(shell $(PIE_TEST2) && $(ECHO) '-fno-PIE -nopie')
+PIE_TEST2 = [ -z "`$(CC) -fno-PIE -x c -c /dev/null -o /dev/null 2>&1`" ]
+PIE_FLAGS2 := $(shell $(PIE_TEST2) && $(ECHO) '-fno-PIE')
 WORKAROUND_CFLAGS += $(PIE_FLAGS) $(PIE_FLAGS2)
 endif
 
diff --git a/roms/seabios-hppa/Makefile b/roms/seabios-hppa/Makefile
index 01f4bba0..4de4ec21 100644
--- a/roms/seabios-hppa/Makefile
+++ b/roms/seabios-hppa/Makefile
@@ -63,7 +63,6 @@ COMMONCFLAGS := -I$(OUT) -Isrc -Os -MD -g \
     -minline-all-stringops -fomit-frame-pointer \
     -freg-struct-return -ffreestanding -fno-delete-null-pointer-checks \
     -ffunction-sections -fdata-sections -fno-common -fno-merge-constants
-COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
 COMMONCFLAGS += $(call cc-option,$(CC),-fno-pie,)
 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
diff --git a/roms/seabios-hppa/Makefile.parisc b/roms/seabios-hppa/Makefile.parisc
index bc52737a..f933221e 100644
--- a/roms/seabios-hppa/Makefile.parisc
+++ b/roms/seabios-hppa/Makefile.parisc
@@ -74,7 +74,6 @@ COMMONCFLAGS := -I$(OUT) -Isrc -Ivgasrc -Os -MD -g \
     -freg-struct-return -ffreestanding -fno-delete-null-pointer-checks \
     -fdata-sections -fno-common -fno-merge-constants -mdisable-fpregs \
     -fno-builtin-printf
-COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
 COMMONCFLAGS += $(call cc-option,$(CC),-fno-pie,)
 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
diff --git a/roms/seabios/Makefile b/roms/seabios/Makefile
index 5f7d5370..a80e1e40 100644
--- a/roms/seabios/Makefile
+++ b/roms/seabios/Makefile
@@ -63,7 +63,6 @@ COMMONCFLAGS := -I$(OUT) -Isrc -Os -MD -g \
     -minline-all-stringops -fomit-frame-pointer \
     -freg-struct-return -ffreestanding -fno-delete-null-pointer-checks \
     -ffunction-sections -fdata-sections -fno-common -fno-merge-constants
-COMMONCFLAGS += $(call cc-option,$(CC),-nopie,)
 COMMONCFLAGS += $(call cc-option,$(CC),-fno-pie,)
 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
 COMMONCFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)


4. host-systemd 245.5

n file included from ../src/basic/arphrd-list.c:12:
src/basic/arphrd-from-name.gperf: In function ‘lookup_arphrd’:
src/basic/arphrd-from-name.gperf:63:16: error: ‘ARPHRD_MCTP’ undeclared (first use in this function); did you mean ‘ARPHRD_FCPP’?
   63 | MCTP, ARPHRD_MCTP
      |                ^~         
      |                ARPHRD_FCPP
src/basic/arphrd-from-name.gperf:63:16: note: each undeclared identifier is reported only once for each function it appears in
In file included from ../src/basic/arphrd-list.c:13:
src/basic/arphrd-to-name.h: In function ‘arphrd_to_name’:
src/basic/arphrd-to-name.h:56:14: error: ‘ARPHRD_MCTP’ undeclared (first use in this function); did you mean ‘ARPHRD_FCPP’?
   56 |         case ARPHRD_MCTP: return "MCTP";
      |              ^~~~~~~~~~~
      |              ARPHRD_FCPP
[103/644] Compiling C object 'src/libsystemd/7253779@@systemd_static@sta/sd-event_sd-event.c.o'
ninja: build stopped: subcommand failed.
make[1]: *** [package/pkg-generic.mk:269:/home/leo/data_4t/github/lotus_bsp/buildroot/output/build/host-systemd-245.5/.stamp_built] 错误 1
make: *** [Makefile:84:_all] 错误 2

解决:

package/systemd/0006.fix.systemd.patch

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: lotus <lotus@example.com>
Date: 一, 01 9月 2025 16:39:03 +0800
Subject: [PATCH] xxxxxxxxxxxxxxxxxxx

This patch resolves compilation issues with newer glibc versions
by providing proper _STAT_VER definitions based on architecture.

Signed-off-by: lotus <lotus@example.com>
---
--- host-systemd-245.5.org/src/basic/arphrd-list.h	2025-09-01 16:37:06.460601180 +0800
+++ host-systemd-245.5/src/basic/arphrd-list.h	2025-09-01 16:37:37.296712864 +0800
@@ -3,3 +3,7 @@
 
 const char *arphrd_to_name(int id);
 int arphrd_from_name(const char *name);
+
+#ifndef ARPHRD_MCTP
+#define ARPHRD_MCTP 45
+#endif
-- 
2.25.1