buildrootでlvgl

# 目的

組み込み(arm linux)環境でlvglを使用したアプリを作成する

# 確認環境

- fedora(rawhide:20250304) + xfce
- qemu 9.2.0

## buildroot

lvglが作成している[buildroot](https://github.com/lvgl/lv_buildroot.git)があるのでそれを使用した

動作確認した commit id は以下
`00060bf86143fac7ad8a2cc2d2f0ff95eb28b149`

# 手順

基本的には [公式](https://docs.lvgl.io/master/details/integration/os/buildroot/quick_setup.html)の通り

ただし、こちらの環境だとビルドエラーになったりしたのでその回避方法など含めて記載

```shell
git clone --depth=1 --recursive https://github.com/lvgl/lv_buildroot.git
cd lv_buildroot
```

以下のpatchを適当な名前(例えば `fix_overlay.patch` など)で保存

<details><summary>fix_overlay.patch</summary>


```diff
diff --git a/build.sh b/build.sh
index 2abf422..535d122 100755
--- a/build.sh
+++ b/build.sh
@@ -7,4 +7,4 @@ cd buildroot
 make defconfig O=../output BR2_DEFCONFIG=../resources/configs/raspberrypi4_lvgl_defconfig
 
 cd ../output
-make
+make V=1
Submodule buildroot contains modified content
diff --git a/buildroot/linux/linux.hash b/buildroot/linux/linux.hash
index ffc25f7959..81a55e6525 100644
--- a/buildroot/linux/linux.hash
+++ b/buildroot/linux/linux.hash
@@ -16,3 +16,5 @@ sha256  b5539243f187e3d478d76d44ae13aab83952c94b885ad889df6fa9997e16a441  linux-
 sha256  fb5a425bd3b3cd6071a3a9aff9909a859e7c1158d54d32e07658398cd67eb6a0  COPYING
 sha256  f6b78c087c3ebdf0f3c13415070dd480a3f35d8fc76f3d02180a407c1c812f79  LICENSES/preferred/GPL-2.0
 sha256  8e378ab93586eb55135d3bc119cce787f7324f48394777d00c34fa3d0be3303f  LICENSES/exceptions/Linux-syscall-note
+
+sha256  dab3052783c68c46a5bc645b1c38d9705da995ab42823566518b62eb1fa1ef97  linux-576cc10e1ed50a9eacffc7a05c796051d7343ea4.tar.gz
diff --git a/buildroot/linux/linux.mk b/buildroot/linux/linux.mk
index 16d9f19470..cd5f555f1f 100644
--- a/buildroot/linux/linux.mk
+++ b/buildroot/linux/linux.mk
@@ -163,7 +163,9 @@ LINUX_MAKE_FLAGS = \
 	CROSS_COMPILE="$(TARGET_CROSS)" \
 	WERROR=0 \
 	REGENERATE_PARSERS=1 \
-	DEPMOD=$(HOST_DIR)/sbin/depmod
+	DEPMOD=$(HOST_DIR)/sbin/depmod \
+	CFLAGS_KERNEL=-g
+	CFLAGS=-g
 
 ifeq ($(BR2_REPRODUCIBLE),y)
 LINUX_MAKE_ENV += \
diff --git a/buildroot/package/e2fsprogs/e2fsprogs.mk b/buildroot/package/e2fsprogs/e2fsprogs.mk
index cbaac4f40b..dad393e71a 100644
--- a/buildroot/package/e2fsprogs/e2fsprogs.mk
+++ b/buildroot/package/e2fsprogs/e2fsprogs.mk
@@ -17,6 +17,7 @@ E2FSPROGS_INSTALL_STAGING = YES
 # problems for other packages.
 E2FSPROGS_DEPENDENCIES = host-pkgconf util-linux
 HOST_E2FSPROGS_DEPENDENCIES = host-pkgconf host-util-linux
+HOST_E2FSPROGS_APPLY_PATCH = YES
 
 E2FSPROGS_SELINUX_MODULES = fstools
 
@@ -35,7 +36,10 @@ HOST_E2FSPROGS_CONF_OPTS = \
 	--enable-elf-shlibs \
 	--with-crond-dir=no \
 	--with-udev-rules-dir=no \
-	--with-systemd-unit-dir=no
+	--with-systemd-unit-dir=no \
+	CFLAGS="$${CFLAGS} -std=gnu17 "
+
+HOST_E2FSPROGS_MAKE_OPTS += CFLAGS="$${CFLAGS} -std=gnu17 "
 
 # Set the binary directories to "/bin" and "/sbin", as busybox does,
 # so that we do not end up with two versions of e2fs tools.
diff --git a/buildroot/package/gawk/gawk.mk b/buildroot/package/gawk/gawk.mk
index ff1b9920af..d15f6eafdf 100644
--- a/buildroot/package/gawk/gawk.mk
+++ b/buildroot/package/gawk/gawk.mk
@@ -32,6 +32,7 @@ GAWK_CONF_OPTS += --without-readline
 endif
 
 HOST_GAWK_CONF_OPTS = --without-readline --without-mpfr
+HOST_GAWK_MAKE_OPTS += CFLAGS="$${CFLAGS} -Wno-error=incompatible-pointer-types"
 
 define GAWK_CREATE_SYMLINK
 	ln -sf gawk $(TARGET_DIR)/usr/bin/awk
diff --git a/buildroot/package/gmp/gmp.mk b/buildroot/package/gmp/gmp.mk
index 7e8da9025c..6ff9ff0d07 100644
--- a/buildroot/package/gmp/gmp.mk
+++ b/buildroot/package/gmp/gmp.mk
@@ -14,6 +14,8 @@ GMP_CPE_ID_VENDOR = gmplib
 GMP_DEPENDENCIES = host-m4
 HOST_GMP_DEPENDENCIES = host-m4
 
+HOST_GMP_CONF_OPTS += CFLAGS="$${CFLAGS} -std=gnu17 "
+
 GMP_CONF_ENV += CC_FOR_BUILD="$(HOSTCC) -std=c99"
 
 # GMP doesn't support assembly for coldfire or mips r6 ISA yet
diff --git a/buildroot/package/m4/m4.mk b/buildroot/package/m4/m4.mk
index 39ad898b10..2f6af275d4 100644
--- a/buildroot/package/m4/m4.mk
+++ b/buildroot/package/m4/m4.mk
@@ -10,4 +10,7 @@ M4_SITE = $(BR2_GNU_MIRROR)/m4
 M4_LICENSE = GPL-3.0+
 M4_LICENSE_FILES = COPYING
 
+HOST_M4_MAKE_OPTS += CFLAGS="$${CFLAGS} -std=gnu17 "
+
+
 $(eval $(host-autotools-package))
diff --git a/resources/configs/raspberrypi4_lvgl_defconfig b/resources/configs/raspberrypi4_lvgl_defconfig
index 8b57ea2..25f8b40 100644
--- a/resources/configs/raspberrypi4_lvgl_defconfig
+++ b/resources/configs/raspberrypi4_lvgl_defconfig
@@ -3,7 +3,8 @@ BR2_cortex_a72=y
 BR2_ARM_FPU_VFPV4=y
 BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_6_6=y
 BR2_TOOLCHAIN_BUILDROOT_CXX=y
-BR2_GLOBAL_PATCH_DIR="board/raspberrypi/patches"
+BR2_BINUTILS_VERSION_2_42_X=y
+BR2_BINUTILS_VERSION="2.42"
 BR2_DOWNLOAD_FORCE_CHECK_HASHES=y
 BR2_TARGET_GENERIC_HOSTNAME="lvgl-buildroot"
 BR2_TARGET_GENERIC_ISSUE="Welcome to LVGL Buildroot! "
```

</details>

```shell
patch -p1 < fix_overlay.patch
./build.sh
# ここで数10分くらいかかる

cd output
make sdk
mkdir -p ~/sdk
tar -xzf images/aarch64-buildroot-linux-gnu_sdk-buildroot.tar.gz -C ~/sdk
cd ../application/lv_benchmark
source ../setup-build-env.sh
cmake -B build -S .
make -j $(nproc) -C build
cd ../..
cp application/lv_benchmark/bin/lvgl-app resources/board/rootfs_overlay/usr/bin/
cd output
make
cd ..
```

# 実行(qemu)

こちらの環境ではなぜかkeyboard入力を受け付けず、ログイン出来なかった
仕方がないのでrcSを以下のように修正した

```shell
echo lvgl-app >> output/target/etc/init.d/rcS
```

再度ビルドして SDカードの容量をpaddingする
```
make -C output 
truncate -s 512M  output/images/sdcard.img
```

以下でqemu実行
```shell
qemu-system-aarch64 -M raspi4b -m 2G -cpu cortex-a72 \
 -kernel output/images/Image \
 -dtb ./bcm2711-rpi-4-b.dtb \
 -drive if=sd,id=sd1,file=output/images/sdcard.img,format=raw \
 -append "root=/dev/mmcblk1p2 rw rootwait rootfstype=ext4 console=tty0" \
 -display gtk \
 -device usb-kbd \
 -device usb-mouse 
```



点滅注意のためコードブロックを置きます

光過敏性発作の可能性があるため、スクロールされる方は自己責任でお願いします

```







































```

実行イメージ

![optimized_animation.gif](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/3786381/b889cc9f-ff71-4dda-aac5-caa629bfede6.gif)


# 自前アプリ

`application/lv_benchmark`内のコードを編集することで
自由にアプリを作成出来る

なお、デフォルトだとfbdevを使用する設定になっている


[(2)](https://qiita.com/ta_yano/items/b4f174893de19c208b77) へ続く