Hello everyone, I am a ruffian balance, is a serious technical ruffian. Today ruffian balance to share with you is the use of IAR with CRC integrity check function of a practice (for KBOOT plus BCA).
Ruffian Heng has written two articles about the CRC check function in IAR “method of opening CRC integrity check function for the project in the IAR development environment”, “Analysis of opening CRC integrity check IAR project generated.out and.bin file sequence”, which is to introduce the details of this function more clearly. But as the saying goes, no matter how much you know in theory, you can’t put it into practice. Ruffian balance today uses this function to solve a practical need:
1. Fill the BCA in KBOOT with CRC verification requirements
Speaking of this demand, remember that it was the first snow of 2014, when Ruffian was working on the Kinetis Bootloader (KBOOT) project at Freescale software group, for which Ruffian had written some articles. Kinetis was Freescale’s Cortex-M microcontroller, and KBOOT was the fully functional Bootloader designed for Kinetis. This is probably the first well-designed generic architecture Bootloader in the embedded world. This Bootloader contains a user configuration function (BCA), which simply stores some Bootloader configuration in the 16 Word of user Application offset 0x3C0-0x3FF. When Bootloader runs, it will first try to read these 16 Words from the Application area to obtain the user configuration (timeout period, peripheral type, ID, speed option, etc.), and then start or upgrade the user Application according to the user configuration.
The CRC integrity check function takes up 12 bytes in the BCA, which is a very important Bootloader feature. See “KBOOT Features (Integrity Check)” for its complete function. Instead of adding a second edit to the final binary file as before.
Let’s take MK64FN1M as an example, download its software package, which contains KBOOT and its example Application, Find the Application project under \ sdk_2.8.2_frdM-k64f \boards\ FRDMk64f \bootloader_examples\demo_apps\led_demo_freedom_a000\ iAR Defined in the project source files startup_MK64F12. S __bootloaderConfigurationArea, but the CRC area is 0 XFF (that is, can not make), compile the generated bin file is 0 XFF all CRC area, we need to do is fill in the correct CRC.
Two, start hands-on practice
2.1 Determine matched CRC algorithm parameter Settings
The specific CRC algorithm can be found in the KBOOT user manual. It uses the more mainstream CRC32-MPEG2 branch. The specific parameters are shown in the following table:
In order to facilitate the check results, Ruffian scale found an online CRC calculation website, using this website, set CRC parameters consistent with KBOOT (in the red box below), and then we select led_demo_freedom_a000.bin first 16 bytes (in the blue box below) as the test data input. Click the Calculate CRC button to generate the result 0x8D96BDF0 (in the purple box below).
Online website: http://www.sunshine2k.de/coding/javascript/crc/crc_js.htmlCopy the code
Led_demo_freedom_a000 (Checksum, Checksum, Checksum, Checksum, Checksum, Checksum) So the first 16 bytes in the final.bin). Refer to the IAR Development manual and make the following CRC algorithm parameter Settings. The result of compilation project is also 0x8D96BDF0, so the CRC Settings are matched.
2.2 First attempt to populate the BCA
With the CRC Settings confirmed, it is now time to modify the source code. In the CRC area of the BCA, replace all the initial 0xFF values with the real CRC values __checksum, __checksum_BEGIN, and __checksum_end. The code is simply modified as follows. Bin = 0x0000a7fc = 0x0000a7fc = 0x0000a7fc = 0x0000a7fc = 0x0000a7fc = 0x0000a7fc = 0x0000a7fc If you think about it, the CRC check value is computed after the link is generated for bin, but the source file is compiled before the link, so it is not possible to get the result after the link is compiled.
- Note: There is a clerical error in the figure above, line 306 of assembly code on the left should be changed to (__checksum_end-__checksum_begin + 1) because this is crcByteCount, same below.
2.3 Final scheme for filling BCA
When the first attempt fails, it is not as simple as it might seem. We need to do some work on the project link file and link __checksum directly to the specific offset in the BCA. Therefore startup_MK64F12. S __bootloaderConfigurationArea from crcExpectedValue and after all, and actually don’t need __FlashConfig (only for links in 0 address is valid, This is Kinetis characteristic).
Then we need to re-define an array of BCA constants in main.c to add all the bCA data that are missing except the crcExpectedValue.
const uint32_t bca[16] @ ".bca_left" = {0x1388ffff.0xffffffff.0xffffffff.0xffffffff.0xffffffff.0xffffffff.0xffffffff.0xffffffff.0xffffffff.0xffffffff.0xffffffff.0xffffffff.0xffffffff.0xffffffff.0xffffffff.0xffffffff};
Copy the code
Finally we need to modify the link file mk64fn1m0XXx12_application_0xA000. icf as follows:
//place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec, readonly section .noinit };
//place in FLASH_region { block ApplicationFlash };
place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };
place at address mem:0xa3cc { ro section .checksum };
place at address mem:0xa3d0 { ro section .bca_left };
place in FLASH_region { readonly section .noinit, block ApplicationFlash };
Copy the code
BCA is the correct CRC value (0xf62ce2b6). The first 16 bytes of bin have been changed due to the change of source code. The next step is to simply adjust the range of CRC calculations you want in the CRC Settings screen.
At this point, the use of IAR with CRC integrity check function of a practice (for KBOOT plus BCA) ruffian balance will be introduced, applause where ~~~
Welcome to subscribe to
The article will be published on my blog park homepage, CSDN homepage, Zhihu homepage and wechat public account at the same time.
Wechat search “ruffian balance embedded” or scan the following two-dimensional code, you can see the first time on the phone oh.