Skip to content

Instantly share code, notes, and snippets.

@eggman
Created July 2, 2016 13:54
Show Gist options
  • Save eggman/5a3a8f3a582a8fd91e6e78942102d1bb to your computer and use it in GitHub Desktop.
Save eggman/5a3a8f3a582a8fd91e6e78942102d1bb to your computer and use it in GitHub Desktop.
あまり面白くないのでボツです。
ARM Cortex M3 のリンカスクリプトを読んで見ました。
# 対象
* Realtek Amebaのベアメタル環境用のリンカスクリプト
* https://github.com/neojou/arm-gcc-blink-example/blob/master/templates/ameba-example/package/scripts/rlx8195A.ld
* 調査はbinutilsのドキュメントを参照しています。
* https://www.gnu.org/software/binutils/ にリンクされている https://sourceware.org/binutils/docs-2.26/ld/index.html
# ENTRY
* ENTRYコマンドは最初に呼ばれる関数を書く
* PreProcessForVendor()は, pin, uart, sdram等いろいろな初期化を行う関数のようです。
```
ENTRY(PreProcessForVendor)
```
# INCLUDE
* INCLUDEコマンドは指定したファイルの内容を取り込む
```
INCLUDE "export-rom.txt"
```
* export-rom.txtにはAmebaのROMに含まれている関数の名前とアドレスのリストが含まれている。
# MEMORY
* MEMORYコマンドはリンカが割り当てを許可するメモリブロックを設定する。
* メモリブロックのフォーマット
* name メモリブロック名
* attr アトリビュート r, w, a, x, a, i, l, !が設定可能、小文字でも大文字でも良い。 rwx なら読み、書き、実行可能。
* origin 開始アドレス
* len 長さ
```
name [(attr)] : ORIGIN = origin, LENGTH = len
```
```
MEMORY
{
TCM (rwx) : ORIGIN = 0x1FFF0000, LENGTH = 65536
BD_RAM (rwx) : ORIGIN = 0x10000bc8, LENGTH = 455735
SDRAM_RAM (rwx) : ORIGIN = 0x30000000, LENGTH = 2M
}
```
* AmebaではTCMは速いSRAM、BD_RAMは普通のSRAM、SDRAM_RAMはちょっと遅いSDRAMとなっています。
# 変数
* 変数を定義できる
```
STACK_SIZE = 0x2000 ;
```
# SECTIONS
* SECTIONSコマンドは、どのようにセクションに配置するかを設定する。
* sections-command で設定していく。
```
SECTIONS
{
sections-command
sections-command
...
}
```
## .ram.start.table
* .ram.start.table セクションの出力設定
* . は現在の位置に相当するアドレスを示す。
* ```__ram_image1_text_start__ = .;```は現在の位置に相当するアドレスに__ram_image1_text_start__というシンボルを作成する。
* SORTコマンドはSORT_BY_NAMEのalias で配置するときに名前順とする。
* KEEPコマンドは、`--gc-sections`で指定するlink time gabrbage collectionを無効にする。
* ```KEEP(*(SORT(.start.ram.data*)))```は.start.ram.data*の入力を名前順でSORTし、link time gabrbage collectionを無効で配置する。
* >BD_RAMはこのセクションをBD_RAMに配置する。
* 実際に.ram.start.table に配置されるのは、gRamStartFun, gRamPatchWAKE, gRamPatchFun0, gRamPatchFun1, gRamPatchFun2 などです。 patchを置くみたいです。
```
.ram.start.table :
{
__ram_image1_text_start__ = .;
__ram_start_table_start__ = .;
KEEP(*(SORT(.start.ram.data*)))
__ram_start_table_end__ = .;
} > BD_RAM
```
## .ram_image1.text
* .ram_image1.text セクションの出力設定
* コメントあるようにROM内のコードが使うRAMを配置するので、場所がずれないようにする必要がある。
*
```
/* Add . to assign the start address of the section, *
* to prevent the change of the start address by ld doing section alignment */
.ram_image1.text . :
{
/* these 4 sections is used by ROM global variable */
/* Don't move them and never add RAM code variable to these sections */
__image1_validate_code__ = .;
KEEP(*(.image1.validate.rodata*))
KEEP(*(.infra.ram.data*))
KEEP(*(.timer.ram.data*))
KEEP(*(.hal.ram.data*))
__image1_bss_start__ = .;
*(.hal.flash.data*)
*(.hal.sdrc.data*)
__image1_bss_end__ = .;
*(.hal.ram.text*)
*(.hal.flash.text*)
*(.hal.sdrc.text*)
*(.rodata*)
*(.infra.ram.text*)
__ram_image1_text_end__ = .;
} > BD_RAM
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment