CN105808298B - A kind of dynamic loading method of single-chip microcontroller lower module - Google Patents
A kind of dynamic loading method of single-chip microcontroller lower module Download PDFInfo
- Publication number
- CN105808298B CN105808298B CN201610131674.4A CN201610131674A CN105808298B CN 105808298 B CN105808298 B CN 105808298B CN 201610131674 A CN201610131674 A CN 201610131674A CN 105808298 B CN105808298 B CN 105808298B
- Authority
- CN
- China
- Prior art keywords
- chip microcontroller
- flash
- executable file
- code
- function
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Expired - Fee Related
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/445—Program loading or initiating
- G06F9/44521—Dynamic linking or loading; Link editing at or after load time, e.g. Java class loading
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Storage Device Security (AREA)
Abstract
The invention discloses a kind of dynamic loading methods of single-chip microcontroller lower module, comprising: S1: by the system-program code programming of single-chip microcontroller in the inside nor flash of single-chip microcontroller;S2: modular program to be loaded is compiled into system executable file, and by the corresponding binary code programming of modular program in the executable file in the external spi flash of single-chip microcontroller;S3: according to the entrance reserved in advance for the modular program to be loaded, the corresponding binary code of the modular program is read from the external spi flash of the single-chip microcontroller, and be written in the nor flash and run;The dynamic loading method can be applied to enciphering and deciphering algorithm and the fragmentation upgrading of single-chip microcontroller, have many advantages, such as that safety coefficient is high.
Description
Technical field
The present invention relates to single-chip microcontroller fields, specifically provide a kind of dynamic loading method of single-chip microcontroller lower module.
Background technique
Currently, in single-chip microcontroller field, the considerations of being in cost or other reasons, many single-chip microcontrollers do not have MMU unit (interior
Deposit administrative unit), the operating system of selection is also not virtual address space.For this kind of single address space operating system,
It can not dlm (dynamic loading module).
In the certain pairs of higher occasions of security requirement, such as encrypt, decryption portion, if encryption/decryption algorithm and system are answered
With compiling together, it is easy to crack out encryption/decryption algorithm from memory at runtime by tool.This endangers for the safety of system
Evil is self-evident.
In addition, if to upgrade to the partial function in system, it is also desirable to whole upgrading is carried out, Internet resources are given,
Storage resource, code change etc. bring risk.
Therefore, how to solve the above problems, become people's urgent problem to be solved.
Summary of the invention
In consideration of it, the purpose of the present invention is to provide a kind of dynamic loading methods of single-chip microcontroller lower module, at least to solve
Previous single-chip microcontroller there are safety coefficients it is low, upgrade job amount is big, there are risks the problems such as.
1, technical solution provided by the invention, specifically, a kind of dynamic loading method of single-chip microcontroller lower module, feature exist
In, comprising:
S1: by the system-program code programming of single-chip microcontroller in the inside nor flash of single-chip microcontroller;
S2: modular program to be loaded is compiled into system executable file and is stored in the external spi of single-chip microcontroller
In flash;
S3: according to the entrance reserved in advance for the modular program to be loaded, from the external spi flash of the single-chip microcontroller
It is middle to read the executable file, and be written in the nor flash and run.
It is preferred that the dynamic loading method of the single-chip microcontroller lower module, further includes:
S4: it after the system-program code end of run of the single-chip microcontroller, removes in the single-chip microcontroller nor flash from institute
State the executable file of spi flash reading and by the executable file treated data.
It further preferably, include: function, global variable and the function pair in the executable file in the step S2
The binary code answered;
The corresponding binary code of the function is stored in the code area of the executable file;
The address of the function is stored as offset of the function in code area relative to code area first address.
Further preferably, modular program to be loaded is compiled into system executable file in the step S2 and be stored in
When in the external spi flash of single-chip microcontroller, the LSB bit pressure of function address each in the executable file is set 0.
Further preferably, executable file is written in the nor flash in step S3 when running, it will be described executable
The LSB bit pressure of each function address sets 1 in file.
The dynamic loading method of single-chip microcontroller lower module provided by the invention, under the single address space of single-chip microcontroller, by monolithic
The system program of machine stores respectively with modular program to be loaded, calls modular program to be loaded to read the form called,
Complete the overall operation of single-chip microcontroller.In this way, making the resting period of modular program to be loaded in single-chip microcontroller memory
It is short, only exist in the of short duration time memory of system program operation, makes other people can not be from the memory (internal nor flash) of single-chip microcontroller
Middle acquisition effective information is cracked, and the safety of SCM system is improved;Meanwhile the loading method can be also used for monolithic
The fragmentation of machine upgrades, for example, the partial function interface that later system upgrade may relate to can be defined, if it is desired to
Upgrading, after the interface defined before is realized again, is made into BIN file for the code of realization, is written to the outside of single-chip microcontroller
In spi flash, after upgrading in this way, although the same function name that system is called, but the specific implementation of function is
Through becoming, this can complete part and upgrade, and reduce cost (such as Internet resources, storage resource, the code change bring of upgrading
Risk etc.).
Detailed description of the invention
Fig. 1 is the schematic diagram that modular program to be loaded is compiled into system executable file.
Specific embodiment
The guarantor that the present invention is further expalined with specific embodiment below, but is not intended to restrict the invention
Protect range.
All application programs are compiled together with system program in previous single-chip microcontroller, are collectively stored in single-chip microcontroller
In internal nor flash, due to system-program code in the inside nor flash of single-chip microcontroller (including system code and all journeys
Sequence code) it is to be arranged according to mode sequence corresponding with source file, there are a series of problems.
Such as: encryption/decryption algorithm is compiled together with system program in previous single-chip microcontroller, is collectively stored in single-chip microcontroller
In internal nor flash, due to program code in the inside nor flash of single-chip microcontroller (including system-program code and enciphering/deciphering
Code) it is to be arranged according to mode sequence corresponding with source file, so being easy to extract from program code and enciphering/deciphering letter
The relevant binary code of number, the problems such as causing encryption/decryption algorithm to be easy to be cracked, cause single-chip microcontroller safety coefficient low.
To solve the above-mentioned problems, present embodiment provides a kind of dynamic loading method of single-chip microcontroller lower module, this realities
The corresponding algorithm routine to be used for enciphering/deciphering in single-chip microcontroller of modular program to be loaded in scheme is applied, inventor studies discovery
Do not include switch sentence and library function call etc. in the above-mentioned program for encryption/decryption algorithm, meets location independence, because
This, consideration can will be used for encryption/decryption algorithm program code and be stored in the external spi flash of single-chip microcontroller, using relatively
Location is called, specific steps are as follows:
S1: by the system-program code programming of single-chip microcontroller in the inside nor flash of single-chip microcontroller;
S2: the algorithm of enciphering/deciphering to be loaded is compiled into system executable file and is stored in the external spi of single-chip microcontroller
In flash;
Referring to Fig. 1, it includes: the letter for being used for enciphering/deciphering in system executable file that encryption/decryption algorithm program, which is compiled into,
Number, global variable and the corresponding binary code of the function for enciphering/deciphering, will be used for the function two of enciphering/deciphering into
Code processed is stored in the code area (area code) of executable file, and the function address and global variable that will be used for enciphering/deciphering
Storage area is recorded in the file header of executable file, wherein the function address for enciphering/deciphering is stored as function in code area
Offset relative to code area first address, it is preferable that global variable is placed on one piece, the function for enciphering/deciphering is placed on one piece.
Wherein, the algorithm of enciphering/deciphering to be loaded is compiled into system executable file and is stored in the outside of single-chip microcontroller
When in spi flash, the LSB bit pressure of function address each in the executable file is set 0.
S3: according to being in advance the entrance reserved for encryption/decryption algorithm program, from the external spi of the single-chip microcontroller
The executable file for being used for encryption/decryption algorithm is read in flash, and is written in the nor flash and runs, and by executable text
When running in the part write-in nor flash, the LSB bit pressure of function address each in the executable file is set 1.
S4: it after the system-program code end of run of the single-chip microcontroller, removes in the single-chip microcontroller nor flash from institute
State the executable file of spi flash reading and by the executable file treated data.
In the embodiment, under the single address space of single-chip microcontroller, by the system-program code of single-chip microcontroller and it to be used for logarithm
It stores according to enciphering/deciphering program code is carried out, only needs in operating system program code using enciphering/deciphering program code respectively
When be just called, for carry out receive data enciphering/deciphering, after system application code end of run, and will call
The enciphering/deciphering program binary code and enciphering/deciphering of reading treated data dump, therefore, enciphering/deciphering program code is only
The of short duration presence in the inside nor flash of single-chip microcontroller, obtain other people can not from the inside nor flash of single-chip microcontroller has
Effect information is cracked, and being individually stored in the data in single-chip microcontroller all is to receive the data of coming, and is carried out by sending device
Encrypted data, this also considerably increases the difficulty that other people crack simultaneously, improves the safety of SCM system.
It is further explained in detail with 1 couple of present invention of a specific embodiment below:
Embodiment 1
If existing system engineering SysProject, wherein needing to use enciphering and deciphering algorithm, (place file is
Algorithm.c successively has function EncodeFun1, Func1, DeCodeFun1, and LastFun is (in end of file, to be empty, only
It is the length in order to calculate valid function)).
Specific operating process are as follows:
1, an engineering GenerateProject is additionally set up, for enciphering and deciphering algorithm to be generated Bin file;
2, algorithm.c is copied in GenerateProject;
3, GenerateBin.c is established, generating algorithm Bin is used for;
4, the binary code of algorithm is copied in external spi flash in GenerateBin.c;
Binary code about copy algorithm uses following code:
typedef struct _EncyptBin {
char EncodeFun1[4];// storage encryption function 1 is in the address in the area Code, for relative to array code's
Offset;
Char Fun1, // storage function 1 is in the address in the area Code, for the offset relative to array code; char
DecodeFun1[4];// storage decryption function 1 is in the address in the area Code, for the offset relative to array code; char
GlobalData1[n];The relevant global variable 1 of // storage; char code[code_len];The two of // storage algorithm
Carry system code; }EncyptBin;
#define offsetof (type, member) (size_t) & (((type*) 0) -> member) // acquisition
Offset of some member relative to structural body initial position in structural body;
unsigned char myGlobalData[n];// global variable;
Int loc=0, offset=0;
EncyptBin *pBin = (EncyptBin *)malloc(sizeof(EncyptBin ));
int code_len = LastFun1 - EncodeFun1;// obtain the corresponding binary system of algorithm partial code
Code length, that is, the length copied after a while;
loc = (int)offsetof(EncyptBin, code);
memcpy(pBin->EncodeFun1, &loc, 4);// put address of the EncodeFun1 in code
Into pBin- > EncodeFun1;
offset = loc + (int)Fun1 - EncodeFun1;// obtain address of the Fun1 in code;
memcpy(pBin->Fun1, &offset, 4);// by address of the Fun1 in code be put into pBin- >
In Fun1;
offset = loc + (int)DecodeFun1 - Fun1;// obtain ground of the DecodeFun1 in code
Location;
memcpy(pBin->DecodeFun1 , &offset, 4);// the ground by DecodeFun1 in code
Location is put into pBin- > DecodeFun1;
// from engineering GenerateProject produce Bin in, the code that EncodeFun1 is started corresponding two into
Code copies processed are to the area code.
// since in ARM CotexM3/M4, execution is Thumb instruction, therefore after assembler is handled, function
It is to indicate entry into ARM state to execute function that the LSB bit of location can be set automatically 1(LSB=0 by assembler, will lead to fault mistake like that
Accidentally), so carrying out copying ,Jiu Yao &0xfffffffe from the real original address of EncodeFun1 to be used;
memcpy(pBin->code, (int)EncodeFun1 & 0xfffffffe, code_len);
memcpy(pBin->GlobalData1, myGlobalData, n);// also save global variable;
FILE fp = fopen(FLASH_PATH, "Encrypt.bin", "w");// by arrange above this
A little data are written in external spi flash.
fwrite(pBin, sizeof(char), sizeof(EncyptBin), fp);
So far, the Bin of algorithm is just carried out.
5, the bin of algorithm is copied in PC from the external spi flash of single-chip microcontroller using xmodem agreement, in case with
Using afterwards (can be distributed to the people of needs by this Bin, then be used by it the external spi of xmodem deposit himself single-chip microcontroller
Flash);
6, when system program will use Encryption Algorithm, one piece of memory is dynamically first opened up in systems, from external spi flash
It is middle that algorithm Bin is read into the memory just opened up;
7, due to there being the address of correlation function in the members such as EncodeFun1, it is possible to very easily find letter
Number executes, and since what is deposited is relative address relative to the area code, so it is unrelated to also achieve position.Note that taking out function
LSB bit is set 1, just can correctly executed, reason is as described above by address.
In addition, the dynamic loading method of single-chip microcontroller lower module can also be applied to the fragmentation liter of single-chip microcontroller in the present invention
Grade, for example, the partial function interface that later system upgrade may relate to can be defined, if it is desired to upgrading, by before
After the interface defined is realized again, the code of realization is made into BIN file, is written in the external spi flash of single-chip microcontroller,
After upgrading in this way, although the same function name that system is called, but the specific implementation of function has become, this can
Upgraded with completing part, reduce the cost of upgrading (such as Internet resources, storage resource, code change bring risk etc.).
The foregoing is merely the preferred embodiment of the present invention, are not intended to restrict the invention, for this field
For technical staff, the invention may be variously modified and varied.All within the spirits and principles of the present invention, made any
Modification, equivalent replacement, improvement etc., should all be included in the protection scope of the present invention.
Claims (1)
1. a kind of dynamic loading method of single-chip microcontroller lower module characterized by comprising
S1: by the system-program code programming of single-chip microcontroller in the inside nor flash of single-chip microcontroller;
S2: modular program to be loaded is compiled into system executable file and is stored in the external spi flash of single-chip microcontroller;
S3: it according to the entrance reserved in advance for the modular program to be loaded, is read from the external spi flash of the single-chip microcontroller
The executable file is taken, and is written in the nor flash and runs;
S4: it after the system-program code end of run of the single-chip microcontroller, removes in the single-chip microcontroller nor flash from described
Executable file that spi flash is read in and by the executable file treated data;
It include: function, global variable and the corresponding binary code of the function in executable file in the step S2;
The corresponding binary code of the function is stored in the code area of the executable file;
The address of the function is stored as offset of the function in code area relative to code area first address;
Modular program to be loaded is compiled into system executable file in the step S2 and is stored in the external spi of single-chip microcontroller
When in flash, the LSB bit pressure of function address each in the executable file is set 0;
Executable file is written in the nor flash in step S3 when running, by function each in the executable file
The LSB bit pressure of location sets 1.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610131674.4A CN105808298B (en) | 2016-03-08 | 2016-03-08 | A kind of dynamic loading method of single-chip microcontroller lower module |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610131674.4A CN105808298B (en) | 2016-03-08 | 2016-03-08 | A kind of dynamic loading method of single-chip microcontroller lower module |
Publications (2)
Publication Number | Publication Date |
---|---|
CN105808298A CN105808298A (en) | 2016-07-27 |
CN105808298B true CN105808298B (en) | 2019-02-12 |
Family
ID=56467834
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610131674.4A Expired - Fee Related CN105808298B (en) | 2016-03-08 | 2016-03-08 | A kind of dynamic loading method of single-chip microcontroller lower module |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN105808298B (en) |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111124550B (en) * | 2020-03-26 | 2020-07-03 | 北京翼辉信息技术有限公司 | Program dynamic loading method and device and storage medium |
CN111856989A (en) * | 2020-06-19 | 2020-10-30 | 中电科航空电子有限公司 | Dynamic linking method for single chip microcomputer |
CN112445540B (en) * | 2020-11-10 | 2023-05-09 | 惠州市创荣发智能科技有限公司 | Program running method, system, terminal and storage medium |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102622253A (en) * | 2012-03-09 | 2012-08-01 | 瑞斯康达科技发展股份有限公司 | Singlechip and method for upgrading singlechip on line |
CN104461589A (en) * | 2013-09-17 | 2015-03-25 | 海尔集团公司 | Single-chip microcomputer updating method and system |
CN104679559A (en) * | 2015-02-11 | 2015-06-03 | 北京配天技术有限公司 | Single chip microcomputer on-line programming method |
-
2016
- 2016-03-08 CN CN201610131674.4A patent/CN105808298B/en not_active Expired - Fee Related
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102622253A (en) * | 2012-03-09 | 2012-08-01 | 瑞斯康达科技发展股份有限公司 | Singlechip and method for upgrading singlechip on line |
CN104461589A (en) * | 2013-09-17 | 2015-03-25 | 海尔集团公司 | Single-chip microcomputer updating method and system |
CN104679559A (en) * | 2015-02-11 | 2015-06-03 | 北京配天技术有限公司 | Single chip microcomputer on-line programming method |
Also Published As
Publication number | Publication date |
---|---|
CN105808298A (en) | 2016-07-27 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN108733988B (en) | Method for protecting executable program on android platform | |
CN108491235B (en) | DEX protection method combining dynamic loading and function Native | |
EP3807797B1 (en) | Pointer authentication and dynamic switching between pointer authentication regimes | |
EP2430584B1 (en) | Interlocked binary protection using whitebox cryptography | |
CN108932406B (en) | Virtualization software protection method and device | |
Checkoway et al. | Return-oriented programming without returns | |
US20160239671A1 (en) | Method and device for protecting an application and method and device for executing a protected application thus protected | |
Kornau | Return oriented programming for the ARM architecture | |
CN103413076B (en) | A kind of Android application program divides the method for block protection | |
US8090959B2 (en) | Method and apparatus for protecting .net programs | |
CN103617401B (en) | Method and device for protecting data files | |
CN105612527A (en) | Method for providing security for common intermediate language-based program | |
WO2016078130A1 (en) | Dynamic loading method for preventing reverse of apk file | |
WO2013170724A1 (en) | Method for protecting java application programs in android system | |
CN106022130A (en) | Shelling method and device for reinforced application program | |
CN109598107B (en) | Code conversion method and device based on application installation package file | |
CN107430650B (en) | Securing computer programs against reverse engineering | |
CN105808298B (en) | A kind of dynamic loading method of single-chip microcontroller lower module | |
CN111832014B (en) | Java SDK code encryption and decryption method and terminal based on dynamic loading | |
CN105608391A (en) | Multi-ELF (Executable and Linkable Format)-file protection method and system | |
WO2012151075A1 (en) | System and method for blurring instructions and data via relocation | |
CN106228041A (en) | A kind of for the precompiler code protection method of Android | |
CN111597514B (en) | An Zhuoyuan code protection method and device | |
CN114398598A (en) | Library file encryption method, decryption method and encryption device | |
CN107908954B (en) | Method for dynamically detecting memory overflow on GPU (graphics processing Unit) based on address compression technology |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
CF01 | Termination of patent right due to non-payment of annual fee |
Granted publication date: 20190212 Termination date: 20210308 |
|
CF01 | Termination of patent right due to non-payment of annual fee |