Detailed description of the boot function of the MDK Compiler

Source: Internet
Author: User

A few days ago, I talked to people in a technical group:
The MDK compiler will also do some bootloader work, and a large group of students will immediately "discuss and correct ", some students say that the vendor has provided the corresponding Startup file, and the corresponding Bo is completed.
For the startup of otloader, some say that the factory Chamber of Commerce will launch the bootloader which is not part of the Startup Program in the internal chip, and some may say that the hardware will directly perform the boot data migration. Students, even if you guess, you have to guess more reliable !!
Of course, these statements are all false, in fact, in the Startup File of arm-None-liunx-GCC, there will be corresponding data section Ram migration (I have done m3 and 4 series development under GCC ), in the MDK, the startup file does not provide that part of the code. I will explain the specific reason below. Many developers only program in the GUI environment or do not have the ability to think independently, some bad habits have been developed. These habits will influence personal judgment after they are deep-rooted. These habits will deeply influence those who are also cloud-oriented and will not be firm. :(
The reason is very simple. MDK made a step during compilation. In the MDK setting column "option for target xxx/target", fill in the flash and ram addresses, generally, this setting is based on a specific device and generally does not need to be modified, but it is very important for the MDK compiler, this is because the scatter file generated by this part will be used during compilation, and it will automatically generate the code for data migration. This problem is quite simple if you want to verify it, you can check the disassembly code. Here I will paste some code for you to see:

0x08000138 a00a ADR r0, {PC} + 4; @ 0x08000164
0x0800013a e8900c00 LDM r0, {r10-r11}
0x0800013e 4482 add R10, R10, R0
0x08000140 4483 add R11, R11, R0
0x08000142 f1aa0701 sub R7, R10, #0x01
_ Scatterload_null:
0x08000146 45da CMP R10, R11
0x08000148 D101 BNE 0x0800014e
0x0800014a f000f83f BL. W _ rt_entry (0x080001cc)
0x0800014e f2af0e09 ADR. w lr, {PC}-0x07; @ 0x08000147
0x08000152 e8ba000f LDM R10 !, {R0-r3}
0x08000156 f0130f01 TST R3, #0x01
0x0800015a bf18 it ne
0x0800015c 1afb subne R3, R7, r3
0x0800015e f00000301 Orr R3, R3, #0x01
0x08000162 4718 BX r3
0x08000164 1d60 dcw 0x1d60
0x08000166 0000 dcw 0x0000
0x08000168 1d80 dcw 0x1d80
0x0800016a 0000 dcw 0x0000

_ Decompress:
0x0800016c using a add R2, R2, r1
0x0800016e f8127b01 ldrb R4, [R0], #0x01
0x08000172 f014050f ands R5, R4, # 0x0f
0x08000176 bf08 it EQ
0x08000178 f8105b01 ldrbeq R5, [R0], #0x01
0x0800017c 0924 lsrs R4, R4, #4
0x0800017e bf08 it EQ
0x08000180 f8127b01 ldrbeq R4, [R0], #0x01
0x08000184 1e6d subs R5, R5, #1
0x08000186 d005 beq 0x08000194
0x08000188 f8103b01 ldrb R3, [R0], #0x01
0x0800018c 1e6d subs R5, R5, #1
0x0800018e f8013b01 strb R3, [R1], #0x01
0x08000192 d1f9 BNE 0x08000188
0x08000194 1e64 subs R4, R4, #1
0x08000196 d003 beq 0x080001a0
0x08000198 1e64 subs R4, R4, #1
0x0800019a f8015b01 strb R5, [R1], #0x01
0x0800019e d1fb BNE 0x08000198
0x080001a0 4291 CMP R1, R2
0x080001a2 d3e4 BCC 0x0800016e
0x080001a4 4770 BX lR
0x080001a6 0000 movs r0, R0
_ Scatterload_zeroinit:
0x080001a8 2300 movs R3, #0x00
0x080001aa 2400 movs R4, #0x00
0x080001ac 2500 movs R5, #0x00
0x080001ae 2600 movs R6, #0x00
0x080001b0 3a10 subs R2, R2, #0x10
0x080001b2 bf28 it cs
0x080001b4 c178 stmcs R1 !, {R3-r6}
0x080001b6 d8fb BHI 0x080001b0
0x080001b8 0752 lsls R2, R2, #29
0x080001ba bf28 it cs
0x080001bc C130 stmcs R1 !, {R4-r5}
0x080001be bf48 it Mi
0x080001c0 600b strmi R3, [R1, #0x00]
0x080001c2 4770 BX lR

There will be a piece of automatically generated code, which does not exist in the code you write. Its main function is to move the data section data in flash to ram, which is automatically generated by the compiler! I hope that later students will not make such mistakes any more.

 

Detailed description of the boot function of the MDK Compiler

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.