--- sdk_folder/app/main. c dmeo 程序
/*****************************************************************************
*
* File Name : main. c
*
* Description: main
*
* Copyright (c) 2014 Winner Micro Electronic Design Co. , Ltd.
* All rights reserved.
*
* Author : dave
*
* Date : 2014-6-14
*****************************************************************************/
#include "wm_include. h"
#include "wm_cpu. h"
#include "wm_internal_flash. h"
#include "wm_fwup. h"
void UserMain (void)
{
extern void tls_sys_clk_set () ;
extern u32 tls_mem_get_avail_heapsize (void) ;
tls_sys_clk_set (CPU_CLK_80M) ;
printf ("\n \\\\\\|///\n") ;
printf (" \\\\ . -. - //\n") ;
printf (". ( . @. @ ) \n") ;
printf ("+-------oOOo----- (_) -----oOOo---------+\n\n") ;
printf (" --- Compile "__DATE__", "__TIME__"\n") ;
printf (" --- %s. c\r\n", __func__) ;
printf (" --- GetHeap: %d\n", tls_mem_get_avail_heapsize () ) ;
printf ("\n+---------------------Oooo------------+\n") ;
printf ("\n user task\n") ;
IMAGE_HEADER_PARAM_ST img;
tls_fls_read (0x81E0000UL, &img, 64) ;
printf ("--- magic_no %08X\n", img. upd_no) ;
printf ("--- img_addr %08X\n", img. img_addr) ;
printf ("--- img_len %08X\n", img. img_len) ;
printf ("--- img_header_addr %08X\n", img. img_header_addr) ;
printf ("--- upgrade_img_addr %08X\n", img. upgrade_img_addr) ;
printf ("--- org_checksum %08X\n", img. org_checksum) ;
printf ("--- upd_no %08X\n", img. upd_no) ;
printf ("--- _reserved0 %08X\n", img. _reserved0) ;
printf ("--- _reserved1 %08X\n", img. _reserved1) ;
printf ("--- next %08X\n", img. next) ;
printf ("--- hd_checksum %08X\n\n", img. hd_checksum) ;
tls_fls_read (img. next, &img, 64) ;
printf ("--- magic_no %08X\n", img. upd_no) ;
printf ("--- img_addr %08X\n", img. img_addr) ;
printf ("--- img_len %08X\n", img. img_len) ;
printf ("--- img_header_addr %08X\n", img. img_header_addr) ;
printf ("--- upgrade_img_addr %08X\n", img. upgrade_img_addr) ;
printf ("--- org_checksum %08X\n", img. org_checksum) ;
printf ("--- upd_no %08X\n", img. upd_no) ;
printf ("--- _reserved0 %08X\n", img. _reserved0) ;
printf ("--- _reserved1 %08X\n", img. _reserved1) ;
printf ("--- next %08X\n", img. next) ;
printf ("--- hd_checksum %08X\n\n", img. hd_checksum) ;
tls_fls_read (img. next, &img, 64) ;
printf ("--- magic_no %08X\n", img. upd_no) ;
printf ("--- img_addr %08X\n", img. img_addr) ;
printf ("--- img_len %08X\n", img. img_len) ;
printf ("--- img_header_addr %08X\n", img. img_header_addr) ;
printf ("--- upgrade_img_addr %08X\n", img. upgrade_img_addr) ;
printf ("--- org_checksum %08X\n", img. org_checksum) ;
printf ("--- upd_no %08X\n", img. upd_no) ;
printf ("--- _reserved0 %08X\n", img. _reserved0) ;
printf ("--- _reserved1 %08X\n", img. _reserved1) ;
printf ("--- next %08X\n", img. next) ;
printf ("--- hd_checksum %08X\n\n", img. hd_checksum) ;
u8 data[1024]={0};
tls_fls_read (img. img_addr, &data, 1024) ;
for (int i = 0; i 1024; i++)
{
printf ("%02X ", data[i]) ;
}
printf ("\n") ;
#if DEMO_CONSOLE
CreateDemoTask () ;
#endif
//用户自己的 task
}
--- sdk_folder/tools/w800/conf. mk 增加文件路径
SECBOOT_HEADER_POS=8002000
SECBOOT_ADDRESS_POS=8002400
SEC_BOOT_BIN : = $ (SDK_TOOLS) /w800_secboot. bin
SEC_BOOT_IMG : = $ (SDK_TOOLS) /w800_secboot
SEC_BOOT : = $ (SDK_TOOLS) /w800_secboot. img
FILE1_HEADER_POS=8020000
FILE1_ADDRESS_POS=8020400
FILE1_BIN : = $ (SDK_TOOLS) /file/file1. bin
FILE1_IMG : = $ (SDK_TOOLS) /file/file1
FILE1 : = $ (SDK_TOOLS) /file/file1. img
FILE2_HEADER_POS=8020800
FILE2_ADDRESS_POS=8020C00
FILE2_BIN : = $ (SDK_TOOLS) /file/file2. bin
FILE2_IMG : = $ (SDK_TOOLS) /file/file2
FILE2 : = $ (SDK_TOOLS) /file/file2. img
FILE3_HEADER_POS=8030000
FILE3_ADDRESS_POS=8030400
FILE3_BIN : = $ (SDK_TOOLS) /file/file3. bin
FILE3_IMG : = $ (SDK_TOOLS) /file/file3
FILE3 : = $ (SDK_TOOLS) /file/file3. img
--- sdk_folder/tools/w800/rules. mk 修改固件生成脚本
ifeq ($ (CODE_ENCRYPT) , 1)
@openssl enc -aes-128-ecb -in $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) . bin -out $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _enc. bin -K 30313233343536373839616263646566 -iv 01010101010101010101010101010101
@openssl rsautl -encrypt -in $ (CA_PATH) /key. txt -inkey $ (CA_PATH) /capub_$ (PRIKEY_SEL) . pem -pubin -out $ (FIRMWAREDIR) /$ (TARGET) /key_en. dat
@cat $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _enc. bin $ (FIRMWAREDIR) /$ (TARGET) /key_en. dat $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _enc_key. bin
@cat $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _enc_key. bin $ (CA_PATH) /capub_$ (PRIKEY_SEL) _N. dat $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _enc_key_N. bin
@$ (WM_TOOL) -b $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _enc_key_N. bin -it $ (IMG_TYPE) -fc 0 -ra $ (RUN_ADDRESS) -ih $ (IMG_HEADER) -ua $ (UPD_ADDRESS) -nh 0 -un 0 -vs $ (shell $ (VER_TOOL) $ (TOP_DIR) /platform/sys/wm_main. c) -o $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET)
else
@$ (WM_TOOL) -b $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) . bin -fc 0 -it $ (IMG_TYPE) -ih $ (IMG_HEADER) -ra $ (RUN_ADDRESS) -ua $ (UPD_ADDRESS) -nh $ (FILE1_HEADER_POS) -un 0 -vs $ (shell $ (VER_TOOL) $ (TOP_DIR) /platform/sys/wm_main. c) -o $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET)
endif
@cp $ (IMAGEODIR) /$ (TARGET) . map $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) . map
@$ (WM_TOOL) -b $ (SEC_BOOT_BIN) -fc 0 -it 0 -ih $ (SECBOOT_HEADER_POS) -ra $ (SECBOOT_ADDRESS_POS) -ua $ (UPD_ADDRESS) -nh $ (IMG_HEADER) -un 0 -o $ (SEC_BOOT_IMG)
@$ (WM_TOOL) -b $ (FILE1_BIN) -fc 0 -it $ (IMG_TYPE) -ih $ (FILE1_HEADER_POS) -ra $ (FILE1_ADDRESS_POS) -ua $ (UPD_ADDRESS) -nh $ (FILE2_HEADER_POS) -un 0 -o $ (FILE1_IMG)
@$ (WM_TOOL) -b $ (FILE2_BIN) -fc 0 -it $ (IMG_TYPE) -ih $ (FILE2_HEADER_POS) -ra $ (FILE2_ADDRESS_POS) -ua $ (UPD_ADDRESS) -nh $ (FILE3_HEADER_POS) -un 0 -o $ (FILE2_IMG)
@$ (WM_TOOL) -b $ (FILE3_BIN) -fc 0 -it $ (IMG_TYPE) -ih $ (FILE3_HEADER_POS) -ra $ (FILE3_ADDRESS_POS) -ua $ (UPD_ADDRESS) -nh 0 -un 0 -o $ (FILE3_IMG)
ifeq ($ (SIGNATURE) , 1)
@openssl dgst -sign $ (CA_PATH) /cakey. pem -sha1 -out $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _sign. dat $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) . img
@cat $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) . img $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _sign. dat $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _sign. img
@cat $ (SEC_BOOT) $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _sign. img $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) . fls
@$ (WM_TOOL) -b $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _sign. img -fc 1 -it $ (IMG_TYPE) -ih $ (IMG_HEADER) -ra $ (RUN_ADDRESS) -ua $ (UPD_ADDRESS) -nh 0 -un 0 -vs $ (shell $ (VER_TOOL) $ (TOP_DIR) /platform/sys/wm_main. c) -o $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _sign
@mv $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _sign_gz. img $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _sign_ota. img
else
@cat $ (SEC_BOOT) $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) . img $ (FILE1) $ (FILE2) $ (FILE3) $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) . fls
@$ (WM_TOOL) -b $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) . img -fc 1 -it $ (IMG_TYPE) -ih $ (IMG_HEADER) -ra $ (RUN_ADDRESS) -ua $ (UPD_ADDRESS) -nh 0 -un 0 -vs $ (shell $ (VER_TOOL) $ (TOP_DIR) /platform/sys/wm_main. c) -o $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET)
@mv $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _gz. img $ (FIRMWAREDIR) /$ (TARGET) /$ (TARGET) _ota. img
endif
--- sdk_folder/tools/w800/file 增加 file 文件夹放置用户数据 bin 文件
--- 编译下载固件
你好, 我这边按照上述修改, 烧录进去不生效, 还需要修改其他的地方吗.
@liu666 哪里不生效, 得去排查, 没有其他地方了哦
@isme
FILE1_HEADER_POS=8020000
FILE1_ADDRESS_POS=8020400
这两个地址分别代表什么意思?
固件是由多个 img 文件组成, img 文件由 bin 文件+头文件 (一个结构体, 给对应 bin 解释) , 合并烧录用户数据, 需要把用户数据打包成 img 格式, FILE1_HEADER_POS 为用户数据头的存储位置, 而 FILE1_ADDRESS_POS=8020400 为用户数据的实际存储地址.
@isme 您好, 请问一下烧录的 bin 包大小有要求吗, 我这边合并了一个非常小的 bin 包, 烧录后使用 tls_fls_read (0x88FFC00UL, &img, 64) 读出来是错误的. 烧录大的 bin 包不会出现这个问题
@liu666 不能小于 1024