Worried about OTA failure bricking your device? Boot swap can help you
1. Introduction to Boot Swap
This article mainly explains how to use the existing program to update the firmware in the flash. Using this method, the code flash is divided into two areas: the execution area and the temporary area. The Renesas Flash Driver RL78RFD Type02 is used to reprogram the flash and perform boot swapping. This explanation mainly takes RL78/F24 as an example to explain how to implement boot swapping.
2. Introduction to RL78/F24
The RL78/F24 is a new generation of ultra-low power automotive microcontrollers, ideal for achieving future high-reliability intelligent actuators and sensors, and is the ideal choice for low-end body ECUs. As an innovative extension of the existing RL78/F1x MCU, the RL78/F24 can meet various future market demands. The RL78/F24 has higher CPU performance, high-temperature resistance, and a stronger peripheral function set, making it suitable for various applications.
The RL78/F2x series products are designed according to the ISO 26262 standard and support functional safety (FuSa) up to ASIL B. They can support security standards up to EVITA-Light or higher. The AES encryption module can handle key lengths up to 256 bits and supports secure boot and authentication functions. To further improve the computational performance of BLDC (FOC) motor control and DC/DC control systems, the RL78/F2x is equipped with a unique application accelerator IP to reduce the load caused by complex trigonometric functions and other computational processing.
3. Development Environment Introduction
Used MCU and board: As mentioned earlier, this article mainly introduces the RL78/F24 as the main control, and the board is the RL78/F24 (R7F124FPJ) Target Board.
Used software environment:
CS+ for CC V8.12.00
Renesas CC-RL Compiler v1.14.00
Smart configurator for RL78 :
Board Support Packages. -v1.62 (r_bsp)
Ports v1.5.0 (Config_PORT)
Flash Driver RL78 Type02 (Code flash, Extra Area, Common) v1.00
4. Flash Space Distribution and Upgrade Process
As mentioned earlier, the boot swap project has two areas, the execution area and the temporary area. The flash size of the RL78/F24 selected for this example is 256K, and its corresponding start and end addresses are as follows. If other sizes of MCUs are selected, they can be modified accordingly.
ROM Size | Execution Area | Temporary Area |
96KB | 0x8000 – 0xFFFF | 0x10000 – 0x17FFF |
128KB | 0x8000 – 0x13FFF | 0x14000 – 0x1FFFF |
192KB | 0x8000 – 0x1BFFF | 0x1C000 – 0x2FFFF |
256KB | 0x8000 – 0x23FFF | 0x24000 – 0x3FFFF |
384KB | 0x8000 – 0x33FFF | 0x34000 – 0x5FFFF |
512KB | 0x8000 – 0x43FFF | 0x44000 – 0x7FFFF |
768KB | 0x8000 – 0x63FFF | 0x64000 – 0xBFFFF |
Detailed Distribution of 256KB Flash:
Upgrade Process:
Erase boot cluster1 and temporary area
Write new firmware to boot cluster1 and temporary area
Erase the execution area
Copy the contents of the temporary area to the execution area
Execute the boot swap command to swap the new boot area program to boot cluster0
Run the new firmware code
5. Implementation Steps
The entire upgrade process was explained earlier, and the specific implementation steps will be explained next. First, create an original project containing Boot+APP1. By checking the schematic diagram of the board, there are LED1 and LED2 on the board that can be used as upgrade success indicators. When Boot+APP1 is running, LED1 flashes, and after the upgrade is successful, LED2 flashes, indicating that the new Boot+APP2 is running. The pin configuration needs to be added in the Smart configurator, as shown below, P66 and P67 are set to out:
The upgrade requires UART, add UART0, and configure it as follows:
At the same time, RFD type02 is needed, add it as follows:
After adding all the peripheral drivers, the section needs to be modified.
The following sections to be included in the ROM.
The sections to be included in the RAM.
After adding the corresponding sections, the corresponding ROM section needs to be manually copied to RAM. The method is as follows, repeat the code in the red box, and copy a total of 5 sections, namely: RFD_CMN_f, RFD_CF_f, RFD_EX_f, SMP_CMN_f, SMP_CF_f.
Modify the “r_cg_userdefine.h” file according to the selected MCU.
Modify the APP, in the userApplicationLoop, you can choose LED1 flashing to indicate APP1 running, and LED2 flashing to indicate APP2 running after the upgrade.
The overall code implementation will not be repeated. After all the code is completed, compile and download it to RL78/F24. Use E2-Lite to connect the board for downloading and debugging, and use the serial port tool to transfer the upgrade file. The detailed hardware connections are shown in the figure below.
After all operations are normal, the LED starts flashing
Next, create a new APP2 for the upgrade. Change the codes in userApplicationLoop() to make LED2 flash.
Use the following steps to generate the .bin file of APP2. In Hex Format->Hex file format, select Binary file, and fill it with 0xFF.
After building, a .bin file will be outputed in the corresponding folder.
Disconnect E2-Lite, connect the serial port tool, P61:TXD, P62:RXD, EVDD:3.3V, GND:GND.
Run BootSwapGUI.exe, select 256K, select the corresponding COM, and open the previously generatedbin file.
Click START, observe the progress bar, and after completion, the MCU will automatically complete the boot swap action. Finally, observe LED2, and LED2 starts flashing, indicating that the upgrade is successful. During the upgrade process, LED1 has not stopped flashing, indicating that this method does not affect the operation of the previous version during the whole upgrade process.
6. Summary
Boot swap is a specialized firmware upgrade method for MCUs developed by Renesas. The primary advantage of this method is that it does not require interrupting the current application operation while receiving new firmware, which is crucial for many applications. Additionally, during the conventional reprogramming (upgrade) process, external factors such as resets or power failures can occur, leading to data corruption in the interrupt vector table, basic functions, etc. Any data corruption may result in the MCU not starting normally. Regarding the characteristics of boot swap, it effectively mitigates this risk. This method ensures that the MCU always has a complete, operational boot cluster1 and app1. Consequently, another significant advantage of boot swap is its ability to prevent the MCU from becoming "bricked" due to upgrade failures.