修复分区size错误造成无法启动问题,已经增加检测分区脚本,确保不再出错。
authorsnickersun <snickersun@163.com>
Wed, 3 Jun 2026 07:06:51 +0000 (15:06 +0800)
committersnickersun <snickersun@163.com>
Wed, 3 Jun 2026 07:06:51 +0000 (15:06 +0800)
2.sdk/project/7PIN_1_5/new.bat
2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/images/firmware_base_release_pack/config/partition/CRANEL_SINGLE_QUEC_FLASH_LAYOUT_8M_GNSS_OPEN_VOLTE.json
2.sdk/project/7PIN_1_5/sdk/system/platform/ASR_1606/boards/EG810MCN_GA_VOLTE/include/app_link_start_addr.h
2.sdk/project/7PIN_1_5/tools/check_app_partition_layout.py [new file with mode: 0644]

index 37eabed..425b757 100644 (file)
@@ -13,6 +13,13 @@ if "!PRODUCT_NAME!"=="" (
 md images 2>nul
 del /q images\* 2>nul
 
+rem ---- APP partition layout consistency check (must pass before build) ----
+python tools\check_app_partition_layout.py
+if errorlevel 1 (
+    echo [ERROR] app partition layout check failed
+    exit /b 1
+)
+
 rem sync audio NVM into usr for customer_fs (gain / VE tables)
 if exist "sdk\services\microPython\ports\quectel\core\audio_gain.nvm" (
     copy /y "sdk\services\microPython\ports\quectel\core\audio_gain.nvm" "usr\audio_gain.nvm" >nul
@@ -28,7 +35,7 @@ if errorlevel 1 (
 )
 echo [OK] ext_fs.bin
 
-..\..\Helios_SDK\tools\ASR_1606\win32\mklfs.exe -c usr -b 4096 -r 4096 -p 4096 -s 1007616 -i .\images\customer_fs.bin
+..\..\Helios_SDK\tools\ASR_1606\win32\mklfs.exe -c usr -b 4096 -r 4096 -p 4096 -s 1019904 -i .\images\customer_fs.bin
 if errorlevel 1 (
     echo [ERROR] customer_fs.bin failed - check usr size
     exit /b 1
index 0342a45..d3c6986 100644 (file)
@@ -65,8 +65,8 @@
             },
             {
                "format" : "raw",
-               "name" : "pad",
-               "size" : "12KiB"
+               "name" : "reserved",
+               "size" : "-1"
             },
             {
                "format" : "raw",
@@ -76,7 +76,7 @@
             {
                "format" : "raw",
                "name" : "customer_fs",
-               "size" : "984KiB"
+               "size" : "996KiB"
             },
             {
                "format" : "raw",
index 5567586..7028a56 100644 (file)
@@ -3,11 +3,12 @@
 #define __APP_LINK_START_ADDR_H__
 
 #define APP_LINK_START_ADDR  0x80521000
-/* 对齐 K8:为 Opus(~250KB) 等扩展预留 APP 区;物理分区需与基线一致 */
-#define APP_FLASH_MAX_SIZE 0x180000
-// 1.5M 大小 0x180000
-// 1.2M 大小 0x120000
-// 1.8M 大小 0x1F8000  
+/* 必须严格等于 partition.json 中 customer_app 大小,否则 app 尾部会越界覆盖 customer_fs 导致 lfs 挂载失败 */
+#define APP_FLASH_MAX_SIZE 0x177000
+// 1500K 大小 0x177000  (= 当前 customer_app 分区)
+// 1.5M  大小 0x180000  (= 1536KiB)
+// 1.2M  大小 0x120000
+// 1.8M  大小 0x1F8000  
 
 #define APP_RAM_START 0x7E3E0000
 #define APP_RAM_MAX_SIZE 0x180000
diff --git a/2.sdk/project/7PIN_1_5/tools/check_app_partition_layout.py b/2.sdk/project/7PIN_1_5/tools/check_app_partition_layout.py
new file mode 100644 (file)
index 0000000..90ce514
--- /dev/null
@@ -0,0 +1,173 @@
+# -*- coding: utf-8 -*-
+# =============================================================================
+# APP 分区一致性校验(编译期保护 / 校验式 SSOT)
+#
+# 为什么需要它:
+#   customer_app 的起始地址必须严格 == APP_LINK_START_ADDR(0x80521000),否则
+#   app 代码里的绝对地址全部跑飞,设备启动崩溃。
+#   分区表里 reserved:-1 排在 customer_app 前面,它会“吃掉 app+fs 用剩的空间”,
+#   即  reserved = 固定段 - customer_app - customer_fs。
+#   只有当 (customer_app + customer_fs) 恒为基线值 2496KiB 时,reserved 才恒为
+#   12KiB,customer_app 才落在 0x80521000。任何只改一处都会让 app 移位或越界
+#   覆盖 customer_fs(表现为 Exception PC / Fail to mount lfs)。
+#
+# 三处必须同步(本脚本只“校验”,不自动改;不一致会中止编译并提示应改成什么):
+#   [A] app_link_start_addr.h : APP_FLASH_MAX_SIZE  = customer_app 字节(hex)
+#   [B] partition json        : customer_app.size / customer_fs.size (KiB)
+#   [C] new.bat               : mklfs -c usr -s     = customer_fs 字节(十进制)
+#
+# 改分区怎么改(示例:给 Opus 再多留 12KiB 给 app):
+#   1) json: customer_app 1500KiB -> 1512KiB;customer_fs 996KiB -> 984KiB
+#            (一增一减,和必须仍 == 2496KiB)
+#   2) .h  : APP_FLASH_MAX_SIZE -> hex(1512*1024) = 0x17A000
+#   3) new.bat: mklfs -c usr -s -> 984*1024 = 1007616
+#   改完重新编译,本脚本通过才会继续。
+#
+# 约束:customer_app、customer_fs 的 KiB 必须是 4 的倍数(=> 字节 4KB 对齐)。
+# =============================================================================
+import os
+import re
+import sys
+import json
+
+try:
+    sys.stdout.reconfigure(encoding="utf-8")
+except Exception:
+    pass
+
+# ---- SSOT 常量(基线设计值,改布局总量时才动这里)----
+TOTAL_KIB = 2496            # customer_app + customer_fs 的固定总和
+EXPECT_APP_LINK = 0x80521000  # customer_app 期望起始 == APP_LINK_START_ADDR
+TAG = "[layout-check]"
+
+HERE = os.path.dirname(os.path.abspath(__file__))
+PROJ = os.path.dirname(HERE)  # project/7PIN_1_5
+BOARD = os.path.join(PROJ, "sdk", "system", "platform", "ASR_1606",
+                     "boards", "EG810MCN_GA_VOLTE")
+H_PATH = os.path.join(BOARD, "include", "app_link_start_addr.h")
+J_PATH = os.path.join(BOARD, "images", "firmware_base_release_pack",
+                      "config", "partition",
+                      "CRANEL_SINGLE_QUEC_FLASH_LAYOUT_8M_GNSS_OPEN_VOLTE.json")
+NB_PATH = os.path.join(PROJ, "new.bat")
+
+
+def read_text(path):
+    if not os.path.isfile(path):
+        return None
+    with open(path, "r", encoding="utf-8", errors="ignore") as f:
+        return f.read()
+
+
+def parse_hex_define(text, name):
+    m = re.search(r"#define\s+" + name + r"\s+(0x[0-9A-Fa-f]+)", text)
+    return int(m.group(1), 16) if m else None
+
+
+def parse_json_sizes(text):
+    sizes = {}
+    try:
+        data = json.loads(text)
+    except Exception:
+        return sizes
+
+    def walk(o):
+        if isinstance(o, dict):
+            if "name" in o and "size" in o:
+                sizes[o["name"]] = o["size"]
+            for v in o.values():
+                walk(v)
+        elif isinstance(o, list):
+            for v in o:
+                walk(v)
+
+    walk(data)
+    return sizes
+
+
+def size_to_kib(val):
+    m = re.match(r"\s*(\d+)\s*KiB", str(val or ""))
+    return int(m.group(1)) if m else None
+
+
+def parse_mklfs_usr_bytes(text):
+    m = re.search(r"mklfs\.exe[^\n\r]*-c\s+usr[^\n\r]*-s\s+(\d+)", text)
+    return int(m.group(1)) if m else None
+
+
+def main():
+    h_text = read_text(H_PATH)
+    j_text = read_text(J_PATH)
+    nb_text = read_text(NB_PATH)
+
+    errs = []
+    for label, val, path in (("app_link_start_addr.h", h_text, H_PATH),
+                             ("partition json", j_text, J_PATH),
+                             ("new.bat", nb_text, NB_PATH)):
+        if val is None:
+            errs.append("找不到文件: %s (%s)" % (label, path))
+    if errs:
+        for e in errs:
+            print("%s ERROR %s" % (TAG, e))
+        return 1
+
+    app_link = parse_hex_define(h_text, "APP_LINK_START_ADDR")
+    app_max = parse_hex_define(h_text, "APP_FLASH_MAX_SIZE")
+
+    sizes = parse_json_sizes(j_text)
+    app_kib = size_to_kib(sizes.get("customer_app"))
+    fs_kib = size_to_kib(sizes.get("customer_fs"))
+
+    fs_mklfs = parse_mklfs_usr_bytes(nb_text)
+
+    print("%s ---- 当前三处取值 ----" % TAG)
+    print("%s [A] .h   APP_LINK_START_ADDR = %s" %
+          (TAG, hex(app_link) if app_link is not None else "<解析失败>"))
+    print("%s [A] .h   APP_FLASH_MAX_SIZE  = %s%s" %
+          (TAG, hex(app_max) if app_max is not None else "<解析失败>",
+           " (%dKiB)" % (app_max // 1024) if app_max else ""))
+    print("%s [B] json customer_app.size   = %s KiB" % (TAG, app_kib))
+    print("%s [B] json customer_fs.size    = %s KiB" % (TAG, fs_kib))
+    print("%s [C] new.bat mklfs usr -s     = %s bytes%s" %
+          (TAG, fs_mklfs, " (%dKiB)" % (fs_mklfs // 1024) if fs_mklfs else ""))
+
+    if None in (app_link, app_max, app_kib, fs_kib, fs_mklfs):
+        print("%s ERROR 三处取值存在解析失败,请检查文件格式" % TAG)
+        return 1
+
+    # 1) app + fs 总和恒定
+    if app_kib + fs_kib != TOTAL_KIB:
+        errs.append("app(%dKiB)+fs(%dKiB)=%dKiB != %dKiB; 若 app 取 %dKiB, fs 应改为 %dKiB"
+                    % (app_kib, fs_kib, app_kib + fs_kib, TOTAL_KIB,
+                       app_kib, TOTAL_KIB - app_kib))
+    # 2) 4KB 对齐
+    if app_kib % 4 != 0:
+        errs.append("customer_app=%dKiB 不是 4 的倍数(需 4KB 对齐)" % app_kib)
+    if fs_kib % 4 != 0:
+        errs.append("customer_fs=%dKiB 不是 4 的倍数(需 4KB 对齐)" % fs_kib)
+    # 3) .h APP_FLASH_MAX_SIZE == customer_app
+    if app_max != app_kib * 1024:
+        errs.append(".h APP_FLASH_MAX_SIZE=%s != customer_app %dKiB; 应改为 %s"
+                    % (hex(app_max), app_kib, hex(app_kib * 1024)))
+    # 4) new.bat mklfs == customer_fs
+    if fs_mklfs != fs_kib * 1024:
+        errs.append("new.bat mklfs usr -s=%d != customer_fs %dKiB; 应改为 %d"
+                    % (fs_mklfs, fs_kib, fs_kib * 1024))
+    # 5) APP_LINK_START_ADDR 期望固定
+    if app_link != EXPECT_APP_LINK:
+        errs.append(".h APP_LINK_START_ADDR=%s != 期望 %s (由 reserved 对齐决定,勿随意改)"
+                    % (hex(app_link), hex(EXPECT_APP_LINK)))
+
+    if errs:
+        print("%s ======== 分区配置不一致,编译中止 ========" % TAG)
+        for e in errs:
+            print("%s ERROR %s" % (TAG, e))
+        print("%s 改法见 tools/check_app_partition_layout.py 顶部备注" % TAG)
+        return 1
+
+    print("%s OK app+fs=%dKiB, customer_app 起始锁定 %s" %
+          (TAG, TOTAL_KIB, hex(EXPECT_APP_LINK)))
+    return 0
+
+
+if __name__ == "__main__":
+    sys.exit(main())