From ddfd1960bbbcff04beea3129c53b2dbe43482ce8 Mon Sep 17 00:00:00 2001
From: lin <lin@kickpi.com>
Date: Wed, 16 Apr 2025 10:28:41 +0000
Subject: [PATCH] feat(build): add auto build support

---
 build.sh |   67 ++++++++++++++++++++++++++++++++-
 1 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/build.sh b/build.sh
index 8a2e427..4ced701 100755
--- a/build.sh
+++ b/build.sh
@@ -2,6 +2,16 @@
 
 BOARD_CONFIG_DIR=longan/device/config/chips/
 BOARD_CONFIG_FILE=longan/device/.BoardConfig.mk
+DTS_DIR=$BOARD_CONFIG_DIR/a133/configs/c3
+
+LCD_DTS=(
+  "lcd-lvds-7-1024-600.dtsi"
+  "lcd-lvds-21-1920-1080.dtsi"
+  "lcd-mipi-10-800-1280-v1.dtsi"
+  "lcd-mipi-10-800-1280-v2.dtsi"
+  "lcd-mipi-8-800-1280.dtsi"
+  "lcd-mipi-5-720-1280.dtsi"
+)
 
 function build_lunch() {
     TARGET_BOARD_PATH_ARRAY=($(find $BOARD_CONFIG_DIR -name "BoardConfig-a133*.mk" | sort))
@@ -34,10 +44,34 @@
     longan/build/mkcommon.sh autoconfig -i a133 -o android -b c3
 }
 
-if [ "x$1" == "xlunch" ]; then
-    build_lunch && exit 0
-else
+function build() {
+    DTS_FILE=${DTS_DIR}/${DTS_NAME}.dts
+    for config in "${LCD_DTS[@]}"; do
+      # 检查未被注释的配置行(支持行首空格)
+      if grep -q -E "^[[:space:]]*#include \"${config}\"" "$DTS_FILE"; then
+        # 提取 lcd- 之后 .dtsi 之前的内容(去除头尾字符)
+        LCD_NAME=$(echo "$config" | sed 's/^lcd-\(.*\)\.dtsi$/\1/')
+        break
+      fi
+    done
+
+
+sed -i -E "
+/^[[:space:]]*export LCD_NAME=/ {
+  s|^(export LCD_NAME=).*$|\1${LCD_NAME}|
+  h
+  \$!{x;b};x
+  b done
+}
+
+1 i export LCD_NAME=${LCD_NAME}
+
+:done
+" "${BOARD_CONFIG_FILE}"
+
+
     source $BOARD_CONFIG_FILE
+
     if [ x"$1" == "xuboot" ] || [ x"$1" == "xu" ] || [ x"$1" == "x" ]; then
         echo "Start build uboot"
         cd longan/brandy/brandy-2.0
@@ -95,4 +129,31 @@
     pack
     cd -
 
+
+}
+
+if [ "x$1" == "xlunch" ]; then
+    build_lunch && exit 0
+else
+    source $BOARD_CONFIG_FILE
+    if [ "x$1" == "xall" ]; then
+        for config in "${LCD_DTS[@]}"; do
+            echo "正在切换设备树: $config"
+            # Step 1: 注释所有 LCD 相关行(无论原始是否已注释)
+            sed -i -E '/#include "lcd-/s|^([[:space:]]*)(//)?|\1//|' "$DTS_DIR/$DTS_NAME.dts"
+
+            # Step 2: 解除目标配置的注释
+            sed -i -E "s|^([[:space:]]*)//#include \"$config\"|\1#include \"$config\"|" "$DTS_DIR/$DTS_NAME.dts"
+
+            # # 提取 lcd- 之后 .dtsi 之前的内容(去除头尾字符)
+            # LCD_DTS_FILE=$(echo "$config" | sed 's/^lcd-\(.*\)\.dtsi$/\1/')
+
+            # 执行编译
+            echo "开始编译..."
+            build
+        done
+    else
+        build  && exit 0
+    fi
+
 fi

--
Gitblit v1.6.2