【朝花夕拾】RT1170 SBL ISP下载代码做remap功能

一,文档简介

之前写过一篇关于使用官方SBL ISP方式下载APP的帖子:
【朝花夕拾】RT1170 SBL ISP下载带SDRAM APP
最近有客户同样需要使用RT1170 SBL ISP下载代码,但是需要下载的代码app是基于MCUXpresso IDE,生成bin文件,可以烧写到flash不同位置,然后使用remap去做对应app的运行。
关于remap,从SBL的文档中可以知道,RT1170是能够直接支持的:
在这里插入图片描述图1
通常,如果结合SFW做SD卡,云端等app更新,可以直接支持remap功能。因为SFW目前只支持IAR和MDK两个IDE,不支持MCUXPresso IDE,所以,对于客户使用MCUXPresso开发的app也不是特别方便,而且,客户也不需要使用SD卡,网络云端去更新代码,SBL的ISP更新已经能够满足。所以如何使用SBL去实现两个MCUXpresso app的remap功能呢?对于MCUXpresso App可以使用一个工程,这样只要少许修改内容来辨别是不同的app,烧录到不同的flash地址即可。下面给出具体的实现方法与步骤。
SBL,APP1,APP2代码的空间结构如下:
在这里插入图片描述

图2

二,SBL操作与修改

2.1 SBL配置与下载

参考文章第2.1章: 【朝花夕拾】RT1170 SBL ISP下载带SDRAM APP
生成好对应的sbl iar工程。

2.2 SBL 添加remap 代码

打开文件:sbl-master\boot\sbl_boot.c
int sbl_boot_main(void)代码修改如下代码:

int sbl_boot_main(void)
{
  char ch = 0;
	struct image_header br_hdr1 = {
		.ih_hdr_size = 0x2000
	};
	struct boot_rsp rsp = {
		.br_hdr = &br_hdr1,
		.br_flash_dev_id = 1,
		.br_image_off = 0x80000
	};
	int rc = 0;

#ifdef CONFIG_BOOT_SIGNATURE
#if defined(SOC_IMXRTYYYY_SERIES) || defined(SOC_LPC55S69_SERIES)
	CRYPTO_InitHardware();
#endif
#endif
	sbl_flash_init();
#ifdef TEST_FUNCTION
    enable_image(Permanent_mode);
#endif	
	BOOT_LOG_INF("Bootloader Version %s", BOOTLOADER_VERSION);
	os_heap_init();    
        BOOT_LOG_INF("remap or not:Y/N\r\n\r\n");
        ch = GETCHAR();
        BOOT_LOG_INF("input=%c,\r\n\r\n",ch);
        if((ch == 'Y') || (ch == 'y'))
        {
            BOOT_LOG_INF("With remap!\r\n\r\n");
            SBL_EnableRemap(BOOT_FLASH_ACT_APP, BOOT_FLASH_ACT_APP+FLASH_AREA_IMAGE_1_SIZE, FLASH_AREA_IMAGE_1_SIZE);
        }  
        else if((ch == 'N') || ((ch == 'n') ))
        {
	    BOOT_LOG_INF("Without remap!\r\n\r\n");
            SBL_DisableRemap();
        }
        else
        {
            BOOT_LOG_INF("Without remap!\r\n\r\n");
        }
#ifdef SINGLE_IMAGE
    rc = boot_single_go(&rsp);
#else
#ifdef SOC_REMAP_ENABLE
    rc = boot_remap_go(&rsp);
#else
	rc = boot_go(&rsp);
#endif
#endif /* SINGLE_IMAGE*/
	if (rc != 0) {
        while (1)
        {
            BOOT_LOG_ERR("Unable to find bootable image");
            SDK_DelayAtLeastUs(3000000, BOARD_BOOTCLOCKRUN_CORE_CLOCK);
        }
    }
    
	BOOT_LOG_INF("Bootloader chainload address offset: 0x%x", rsp.br_image_off);
	BOOT_LOG_INF("Reset_Handler address offset: 0x%x", rsp.br_image_off + rsp.br_hdr->ih_hdr_size);
	BOOT_LOG_INF("Jumping to the image\r\n\r\n");      
	do_boot(&rsp);
	BOOT_LOG_ERR("Never should get here");
    for (;;);
}

修改好代码之后,编译IAR SBL代码,并且使用debugger下载到MIMXRT1170-EVK中。

三,APP准备

参考文章第2.2章: 【朝花夕拾】RT1170 SBL ISP下载带SDRAM APP

这里为了便于区分,可以使用SDK 的hello_world工程,稍作修改。准备两个APP,内容区别:

int main(void)
{
    char ch;

    /* Init board hardware. */
    BOARD_ConfigMPU();
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();
    PRINTF("hello world1->real addr is 0X30100000\r\n"); //app1
    //  PRINTF("hello world2->real addr is 0X30200000\r\n");//app2

    while (1)
    {
        ch = GETCHAR();
        PUTCHAR(ch);
    }
}

使用app1打印方式,生成hello_world1.bin,然后通过配置加密信息添加符合SBL的头,生成:hello_app1.bin。
使用app2打印方式,生成hello_world2.bin,然后通过配置加密信息添加符合SBL的头生成:hello_app2.bin。
下面给出如何生成加密后的app情况,具体如下:
打开sbl-master\target\evkmimxrt1170\env.bat:
切换路径:

cd ..\..\component\secure\mcuboot\scripts

将前面生成的hello_world1.bin和hello_world2.bin拷贝到:
sbl-master\component\secure\mcuboot\scripts
然后通过命令:

python imgtool.py sign --key xxxx_priv.pem --align 4 --version "1.1" --header-size 0x400 --pad-header --slot-size 0x100000 --max-sectors 32 hello_world1.bin hello_app1.bin
python imgtool.py sign --key xxxx_priv.pem --align 4 --version "1.1" --header-size 0x400 --pad-header --slot-size 0x100000 --max-sectors 32 hello_world2.bin hello_app2.bin

生成hello_app1.bin, hello_app2.bin.
在这里插入图片描述

图 3

四,测试结果

使用MCUbootutility的SBL OTA方式,在板子复位之后的5S内连接,并且烧录:
hello_app1.bin到0X30100000
hello_app2.bin到0X30200000
在这里插入图片描述图 4
在这里插入图片描述图 5
下载之后,退出MCUBootutility。
复位芯片,在串口助手中等待log出现,输入‘Y’或’N’来决定是哪个APP启动。
‘Y’: remap, APP2启动
‘N’: without remap, APP1启动。
测试结果如下:

在这里插入图片描述图 6
从测试结果可以看到,可以实现remap的功能了。
附件链接:
https://community.nxp.com/t5/i-MX-RT-Knowledge-Base/RT1170-SBL-ISP-download-app-for-remap-function/ta-p/1782232

  • 27
    点赞
  • 43
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值