2025年6月26日 星期四

build armbian image,修改 kernel 原始碼

目的,加上 ILI9488 LCD 的驅動程式。

因為建立的 external module,載入時會失敗,只好把驅動程式加入建立 image 時的 kernel source 中,這樣建立的 module 就可以使用。只是很難debug,就找現成的來用吧。

後記,買 ST7796 驅動的 LCD,可以使用 565 的格式,直接用 ILI9341 的驅動。ILI9488 只能用 666 的格式,實在很麻煩,儘量不要用。

先 git clone https://github.com/armbian/build

再執行一次 build,不用到最後,只要建立 kernel source 就好

-----------------
./compile.sh \
BOARD=orangepione MAKE_THREADS=4  \
BRANCH=legacy RELEASE=bookworm \
BUILD_MINIMAL=yes BUILD_DESKTOP=no  \
NETWORKING_STACK="network-manager" \
KERNEL_CONFIGURE=no \
INSTALL_HEADERS=yes \
KERNEL_BTF=yes
-----------------

然後把 cache 下的對應的 kernel source,整個複製到新的目錄,如 [6.6_sunxi_armhf_wk]。然後,到新的目錄下,執行 make clean,把編譯的檔案刪掉。刪掉 .git 檔,再執行下列指令,建立啟始的 git 專案。

-----------------
git init
git add .
git commit -m "Initial kernel state for patching"
-----------------

再把驅動程式,如 fb_ili9488.c,複製到對應的目錄下,如 drivers/staging/fbtft,並修改相關的檔案,如 drivers/staging/fbtft 目錄下的 Kconfig 和 Makefile。

然後執行下列指令,提交程式修改。

-----------------
# 首先,提交你的修改
git add drivers/staging/fbtft/fb_ili9488.c drivers/staging/fbtft/Kconfig drivers/staging/fbtft/Makefile
git commit -s -m "Add: FB_TFT ILI9488 driver"
# 然後生成從上次提交到現在的 patch (或者指定範圍)
# 範例:從上一次提交到 HEAD
git format-patch -1 HEAD
# 這會生成一個類似 0001-Add-FB_TFT-ILI9488-driver.patch 的檔案。
-----------------

再將這個 patch 檔,複製到 patch/kernel/archive/sunxi-6.6/patches.armbian/ 下,並修改 series.armbian 和 series.conf,加入這個 patch 檔。

修改 config/kernel/linux-sunxi-legacy.config,加入 CONFIG_FB_TFT_ILI9488=m。

然後,build image,測試結果。

若是加了自己的 patch,或改了 kernel 的 config,重新 build image 的時間,就會花很多時間。

使用 docker 來 build (ArchLinux)

參考 Gemini 教的步驟。

-----------------

-----------------





2025年6月20日 星期五

Orange Pi One 連接 ST7796 界面電阻觸控 LCD

成果展示

先展示一下成果,放張照片,當作紀念。要走到這邊,實在不容易。



參考連結

動機與背景

因為貪便宜,也為了改 3D印表機不要花太高的成本,在網路上買了好幾片 Orange Pi One 的單板電腦。

可能因為用的晶片太舊,新的 Kernel 在支援上會有問題。例如目前的 kernel 是 6.12.30,同樣的程式,在 Orange Pi Zero 3 上,可以正常執行,但在 Orange Pi One 就是怪怪的,使用 tinydrm 的 module,完全無法啟動 X window。經反覆測試,確認在較舊的 kernel  6.6.75 上,才能正常執行。另外,armbian/build 的 32位元的 sunxi 的 kernel,沒有把 gpio-backlight 編成 module,dts 中,無法控制背光。

使用 panel-mipi-dbi-spi,在 Orange Pi Zero3 下,可以正常運作,也可以執行 KlipperScreen。但在 Orange Pi One,相同的設定檔,會出現下面的錯誤訊息。後來確認,背光控制要有 gpio_backlight 的 kernel module。

$ dmesg | less
[   18.163593] panel-mipi-dbi-spi spi0.0: supply power not found, using dummy regulator
[   18.163853] panel-mipi-dbi-spi spi0.0: supply io not found, using dummy regulator
[   18.164817] spi spi0.0: deferred probe pending: panel-mipi-dbi-spi: Failed to get backlight

$ sudo modprobe gpio_backlight
[sudo] password for klipper: 
modprobe: FATAL: Module gpio_backlight not found in directory /lib/modules/6.12.23-current-sunxi

另外,Orange Pi Zero3 的 image 裡,有 fb_st7796s 的模組,在 Orange Pi One 則沒有。

使用 6.12.30-current-sunxi,雖然 console 是正常的,但啟動 X window,就會出現 Bus error。

$ X

X.Org X Server 1.21.1.7
X Protocol Version 11, Revision 0
Current Operating System: Linux orangepione 6.12.30-current-sunxi #2 SMP Thu May 22 20:29:54 CST 2025 armv7l
Kernel command line: root=UUID=4c8b2287-edb5-431a-904c-a21f8f213ef8 rootwait rootfstype=ext4 splash=verbose console=ttyS0,115200 console=tty1 hdmi.audio=EDID:0 disp.screen0_output_mode=1920x1080p60 consoleblank=0 loglevel=1 ubootpart=d0be82e5-01 ubootsource=mmc usb-storage.quirks=0x2537:0x1066:u,0x2537:0x1068:u   sunxi_ve_mem_reserve=0 sunxi_g2d_mem_reserve=0 sunxi_fb_mem_reserve=16 cgroup_enable=memory
xorg-server 2:21.1.7-3+deb12u9 (https://www.debian.org/support) 
Current version of pixman: 0.42.2
	Before reporting problems, check http://wiki.x.org
	to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
	(++) from command line, (!!) notice, (II) informational,
	(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.0.log", Time: Mon Jun 23 14:36:07 2025
(==) Using config directory: "/etc/X11/xorg.conf.d"
(==) Using system config directory "/usr/share/X11/xorg.conf.d"
(EE) 
(EE) Backtrace:
(EE) 
(EE) Bus error at address 0xb6185000
(EE) 
Fatal server error:
(EE) Caught signal 7 (Bus error). Server aborting
(EE) 
(EE) 
Please consult the The X.Org Foundation support 
	 at http://wiki.x.org
 for help. 
(EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information.
(EE) 
(EE) Server terminated with error (1). Closing log file.
Aborted

另外,使用 6.12.30-current-sunxi,自行編譯的 fb_st7796s 或 fb_ili9488 模組,也不能正常運作,會變得一片白屏。

經過反覆的測試,確認 Orange Pi One 的 32位元的系統,要使用 6.6.75 的 kernel 才能正常運作。

再持續地做各種嘗試,發現使用 edge 的 image,6.15 的 kernel 可以正常運作。比對 6.12 和 6.15 的 driver 原始碼,發現程式有不少的變動,6.12 的可能有一些 bug 吧。那就用最新的吧。

至於 ILI9488界面的 LCD,因為必須使用 666 的格式,6.12 之後可以支援,但是使用 X 仍會當,最好暫時不要用。

自行 build image

後來自行照著 armbian 的 build 說明,自行 build image,終於可以正常安裝執行 KlipperScreen。

複製 armbian/build 的程式。

$ git clone https://github.com/armbian/build

然後修改 build/config/kernel/linux-sunxi-legacy.config,增加 build gpio_backlight 和 fb_st7796s 的 kernel module。

.......
CONFIG_BACKLIGHT_QCOM_WLED=m
CONFIG_BACKLIGHT_RT4831=m
CONFIG_BACKLIGHT_GPIO=m
CONFIG_BACKLIGHT_LED=m
........
CONFIG_FB_TFT_ST7735R=m
CONFIG_FB_TFT_ST7789V=m
CONFIG_FB_TFT_ST7796S=m
CONFIG_FB_TFT_TINYLCD=m
........

執行 compile.sh。

$ ./compile.sh \
BOARD=orangepione \
BRANCH=legacy RELEASE=bookworm \
BUILD_MINIMAL=yes BUILD_DESKTOP=no  \
NETWORKING_STACK="network-manager" \
KERNEL_CONFIGURE=no \
INSTALL_HEADERS=yes \
KERNEL_BTF=yes

編譯完成,產生的 image。

$ ls build/output/images/
Armbian-unofficial_25.08.0-trunk_Orangepione_bookworm_legacy_6.6.75_minimal.img
Armbian-unofficial_25.08.0-trunk_Orangepione_bookworm_legacy_6.6.75_minimal.img.sha
Armbian-unofficial_25.08.0-trunk_Orangepione_bookworm_legacy_6.6.75_minimal.img.txt






網誌存檔