下面再介绍另外一种方法
内存、flash超大
)。
/*
下面的宏定义功能是转成字符串
如 TO_STRING(badboys) >>> "badboys"
*/
#define TO_STRING_A(s) # s
#define TO_STRING(s) TO_STRING_A(s)
.globl __test_code_start
.globl __test_code_end
/*
汇编 .section .rodata_test_code, "a", %progbits的含义
a表示权限,a是 allocation的缩写,表示该节区可分配;
%progbits是type字段的标记:
PROGBITS: 程序内容,包含代码、数据、调试相关信息
*/
.section .rodata_test_code, "a", %progbits
.balign 4
/* test_image是具体的二进制文件名称
*/
__test_code_start:
.incbin TO_STRING(test_image)
__test_code_end:
#if 32位系统
extern uint32_t __test_code_start[];
extern uint32_t __test_code_end[];
#else
extern uint64_t __test_code_start[];
extern uint64_t __test_code_end[];
#endif
/* 验证是否包含成功
__test_code_start 是文件的起始地址,在C语言中直接使用指针方式就可以引用。
__test_code_end 是是文件的结束地址
*/
printf("start addr=0x%x end addr=0x%x \r\n", __test_code_start, __test_code_end);
这个技巧不错的 👍 👍 👍
以前有幸得到一位大神的指点,用的就是正是这种方法,当时我们测试的是一些裁减过的字库文件、logo图片等。
看到有
STRING
字样,那么二进制文件里面有'\0'
时会截断不?.incbin 的语法是
.incbin file_name_path
你可以类似地理解成:include bin file
所以你的疑问不攻自破了。
@xiaorui
大佬 牛!!
收藏了收藏了
这个办法同样适合某些rootfs文件系统场合