Pārlūkot izejas kodu

update: 完成fota启用后的ld文件自动修改

Wendal Chen 2 gadi atpakaļ
vecāks
revīzija
972222377f
4 mainītis faili ar 302 papildinājumiem un 88 dzēšanām
  1. 2 1
      app/port/luat_conf_bsp.h
  2. 214 0
      ld/xt804.ld
  3. 49 0
      soc_tools/AIR690.json
  4. 37 87
      xmake.lua

+ 2 - 1
app/port/luat_conf_bsp.h

@@ -67,6 +67,7 @@
 // #define LUAT_USE_FTP
 // #define LUAT_USE_ERRDUMP 1
 
+#define LUAT_USE_FOTA 1
 
 #define LUAT_USE_IOTAUTH 1
 
@@ -344,7 +345,7 @@
 //<-- custom
 //------------------------------------------------------------------------------
 
-#ifdef AIR601
+#if defined(AIR601) || defined(AIR690)
 #ifndef LUAT_USE_WLAN
  #define LUAT_USE_WLAN 1
 #endif

+ 214 - 0
ld/xt804.ld

@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/******************************************************************************
+ * @file     gcc_csky.ld
+ * @brief    csky linker file
+ * @version  V1.0
+ * @date     02. June 2017
+ ******************************************************************************/
+MEMORY
+{
+	I-SRAM : ORIGIN = SRAM_O , LENGTH = SRAM_L
+	D-SRAM : ORIGIN = 0x20000100 , LENGTH = 0x47f00   /* D-SRAM  288KB */
+	V-SRAM : ORIGIN = 0x20000000 , LENGTH = 0x100   /* off-chip SRAM 8MB */
+}
+
+__min_heap_size = 0x100;
+PROVIDE (__ram_end  = 0x20028000);
+PROVIDE (__heap_end = __ram_end);
+
+REGION_ALIAS("REGION_TEXT",    I-SRAM);
+REGION_ALIAS("REGION_RODATA",  I-SRAM);
+REGION_ALIAS("REGION_VDATA",   V-SRAM);
+REGION_ALIAS("REGION_DATA",    D-SRAM);
+REGION_ALIAS("REGION_BSS",     D-SRAM);
+
+ENTRY(Reset_Handler)
+SECTIONS
+{
+ .text : {
+  . = ALIGN(0x4) ;
+  KEEP(*startup.o(.vectors))
+  __stext = . ;
+  *(.text)
+  *(.text*)
+  *(.text.*)
+  *(.gnu.warning)
+  *(.stub)
+  *(.gnu.linkonce.t*)
+  *(.glue_7t)
+  *(.glue_7)
+  *(.jcr)
+  KEEP (*(.init))
+  KEEP (*(.fini))
+  . = ALIGN (4) ;
+  PROVIDE(__ctbp = .);
+  *(.call_table_data)
+  *(.call_table_text)
+  . = ALIGN(0x10) ;
+  __etext = . ;
+ } > REGION_TEXT
+ .rodata : {
+  . = ALIGN(0x4) ;
+  __srodata = .;
+  *(.rdata)
+  *(.rdata*)
+  *(.rdata1)
+  *(.rdata.*)
+  *(.rodata)
+  *(.rodata1)
+  *(.rodata*)
+  *(.rodata.*)
+  *(.rodata.str1.4)
+  . = ALIGN(0x4) ;
+  __ctor_start__ = .;
+  KEEP (*crtbegin.o(.ctors))
+  KEEP (*crtbegin?.o(.ctors))
+  KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
+  KEEP (*(SORT(.ctors.*)))
+  KEEP (*(.ctors))
+  __ctor_end__ = .;
+  KEEP (*crtbegin.o(.dtors))
+  KEEP (*crtbegin?.o(.dtors))
+  KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
+  KEEP (*(SORT(.dtors.*)))
+  KEEP (*(.dtors))
+  __dtor_end__ = .;
+  . = ALIGN(0x4) ;
+  __erodata = .;
+ } > REGION_RODATA
+ .vdata : {
+ 	. = ALIGN(0x4) ;
+  	__vdata_start__ = . ;
+ 	KEEP(*startup.o(.vdata))
+ 	. = ALIGN(0x4) ;
+  	__vdata_end__ = .;
+ } > REGION_VDATA
+ .data : {
+  . = ALIGN(0x4) ;
+  __sdata = . ;
+  __data_start__ = . ;
+  data_start = . ;
+  *(.ram_run)
+  *(.got.plt)
+  *(.got)
+  *(.gnu.linkonce.r*)
+  *(.data)
+  *(.data*)
+  *(.data1)
+  *(.data.*)
+  *(.gnu.linkonce.d*)
+  *(.data1)
+  *(.gcc_except_table)
+  *(.gcc_except_table*)
+  __start_init_call = .;
+  *(.initcall.init)
+  __stop_init_call = .;
+  __start_cmd = .;
+  *(.bootloaddata.cmd)
+  . = ALIGN(4) ;
+  __stop_cmd = .;
+  *(.sdata)
+  *(.sdata.*)
+  *(.gnu.linkonce.s.*)
+  *(__libc_atexit)
+  *(__libc_subinit)
+  *(__libc_subfreeres)
+  *(.note.ABI-tag)
+  . = ALIGN(0x4) ;
+  __edata = .;
+  __data_end__ = .;
+ } > REGION_DATA AT > REGION_RODATA
+ .bss : {
+  . = ALIGN(0x4) ;
+  __sbss = ALIGN(0x4) ;
+  __bss_start__ = . ;
+  *(.dynsbss)
+  *(.sbss)
+  *(.sbss.*)
+  *(.scommon)
+  *(.dynbss)
+  *(.bss)
+  *(.bss.*)
+  *(COMMON)
+  . = ALIGN(0x4) ;
+  __ebss = . ;
+  __end = . ;
+  end = . ;
+  __bss_end__ = .;
+ } > REGION_BSS
+ ._user_heap : {
+  . = ALIGN(0x8) ;
+  __heap_start = .;
+  . += __min_heap_size;
+  . = ALIGN(0x4) ;
+ } > REGION_BSS
+ .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) } > REGION_BSS
+ .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) } > REGION_BSS
+ .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }
+ .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
+ .eh_frame_hdr : { *(.eh_frame_hdr) }
+ .preinit_array :
+ {
+  PROVIDE_HIDDEN (__preinit_array_start = .);
+  KEEP (*(.preinit_array))
+  PROVIDE_HIDDEN (__preinit_array_end = .);
+ }
+ .init_array :
+ {
+  PROVIDE_HIDDEN (__init_array_start = .);
+  KEEP (*(SORT(.init_array.*)))
+  KEEP (*(.init_array))
+  PROVIDE_HIDDEN (__init_array_end = .);
+ }
+ .fini_array :
+ {
+  PROVIDE_HIDDEN (__fini_array_start = .);
+  KEEP (*(.fini_array))
+  KEEP (*(SORT(.fini_array.*)))
+  PROVIDE_HIDDEN (__fini_array_end = .);
+ }
+ .junk 0 : { *(.rel*) *(.rela*) }
+ .stab 0 : { *(.stab) }
+ .stabstr 0 : { *(.stabstr) }
+ .stab.excl 0 : { *(.stab.excl) }
+ .stab.exclstr 0 : { *(.stab.exclstr) }
+ .stab.index 0 : { *(.stab.index) }
+ .stab.indexstr 0 : { *(.stab.indexstr) }
+ .comment 0 : { *(.comment) }
+ .debug 0 : { *(.debug) }
+ .line 0 : { *(.line) }
+ .debug_srcinfo 0 : { *(.debug_srcinfo) }
+ .debug_sfnames 0 : { *(.debug_sfnames) }
+ .debug_aranges 0 : { *(.debug_aranges) }
+ .debug_pubnames 0 : { *(.debug_pubnames) }
+ .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
+ .debug_abbrev 0 : { *(.debug_abbrev) }
+ .debug_line 0 : { *(.debug_line) }
+ .debug_frame 0 : { *(.debug_frame) }
+ .debug_str 0 : { *(.debug_str) }
+ .debug_loc 0 : { *(.debug_loc) }
+ .debug_macinfo 0 : { *(.debug_macinfo) }
+ .debug_weaknames 0 : { *(.debug_weaknames) }
+ .debug_funcnames 0 : { *(.debug_funcnames) }
+ .debug_typenames 0 : { *(.debug_typenames) }
+ .debug_varnames 0 : { *(.debug_varnames) }
+ .debug_pubtypes 0 : { *(.debug_pubtypes) }
+ .debug_ranges 0 : { *(.debug_ranges) }
+ .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
+ /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
+}

+ 49 - 0
soc_tools/AIR690.json

@@ -0,0 +1,49 @@
+{
+    "version" : 1,
+    "chip" : {
+        "type" : "air101",
+        "ram"  :  {
+            "total" : 288,
+            "sys" : 64,
+            "lua" : 176
+        }
+    },
+    "rom": {
+        "file" : "AIR690.fls",
+        "fs" : {
+            "script" : {
+                "offset" : "80E0000",
+                "size" : 112,
+                "type" : "luadb"
+            }
+        },
+        "version-core": "v0007",
+        "version-bsp" : "v0004",
+        "mark" : "default",
+        "build" : {
+            "build_at" : "",
+            "build_by" : "",
+            "build_host" : "",
+            "build_system" : ""
+        }
+    },
+    "script" : {
+		"file" : "script.img",
+        "lua" : "5.3",
+        "bitw" : 32,
+        "use-luac" : true,
+        "use-debug" : true
+    },
+    "user" : {
+        "project" : "",
+        "version" : "",
+        "log_br" : "921600"
+    },
+	"download" : {
+		"core_addr" : "0x00000000",
+		"app_addr" : "0x00000000",
+		"script_addr" : "0x80E0000",
+		"user_addr" : "0x00000000",
+        "force_br" : "2M"
+	}
+}

+ 37 - 87
xmake.lua

@@ -4,12 +4,7 @@ set_xmakever("2.6.3")
 -- set_version("0.0.2", {build = "%Y%m%d%H%M"})
 add_rules("mode.debug", "mode.release")
 
-local AIR10X_VERSION
-local VM_64BIT = nil
 local luatos = "../LuatOS/"
-local TARGET_NAME
-local AIR10X_FLASH_FS_REGION_SIZE
-local LUAT_SCRIPT_SIZE
 
 toolchain("csky")
     set_kind("cross")
@@ -475,61 +470,21 @@ target("air10x")
     set_arch("c-sky")
     set_targetdir("$(buildir)/out")
     on_load(function (target)
-        local conf_data = io.readfile("$(projectdir)/app/port/luat_conf_bsp.h")
-        local LUAT_FS_SIZE = tonumber(conf_data:match("#define LUAT_FS_SIZE%s+(%d+)"))
-        LUAT_SCRIPT_SIZE = tonumber(conf_data:match("#define LUAT_SCRIPT_SIZE%s+(%d+)"))
 
-        AIR10X_FLASH_FS_REGION_SIZE = LUAT_FS_SIZE + LUAT_SCRIPT_SIZE
-        -- print(AIR10X_FLASH_FS_REGION_SIZE,LUAT_FS_SIZE , LUAT_SCRIPT_SIZE)
-        AIR10X_VERSION = conf_data:match("#define LUAT_BSP_VERSION \"(%w+)\"")
-        local LVGL_CONF = conf_data:find("\r#define LUAT_USE_LVGL") or conf_data:find("\n#define LUAT_USE_LVGL")
-        if LVGL_CONF then target:add("deps", "lvgl") end
+
+        import "buildx"
+        local chip = buildx.chip()
+
+        if chip.use_lvgl then target:add("deps", "lvgl") end
         target:add("deps", "miniz")
         target:add("deps", "fastlz")
-        VM_64BIT = conf_data:find("\r#define LUAT_CONF_VM_64bit") or conf_data:find("\n#define LUAT_CONF_VM_64bit")
-        local custom_data = io.readfile("$(projectdir)/app/port/luat_conf_bsp.h")
-        local TARGET_CONF = custom_data:find("\r#define AIR101") or custom_data:find("\n#define AIR101")
-        if TARGET_CONF == nil then TARGET_NAME = "AIR103" else TARGET_NAME = "AIR101" end
-        if custom_data:find("\r#define AIR601") or custom_data:find("\n#define AIR601") then
-            TARGET_NAME = "AIR601"
-        end
-        local FDB_CONF = conf_data:find("\r#define LUAT_USE_FDB") or conf_data:find("\n#define LUAT_USE_FDB") or conf_data:find("\r#define LUAT_USE_FSKV") or conf_data:find("\n#define LUAT_USE_FSKV") 
-        local USE_WLAN = conf_data:find("\r#define LUAT_USE_WLAN") or conf_data:find("\n#define LUAT_USE_WLAN") 
-        if TARGET_NAME == "AIR601" then
-            USE_WLAN = true
-        end
-        local fs_size = AIR10X_FLASH_FS_REGION_SIZE or 112
-        if FDB_CONF or fs_size > 112 then
-            local ld_data = io.readfile("./ld/"..TARGET_NAME..".ld")
-            local _origin , I_SRAM_LENGTH = ld_data:match("I-SRAM : ORIGIN = 0x(%x+) , LENGTH = 0x(%x+)")
-            local sram_size = tonumber('0X'..I_SRAM_LENGTH)
-            if FDB_CONF then
-                sram_size = sram_size - 64*1024
-            end
-            if fs_size > 112 then
-                sram_size = sram_size - (fs_size - 112) *1024
-            end
-            print("I_SRAM", sram_size // 1024)
-            local I_SRAM_LENGTH_N = string.format("%X", sram_size)
-            local ld_data_n = ld_data:gsub(I_SRAM_LENGTH,I_SRAM_LENGTH_N)
-            io.writefile("./ld/air101_103.ld", ld_data_n)
-        else
-            os.cp("./ld/"..TARGET_NAME..".ld", "./ld/air101_103.ld")
-        end
-
         
-        local ld_data = io.readfile("./ld/air101_103.ld")
-        local ORIGIN, I_SRAM_LENGTH = ld_data:match("I-SRAM : ORIGIN = 0x(%x+) , LENGTH = 0x(%x+)")
-        if USE_WLAN then
-            -- print("更新I_SRAM段的大小")
-            local I_SRAM_LENGTH_N = string.format("%X", (tonumber(I_SRAM_LENGTH, 16) - 12 * 1024))
-            local ld_data_n = ld_data:gsub(ORIGIN, "08013400")
-            ld_data_n = ld_data_n:gsub(I_SRAM_LENGTH, I_SRAM_LENGTH_N)
-            io.writefile("./ld/air101_103.ld", ld_data_n)
-            I_SRAM_LENGTH = I_SRAM_LENGTH_N
-        end
-        print("APP区总大小", I_SRAM_LENGTH, tonumber(I_SRAM_LENGTH, 16) // 1024, "kb")
+        local ld_data = io.readfile("./ld/xt804.ld")
+        local ld_data_n = ld_data:gsub("SRAM_O", string.format("0x%X", chip.flash_app_offset))
+        ld_data_n = ld_data_n:gsub("SRAM_L", string.format("0x%X", chip.flash_app_size))
+        io.writefile("./ld/air101_103.ld", ld_data_n)
 
+        TARGET_NAME = chip.target_name
         target:set("filename", TARGET_NAME..".elf")
         target:add("ldflags", flto .. "-Wl,--gc-sections -Wl,-zmax-page-size=1024 -Wl,--whole-archive ./lib/libwmarch.a ./lib/libgt.a ./lib/libwlan.a ./lib/libbtcontroller.a -Wl,--no-whole-archive -mcpu=ck804ef -nostartfiles -mhard-float -lm -Wl,-T./ld/air101_103.ld -Wl,-ckmap=./build/out/"..TARGET_NAME..".map ",{force = true})
     end)
@@ -750,6 +705,11 @@ target("air10x")
     -- add_files(opus_dir .. "bind/*.c")
 
 	after_build(function(target)
+        import "buildx"
+        local chip = buildx.chip()
+        local TARGET_NAME = chip.target_name
+        local AIR10X_VERSION = chip.bsp_version
+
         sdk_dir = target:toolchains()[1]:sdkdir().."/"
         os.exec(sdk_dir .. "bin/csky-elfabiv2-objcopy -O binary $(buildir)/out/"..TARGET_NAME..".elf $(buildir)/out/"..TARGET_NAME..".bin")
         -- 默认不生成.asm和.list,调试的时候自行打开吧
@@ -757,19 +717,19 @@ target("air10x")
         -- io.writefile("$(buildir)/out/"..TARGET_NAME..".list", os.iorun(sdk_dir .. "bin/csky-elfabiv2-objdump -h -S $(buildir)/out/"..TARGET_NAME..".elf"))
         io.writefile("$(buildir)/out/"..TARGET_NAME..".size", os.iorun(sdk_dir .. "bin/csky-elfabiv2-size $(buildir)/out/"..TARGET_NAME..".elf"))
         io.cat("$(buildir)/out/"..TARGET_NAME..".size")
-        local conf_data = io.readfile("$(projectdir)/app/port/luat_conf_bsp.h")
-        local USE_WLAN = conf_data:find("\r#define LUAT_USE_WLAN") or conf_data:find("\n#define LUAT_USE_WLAN")
-        if conf_data:find("\r#define AIR601") or conf_data:find("\n#define AIR601")  then
-            USE_WLAN = true
-        end
-        if USE_WLAN then
-            print("启用了WLAN, 更新运行区域参数")
-            os.exec("./tools/xt804/wm_tool"..(is_plat("windows") and ".exe" or "").." -b $(buildir)/out/"..TARGET_NAME..".bin -fc 0 -it 1 -ih 8013000 -ra 8013400 -ua 8012000 -nh 0 -un 0 -vs G01.00.02 -o $(buildir)/out/"..TARGET_NAME.."")
-            os.exec("./tools/xt804/wm_tool"..(is_plat("windows") and ".exe" or "").." -b  ./tools/xt804/xt804_secboot.bin -fc 0 -it 0 -ih 8002000 -ra 8002400 -ua 8012000 -nh 8013000 -un 0 -o ./tools/xt804/"..TARGET_NAME.."_secboot")
-        else
-            os.exec("./tools/xt804/wm_tool"..(is_plat("windows") and ".exe" or "").." -b $(buildir)/out/"..TARGET_NAME..".bin -fc 0 -it 1 -ih 8010400 -ra 8010800 -ua 8010000 -nh 0 -un 0 -vs G01.00.02 -o $(buildir)/out/"..TARGET_NAME.."")
-            os.exec("./tools/xt804/wm_tool"..(is_plat("windows") and ".exe" or "").." -b  ./tools/xt804/xt804_secboot.bin -fc 0 -it 0 -ih 8002000 -ra 8002400 -ua 8010000 -nh 8010400 -un 0 -o ./tools/xt804/"..TARGET_NAME.."_secboot")
-        end
+        
+        local wm_tool = "./tools/xt804/wm_tool"..(is_plat("windows") and ".exe" or "")
+        local app_image = "-fc 0 -it 1 -ih %x -ra %x -ua 8010000 -nh 0 -un 0 -vs G01.00.02 -o $(buildir)/out/%s"
+        app_image = string.format(app_image, chip.flash_app_offset - 1024, chip.flash_app_offset, chip.target_name)
+        local cmd = wm_tool.." -b $(buildir)/out/"..TARGET_NAME..".bin " .. app_image
+        print(cmd)
+        os.exec(cmd)
+        local sec_image = "-fc 0 -it 0 -ih 8002000 -ra 8002400 -ua 8010000 -nh %x -un 0 -o ./tools/xt804/%s_secboot"
+        sec_image = string.format(sec_image, chip.flash_app_offset - 1024, chip.target_name)
+        cmd = wm_tool .. " -b ./tools/xt804/xt804_secboot.bin " .. sec_image
+        print(cmd)
+        os.exec(cmd)
+
         os.cp("./tools/xt804/"..TARGET_NAME.."_secboot.img", "$(buildir)/out/"..TARGET_NAME..".fls")
         local img = io.readfile("$(buildir)/out/"..TARGET_NAME..".img", {encoding = "binary"})
         local fls = io.open("$(buildir)/out/"..TARGET_NAME..".fls", "a+")
@@ -801,33 +761,28 @@ target("air10x")
                 end
             end
             if path7z then
-                if AIR10X_FLASH_FS_REGION_SIZE or VM_64BIT then
-                    -- print("AIR10X_FLASH_FS_REGION_SIZE",AIR10X_FLASH_FS_REGION_SIZE)
-                    -- print("LUAT_SCRIPT_SIZE", LUAT_SCRIPT_SIZE)
                     local info_data = io.readfile("./soc_tools/"..TARGET_NAME..".json")
                     import("core.base.json")
                     local data = json.decode(info_data)
                     data.rom.fs.script.size = tonumber(LUAT_SCRIPT_SIZE)
-                    if TARGET_NAME == "AIR101" then
-                        offset = string.format("%X",0x81FC000-AIR10X_FLASH_FS_REGION_SIZE*1024)
+                    if chip.flash_size == 2*1024*1024 then
+                        offset = string.format("%X",0x81FC000-chip.flash_fs_size - chip.flash_script_size)
                         data.download.script_addr = offset
                         data.rom.fs.script.offset = offset
+                        data.rom.fs.script.size = chip.flash_script_size // 1024
+                        print("2M布局", "脚本区偏移量", offset)
                     else
-                        offset = string.format("%X",0x80FC000-AIR10X_FLASH_FS_REGION_SIZE*1024)
+                        offset = string.format("%X",0x80FC000-chip.flash_fs_size - chip.flash_script_size)
+                        print("1M布局", "脚本区偏移量", offset)
                         data.download.script_addr = offset
                         data.rom.fs.script.offset = offset
+                        data.rom.fs.script.size = chip.flash_script_size // 1024
                     end
-                    if VM_64BIT then
+                    if chip.use_64bit then
                         data.script.bitw = 64
                     end
                     io.writefile("./soc_tools/info.json", json.encode(data))
-                    print(json.encode(data))
-                else
-                    print("AIR10X_FLASH_FS_REGION_SIZE", "default", 112)
-                    os.cp("./soc_tools/"..TARGET_NAME..".json", "./soc_tools/info.json")
-                end
-                print("===== " .. (VM_64BIT and "VM 64bit" or "VM 32bit") .. " =====")
-                if VM_64BIT then
+                if chip.use_64bit then
                     os.cp("./soc_tools/script_64bit.img", "./soc_tools/script.img")
                 else
                     os.cp("./soc_tools/script_32bit.img", "./soc_tools/script.img")
@@ -843,11 +798,6 @@ target("air10x")
                 os.rm("./soc_tools/"..TARGET_NAME..".fls")
                 return
             end
-            
-        -- end
-        --os.rm("./ld/air101_103.ld")
-        -- os.exec("./tools/xt804/wm_tool"..(is_plat("windows") and ".exe" or "").." -b $(buildir)/out/AIR101.img -fc 1 -it 1 -ih 80D0000 -ra 80D0400 -ua 8010000 -nh 0 -un 0 -vs G01.00.02 -o $(buildir)/out/AIR101")
-        -- os.mv("$(buildir)/out/AIR101_gz.img", "$(buildir)/out/AIR101_ota.img")
     end)
 target_end()