当前位置:网站首页>MCU firmware packaging Script Software
MCU firmware packaging Script Software
2022-07-01 02:41:00 【Big orange madness】
1 Preface
To develop the MCU After software , Usually generated hex Documents or bin file , Used for firmware burning or upgrading , If used for product development , When it comes to the firmware version , Beginners usually use firmware file renaming to distinguish versions .
If you need to write the version to the firmware , It needs to be realized in a certain way , There are many ways to achieve it .
2 Introduce
The following describes a script software that automatically packs firmware , It mainly realizes the following functions :
- be based on Windows Single chip microcomputer of the platform MCU Firmware script packaging tool
- Support hex File clipping and hex Consolidation of documents
- It can be for hex Add firmware version information 、Git Commit Branch and submit records, etc
- Name according to version information hex The firmware , Generative bin Documents, etc.
- The above can be passed ini Configuration file setting parameter pair hex File operation
3 Implementation steps
Let's say MDK + STM32 Development as an example .
3.1 __attribute__ Mechanism
First of all, let's get to know __attribute__ Mechanism , It's a compiler directive , Tell the compiler about the declared features , Or let the compiler do more error checking and advanced optimization .
GUN C Can be used in __attribute__() To the variable 、 Functions and types set various properties , and __attribute__ Of section Option to change the properties of the segment ;
among __attribute__((section("section_name"))) Is used to put the defined function or data variable into the specified name ”section_name” In the paragraph .
Whether it's GNU still ARM The compiler , All support
__attribute__The specified compilation properties .
open keil Of options…, Uncheck... As shown in the following figure , And then click “Edit…”.

Automatic pop-up “*.sct” file ( Compile first and then operate ), The following is Keil in STM32 Link file for , The compiler will base on the linked file and __attribute__ Of section Options ( You can add a segment by yourself , Assign address and size ) The address of the assignment function and data variable in the program firmware .
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x08000000 0x00010000 { ; load region size_region
ER_IROM1 0x08000000 0x00010000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
.ANY (+XO)
}
RW_IRAM1 0x20000000 0x00005000 { ; RW data
.ANY (+RW +ZI)
}
} I won't give you too much introduction here , The methods described below do not need to be modified “*.sct” file , Or adopt __attribute__ Of section Options , But in section You can specify the position in the options .
__attribute__ ((section(".ARM.__at_0x08000020")))3.2 Code implementation
1. Define a structure , It defines some software version related information
typedef struct
{
char szVersion[32]; // Software version
char szBuildDate[32]; // Program compilation date
char szBuildTime[32]; // Program compilation time
char szCommitId[32]; // git commit id
}AppInfo_t;2. adopt __attribute__ Define a read-only structure variable ( Read only purpose : Prevent program changes 、 save RAM), Assign initial value to ( among __DATE_ and __TIME__ yes C Built in macros in languages , They are the current compilation date and compilation time ).
const AppInfo_t __attribute__ ((section(".ARM.__at_0x08002000"))) sg_tAppInfo =
{
"STM32_TEST",
__DATE__,
__TIME__,
""
};notes :STM32 The starting address of the code is from 0x08000000 At the beginning , And store interrupt vector table information , Therefore, when selecting the program address, you must avoid , Not too far back , Otherwise, it's generated bin The file exceeds the actual code firmware size , In the realization of bin File upgrade will take too long .
3. Print it out through the serial port
int main(void)
{
FML_USART_Init();
USART_Printf(0, "Version : %s\r\n", sg_tAppInfo.szVersion);
USART_Printf(0, "buildTime: %s\r\n", sg_tAppInfo.szBuildDate);
USART_Printf(0, "buildTime: %s\r\n", sg_tAppInfo.szBuildTime);
USART_Printf(0, "commitId: %s\r\n\r\n", sg_tAppInfo.szCommitId);
while(1);
}4. Submit git After compiling , You can see git commit id value ( adopt git commit You can quickly locate when the source code was compiled )

3.3 Firmware packaging
Download firmware packaging script , According to the configuration settings , double-click bat You can complete the firmware packaging , Then click download to verify .
Need to pass through J-LINK Kit or ST-Link The tool opens the generated firmware for burning ( adopt Keil It is useless to compile and download directly , What I use here is ST-Link Tools ).

4 Profile contents
Here are the options in the configuration file
; The paths in this paper can be absolute paths or relative paths ( Relative to firmware packaging bat In terms of documents )
; Version information Flash Initial address Reserved size Prefix string
[version]
addr=0x08002000
size=32
strPrefix=
; Git Information Flash Initial address Reserved size
[git_commit]
addr=0x08002060
size=32
[boot_file]
; Boot Hex File path File name
hexFilePath=.\
hexFileName=test_boot
[file]
; Hex File path File name
hexFilePath=.\
hexFileName=test
; Crop start address Keep the size
hexFileAddr=0x08000000
hexFileSize=0xFFFF
; The output path of the package file
outputPath=.\output
[option]
; Whether to merge boot The firmware
isMergeBootHexFile=0
; Whether to generate Bin file
isGenerateBin=1
; Crop or not Hex file , according to (hexFileAddr hexFileSize)
isCropHexFile=1
; Whether to add Git Commit Information
isAddGitCommit=0
; Whether to clear temporary files after successful packaging
isClearTmpFile=15 Download address
MCU Firmware packaging script
https://gitee.com/const-zpc/mcu-pack-script
边栏推荐
- What is the difference between port number and process number?
- PCB defect detection based on OpenCV and image subtraction
- Mouse over effect IV
- Dell server restart Idrac method
- Lenovo x86 server restart management controller (xclarity controller) or TSM method
- Detailed data governance knowledge system
- Mouse over effect III
- How do I open an account on my mobile phone? Also, is it safe to open an account online?
- 鼠标悬停效果七
- What are the top ten securities companies? In addition, is it safe to open an account online now?
猜你喜欢
随机推荐
使用ipmitool配置X86服务器的BMC网络和用户信息
Rocketqa: cross batch negatives, de noised hard negative sampling and data augmentation
Pulsar geo replication/ disaster recovery / regional replication
Machine learning 9-universal approximator radial basis function neural network, examining PDA and SVM from a new perspective
SSH configuration password free login error: /usr/bin/ssh copy ID: error: no identities found solution
Comment réaliser la liaison entre la serrure intelligente et la lampe, la scène du moteur de rideau intelligent dans le timing intelligent?
Contrastive learning of Class-agnostic Activation Map for Weakly Supervised Object Localization and
I want to know how to open a stock account? Is it safe to open an account online?
import tensorflow. contrib. Slim as slim error
鼠标悬停效果九
[graduation season · advanced technology Er] - summary from graduation to work
The image variables in the Halcon variable window are not displayed, and it is useless to restart the software and the computer
Pytoch -- foundation refers to the north_ II. What high school students can understand [back propagation and gradient descent]
VirtualBox installation enhancements
What is PMP?
Sampling Area Lights
如何在智汀中实现智能锁与灯、智能窗帘电机场景联动?
Mouse over effect IV
@The difference between configurationproperties and @value
鼠标悬停效果六








