arm 映像文件存储器映射调整 android ld link script

2024-02-28 02:08

本文主要是介绍arm 映像文件存储器映射调整 android ld link script,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

分散加载

scatter文件语法

scatter文件典型用法

等效的简单映射分散载入描述

How to convert from an armlink scatter file to a GNU ld linker script For some of my research projects, I use the Intel iMote (ISN100-BA) platform, provided by Intel research labs Cambridge. The default TinyOS platform code uses GNU gcc for compiling, but depends on the ARM developer suite (ADS 1.2 or Realview) linker for the final step. Replacing this with the GNU linker ld was a non-trivial task, and part of it was to convert the memory layout from the armlink scatter file to a GNU ld linker script. In the following, I use the ScatterFile.txt shipped with the iMote TinyOS platform, but the steps should be applicable to other files as well. Please email me when you have successfully converted other files, so that I can add more examples to this page. For brevity, I have removed all comments from the original file: -------------------------------------------------------------------------------- LoadFlashCode 0x004000 ABSOLUTE 0x7C000 { FlashCode2 +0 ; { * (FlashBoot) ; area is found in SU_FlashBoot.s } FlashCode3 +0 { * (+RO) } RomLinkV1 0x200000 OVERLAY { SU_ROMLinkV1.o (+RO) } RomLinkV2 0x200000 OVERLAY { SU_ROMLinkV2.o (+RO) } IRamStack +0 ABSOLUTE { * (Stacks) } IRamCode +0 ABSOLUTE { TM_FlashDrvAmend.o (+RO) TM_IRamCode.o (+RO) } IRamNI +0 { * (ResetFlags) SU_PowerUpCheckVar.o (+ZI) } IRamRW +0 { * ( +RW ) } IRamZI +0 { * ( +ZI ) } BRamNI 0x20CB00 ABSOLUTE { } BRamZI 0x20F900 ABSOLUTE 0x700 { BBD_BufferSramVar.o ( +ZI) LM_BufferSramVar.o ( +ZI) BP_BufferSramVar.o ( +ZI) } XRamZI 0x400000 ABSOLUTE { BP_DummyXramVar.o ( +ZI) } } -------------------------------------------------------------------------------- There are numerous examples for GNU ld linker scripts on the web, also for ARM7TDMI (which is used on the iMote). These can be used for the general structure. But to generate a working file, we first need to find out the segments used by the target platform, that is, start and end addresses for loading and executing code and data. Using the manual for armlink, these can be extracted from the above file (yes, reverse engineering). The first line LoadFlashCode 0x004000 ABSOLUTE 0x7C000(the name is ignored) tells us that the flash memory starts at 0x4000 with a size of 0x7C000 bytes; this is called the "load region" for armlink, and defines how the generated binary file will look like. In the first block (blocks inside the load region define the "exec region", which might have a different mapping), FlashCode2 +0 ; { * (FlashBoot) }a boot loader code is put at the beginning of the load region. The name is again arbitrary and can be ignored for the address layout, but the +0 is an offset for the block, relative to the preceeding section (as this is the first region, relative to the load region start address). Since the address offset is zero, this tells us that, for executing code, this platform uses the same start address during execution that we need to use for loading. That is, the load region and the exec region for initialization code start at the same absolute address. This is to be expected for most platforms. Although the name is not relevant for the linker itself, exec regions automatically generate Load$$Name symbols, which can be referenced in the code. This is typically used by the boot loader to set up the run-time environment before starting the custom code, i.e. for transforming the load segmentation into the exec segmentation. Since GNU ld does not generate these symbols automatically, we will need to do so explicitly, as described below. There are two components in the lines within these blocks: a module selector, which matches input file names (object or library files), and an (optional) input section selector in brackets, which matches the section that the compiler created. Both components need to match for the line to include anything in the output. The above line matches any input file (i.e. don't care) that defines a section named FlashBoot (which is, in this case, contained in the file SU_FlashBoot.o). Then the next block FlashCode3 +0 { * (+RO) }simply appends all the other executable code and constant values (which are marked read-only, i.e. as an RO section, by the compiler). Again, the +0 is an offset and tells us that our own executable code is mapped to the same addresses for loading and for execution. Now it gets slightly more complicated. The next two exec regions RomLinkV1 0x200000 OVERLAY { SU_ROMLinkV1.o (+RO) } RomLinkV2 0x200000 OVERLAY { SU_ROMLinkV2.o (+RO) }use the same absolute address during execution, namely 0x200000, and the OVERLAY keyword. This means that two different code blocks (code because the section matches are RO) can be available in the area starting at address 0x200000 and that the executed code somehow needs to select which one is used (in the iMote TinyOS case, this is done by the boot loader). For linking, this means that two code blocks that are separate in the load region (i.e. the binary file to be flashed) need to use the same start address when being referenced to for execution. The modules referenced by the module selectors, i.e. SU_ROMLinkV1.o and SU_ROMLinkV2.o (contained in the motelib.a file), are appended to the code area in the load region. Although this is not made explicit, the new base address tells us that a new segment was started. We can guess (taking into account the load region names...), the the segment starting at address 0x4000 is a flash memory, both during load and during execution time, and that the segment starting at address 0x200000 is RAM. The data sheet of the iMote tells us that it has a size of 64kB, or 0x10000, so we can use this for verification that the RAM area is sufficient for the executable. The following regions therefore define the RAM layout during execution. A small part at the start is already consumed by the overlaid regions, followed by IRamStack +0 ABSOLUTE { * (Stacks) }which defines our stack region. The +0 ABSOLUTE address modifier tells us that this exec region follows the preceding, but that it does not inherit its OVERLAY flag. As for the first load region, this matches a specific section name (defined in motelib.a). Then two more code modules (only the code and constant data parts marked RO of two specific modules, again contained in motelib.a) IRamCode +0 ABSOLUTE { TM_FlashDrvAmend.o (+RO) ;//Ammendments to Flash driver code TM_IRamCode.o (+RO) }are appended and need to be copied from the load address to the execution address by the boot loader (these are different by now, since the modules need to be appended to the generated binary that is loaded to the flash, but will be executed in RAM addresses). The next exec region IRamNI +0 { * (ResetFlags) SU_PowerUpCheckVar.o (+ZI) }defines another part identified by section name and room for some variables that should be initialized with zero (the ZI attribute, which indicates that this is "BSS" data, i.e. uninitialized static variables). Finally, the next two exec regions IRamRW +0 { * ( +RW ) } IRamZI +0 { * ( +ZI ) }define the RAM areas for all other initialized (RW) and uninitialized (ZI) variables that have not been added by previous regions. These are the normal "DATA" and "BSS" segments. Then seemingly nonsensical, an emtpy exec region BRamNI 0x20CB00 ABSOLUTE { }that only defines the matching symbols at address 0x20CB00 but does not reserve any further space (in neither the load nor the exec areas). At the very end of the available RAM block, the exec region BRamZI 0x20F900 ABSOLUTE 0x700 { BBD_BufferSramVar.o ( +ZI) LM_BufferSramVar.o ( +ZI) BP_BufferSramVar.o ( +ZI) }reserves space for uninitialized variables (ZI) defined in three modules within the last 0x700 bytes, starting at address 0x20F900. Taking module names into account, we can guess that this is a small buffered SRAM area, possibly used for performance reasons (a detailed data sheet would make this guessing unnecessary...). Note that this does again not consume any space in the load region, because this exec region only defines uninitialized variables. The above description of "all other variables that have not been added by previous regions" is not completely correct. Not order matches, but most specific lines. Finally, the last exec region XRamZI 0x400000 ABSOLUTE { BP_DummyXramVar.o ( +ZI) }defines yet another segment, starting at address 0x400000. It also doesn't append anything to the load region, but reserves space for uninitialized variables (ZI) of a specific module. Summarizing this analysis, the scatter file defines three regions: •Start address 0x4000 with a length of 0x7C000: This is mapped in both the load and the execution areas and defines the flash memory. Some code (marked RO) is executed in-place, and other code and constants (marked RO) and start values for initialized variables (marked RW) are stored in the load area (in the binary file and loaded into the flash memory) and need to be copied to the other, writable segments by the boot loader before executing the main program. •Start address 0x200000 with a length of 0x10000: This is the normal RAM for the execution area, and the linker reserves space for defined variables here. •Start address 0x400000 with unknown length: Contains only some uninitialized variables. This means that the linker only needs to set resolve some symbols to lie within this segment, but does not need to put anything in there. Now we need to write an ld linker scripts that creates the same layout. A complete reference for ld linker scripts can be found here. The initial definition of the three regions is simple: MEMORY { FLASH (rx) : ORIGIN = 0x004000, LENGTH = 0x7C000 RAM (rwx) : ORIGIN = 0x200000, LENGTH = 0x10000 RAM2 (rwx) : ORIGIN = 0x400000, LENGTH = 0x10000 }As we don't really know the length of the second RAM region but the LENGTH attribute is mandatory, we need to guess something. As it is just used to check for overflowing regions, this should not lead to any problems. Note that the addresses specified in the MEMORY layout refer to the executable area, i.e. exec regions in armlink terms. The main part of an ld linker script is its SECTIONS block, which we start with the code area that is mapped to the same address in the load and execution areas, i.e. the flash: SECTIONS { .text : { * (FlashBoot) __end_of_boot__ = ABSOLUTE(.); * (.text) * (.rodata) * (.rodata*) * (.glue_7) * (.glue_7t) } > FLASH __end_of_text__ = .; This first output section is named .text, which is the standard name for ELF format files, and first includes the section named FlashBoot from any of the input files and then all remaining .text, .rodata, and special glue code segments from any of the input files. The addresses are set automatically, because the whole output section is put into the defined FLASH memory region. Additionally, we define the symbol __end_of_boot__ to contain the end address of the boot loader code, for later use. ..

这篇关于arm 映像文件存储器映射调整 android ld link script的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/754170

相关文章

Android Paging 分页加载库使用实践

《AndroidPaging分页加载库使用实践》AndroidPaging库是Jetpack组件的一部分,它提供了一套完整的解决方案来处理大型数据集的分页加载,本文将深入探讨Paging库... 目录前言一、Paging 库概述二、Paging 3 核心组件1. PagingSource2. Pager3.

Kotlin Map映射转换问题小结

《KotlinMap映射转换问题小结》文章介绍了Kotlin集合转换的多种方法,包括map(一对一转换)、mapIndexed(带索引)、mapNotNull(过滤null)、mapKeys/map... 目录Kotlin 集合转换:map、mapIndexed、mapNotNull、mapKeys、map

Android kotlin中 Channel 和 Flow 的区别和选择使用场景分析

《Androidkotlin中Channel和Flow的区别和选择使用场景分析》Kotlin协程中,Flow是冷数据流,按需触发,适合响应式数据处理;Channel是热数据流,持续发送,支持... 目录一、基本概念界定FlowChannel二、核心特性对比数据生产触发条件生产与消费的关系背压处理机制生命周期

Android ClassLoader加载机制详解

《AndroidClassLoader加载机制详解》Android的ClassLoader负责加载.dex文件,基于双亲委派模型,支持热修复和插件化,需注意类冲突、内存泄漏和兼容性问题,本文给大家介... 目录一、ClassLoader概述1.1 类加载的基本概念1.2 android与Java Class

Java继承映射的三种使用方法示例

《Java继承映射的三种使用方法示例》继承在Java中扮演着重要的角色,它允许我们创建一个类(子类),该类继承另一个类(父类)的所有属性和方法,:本文主要介绍Java继承映射的三种使用方法示例,需... 目录前言一、单表继承(Single Table Inheritance)1-1、原理1-2、使用方法1-

Android DataBinding 与 MVVM使用详解

《AndroidDataBinding与MVVM使用详解》本文介绍AndroidDataBinding库,其通过绑定UI组件与数据源实现自动更新,支持双向绑定和逻辑运算,减少模板代码,结合MV... 目录一、DataBinding 核心概念二、配置与基础使用1. 启用 DataBinding 2. 基础布局

Android ViewBinding使用流程

《AndroidViewBinding使用流程》AndroidViewBinding是Jetpack组件,替代findViewById,提供类型安全、空安全和编译时检查,代码简洁且性能优化,相比Da... 目录一、核心概念二、ViewBinding优点三、使用流程1. 启用 ViewBinding (模块级

k8s上运行的mysql、mariadb数据库的备份记录(支持x86和arm两种架构)

《k8s上运行的mysql、mariadb数据库的备份记录(支持x86和arm两种架构)》本文记录在K8s上运行的MySQL/MariaDB备份方案,通过工具容器执行mysqldump,结合定时任务实... 目录前言一、获取需要备份的数据库的信息二、备份步骤1.准备工作(X86)1.准备工作(arm)2.手

Nginx Location映射规则总结归纳与最佳实践

《NginxLocation映射规则总结归纳与最佳实践》Nginx的location指令是配置请求路由的核心机制,其匹配规则直接影响请求的处理流程,下面给大家介绍NginxLocation映射规则... 目录一、Location匹配规则与优先级1. 匹配模式2. 优先级顺序3. 匹配示例二、Proxy_pa

Android学习总结之Java和kotlin区别超详细分析

《Android学习总结之Java和kotlin区别超详细分析》Java和Kotlin都是用于Android开发的编程语言,它们各自具有独特的特点和优势,:本文主要介绍Android学习总结之Ja... 目录一、空安全机制真题 1:Kotlin 如何解决 Java 的 NullPointerExceptio