项目系统架构搭好了,咱们就开始动手实践吧!
实现固件升级需要用到UBoot引导加载程序,因此,首先我们先创建一个项目实现UBoot功能。
目录
一、新建项目配置
项目在e2 studio创建,创建过程不再详述啦!FSP版本不必纠结,基本上大同小异变化不是太大,推荐使用近期发行的版本。项目配置信息如下:
二、新增MCUBoot
添加模块:
三、配置MCUBoot属性
Downgrade Prevention(Overwrite Only):设置为Disabled,关闭是为了日后异常可以灵活处理,回退版本。
Signing and Encryption Options选项下的内容没有启用,固件需要加密打包的,就没有必要使用签名加密了。
配置g_flash0属性:
关闭掉Data Flash Programming Enable可以减少固件尺寸,在项目中也用不到data flash。
配置完成,点击生成项目内容:
四、配置项目属性
配置完成后,点击应用关闭。
五、编写启动函数
在hal_entry.c中编写函数mcuboot_quick_setup
void mcuboot_quick_setup()
{
#ifdef MCUBOOT_USE_MBED_TLS
/* Initialize mbedtls. */
mbedtls_platform_context ctx = {0};
assert(0 == mbedtls_platform_setup(&ctx));
#elif (defined(MCUBOOT_USE_TINYCRYPT) && defined(RM_MCUBOOT_PORT_USE_TINYCRYPT_ACCELERATION))
/* Initialize TinyCrypt port. */
assert(FSP_SUCCESS == RM_TINCYRYPT_PORT_Init());
#elif (defined(MCUBOOT_USE_USER_DEFINED_CRYPTO_STACK))
/* Initialize Custom Crypto (Protected Mode) driver. */
assert(FSP_SUCCESS == R_SCE_Open(&sce_ctrl, &sce_cfg));
#endif
/* (Optional, not required if --pad is used during signing) To check for updates, call boot_set_pending. */
bool update = 0;
if (update)
{
boot_set_pending(0);
}
/* Verify the boot image and get its location. */
struct boot_rsp rsp;
assert(0 == boot_go(&rsp));
/* Enter the application. */
RM_MCUBOOT_PORT_BootApp(&rsp);
}
/*******************************************************************************************************************//**
* main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function
* is called by main() when no RTOS is used.
**********************************************************************************************************************/
void hal_entry(void)
{
/* TODO: add your own code here */
mcuboot_quick_setup();
#if BSP_TZ_SECURE_BUILD
/* Enter non-secure code */
R_BSP_NonSecureEnter();
#endif
}
六、编译工程
编译输出结果:
七、编译问题解决
使用FSP5.1编译会出现找不到头文件rm_tinycrypt_port_cfg.h,用来做加密配置的,咱也没用到,注释掉就行啦!
八、工程源码
RA6M5_MCUBoot工程源代码https://download.csdn.net/download/xtudj/90492983