7.15. MOVABLE

Overview

提供动态加载指定代码到sram或者sdram运行的例子。

7.15.1. 应用实例

示例演示:

example: 具体示例代码详见 apps/common/movable/example.c , 示例工程实现必须在 apps/demo/demo_audio/include/app_config.h 中定义宏 CONFIG_NO_SDRAM_ENABLECONFIG_DYNAMIC_SDRAM_ONOFF_ENABLE

//1、首先需要动态加载的代码需要以代码段的定义存在,具体方法可参考“库符号重定位到指定段方法”文档

//2、在apps/common/movable/movable_text.ld文件里模仿添加,注意参加的序号不要重复
    *(.movable.stub.4)
    __xxx_movable_region_start = .;
    *(.movable.region.4);
    __xxx_movable_region_end = .;

//3、在apps/common/movable/movable_data.ld文件里模仿添加,注意参加的序号不要重复
    . = ALIGN(4);
    __xxx_movable_slot_start = .;
    *(.movable.slot.4);
    __xxx_movable_slot_end = .;

//4、在apps/common/movable/section.c文件里模仿添加,注意参加的序号不要重复
4:
.xxx.text

static u32 *start_of_region = NULL;

extern u32 __xxx_movable_slot_start[];
extern u32 __xxx_movable_slot_end[];
extern u8 __xxx_movable_region_start[];
extern u8 __xxx_movable_region_end[];

static void enter_xxx_movable_region(u32 **start_of_region, u8 *code_load_addr)
{
    u32 code_size = __xxx_movable_region_end - __xxx_movable_region_start;
    code_movable_load(__xxx_movable_region_start, code_size, code_load_addr, __xxx_movable_slot_start, __xxx_movable_slot_end, start_of_region);
}

static void exit_xxx_movable_region(u32 **start_of_region, u8 *code_load_addr)
{
    code_movable_unload(__xxx_movable_region_start, __xxx_movable_slot_start, __xxx_movable_slot_end, start_of_region);
}