指定linux OS运行地址
zhilu.zhang
zhilu.zhang
发布于 2020-03-15 / 25 阅读 / 0 评论 / 0 点赞

指定linux OS运行地址

指定linux OS运行地址

前言:如下图所示,现要指定OS在0xa0000000地址处运行。

0x40000000-OxAOOO00O0地址内核完全不管,不用内校划分页表等。

一、介绍几个相关变量

ZTEXTADDR

解压代码运行的开始地址。没有物理地址和虚拟地址之分,因为此时MMU处于关闭状态。这个地址不一定时RAM的地址,可以是支持读写寻址的flash等存储中介。

Start address of decompressor. here's no point in talking about virtual or physical addresses here, since the MMU will be off at the time when you call the decompressor code. You normally call the kernel at this address to start it booting. This doesn't have to be located in RAM, it can be in flash or other read-only or read-write addressable medium.

ZRELADDR

内核启动在RAM中的地址。压缩的内核映像被解压到这个地址,然后执行。

This is the address where the decompressed kernel will be written, and eventually executed. The following constraint must be valid:

__virt_to_phys(TEXTADDR) == ZRELADDR

The initial part of the kernel is carefully coded to be position independent.

TEXTADDR

内核启动的虚拟地址,与ZRELADDR相对应。一般内核启动的虛拟地址为RAM的第一个bank地址加上0x8000。

TEXTADDR = PAGE_OFFSET + TEXTOFFST

Virtual start address of kernel, normally PAGE_OFFSET + 0x8000.This is where the kernel image ends up. With the latest kernels, it must be located at 32768 bytes into a 128MB region.

Previous kernels placed a restriction of 256MB here.

TEXTOFFSET

内核偏移地址。在arch/arm/makefile中设定。

PHYS_OFFSET

RAM第一个bank的物理起始地址。

Physical start address of the first bank of RAM.

PAGE_OFFSET

RAM第一个bank的虛拟起始地址。

Virtual start address of the first bank of RAM. During the kernel

boot phase, virtual address PAGE_OFFSET will be mapped to physical address PHYS_OFFSET, along with any other mappings you supply.This should be the same value as TASK_SIZE.

二.追踪代码发现修改如下两个变量即可实现

1.修改DDR起始地址

既然内核持0x40000000-0xA0000000地址完全置之不理 ,则可以直接修改PHYS_ OFFSET宏,追出码发现由PLAT_PHYS_OFFSET决定。

修改文件kernel/arch/arm/mach-hi3536/include/mach/memory.h

/*
 * Physical DRAM offset.
 */

//#define PLAT_PHYS_OFFSET UL(O×40000000)

#define PLAT_PHYS_OFFSETUL (Oxa0000000)

2.修改内核在RAM中运行的地址

ZRELADDR指定内核在RAM中的地址,压缩的内核映像解压到这个地址,然后执行。

修改文件kernel_hi3536169_ decoderlarchlarmimach-hi3536/Makefile.boot

#zreladdr-y   := 0x40008000
zreladdr-y    := Oxa0008000
params_phys-y := 0x00000100
initrd_phys-y := 0x00800000

三、验证

1.进入uboot查看bootcmd

fsload 0x42000000 Image; fsload 0x43000000 cramfs.initrd.img;bootm 0×42000000

0x43000000

内核启动失败。

2.修改bootcmd

fsload Oxa2000000 Image; fsload Oxa3000000 cramfs.initrd.img;bootm Oxa2000000

Oxa3000000

内核启动成功。

疑惑:内核的启动地址似乎和映像文件的加载地址没有关系吧?为什么非要加载到0xa0000000之后才行呢?

3.查看DDR内存

利用memtester DDR压力测试工具打乱0x40000000-0xa0000000之间的内存,如果系统不崩溃证明指定验证成功。

memtester -p 0×40000000 1536M 1

查看内存:

#memdev -d 0x9fffff80
9fffff80: 00000000 ffffffff 00000000 ffffffff
9fffff90: 00000000 ffffffff 00000000 ffffffff
9fffffa0: 00000000 ffffffff 00000000 ffffffff
9fffffb0: 00000000 ffffffff 00000000 ffffffff
9fffffcO: 00000000 ffffffff 00000000 ffffffff
9fffffd0:00000000 ffffffff 00000000 ffffffff
9fffffe0: 00000000 ffffffff 00000000 ffffffff
9ffffffO: 00000000 ffffffff 00000000 ffffffff
a0000000: 00000000 3fe62e43 72bea4d0 3e663769
a0000010: c5d266f1 bebbbd41 af25de2c 3f11566a
a0000020: 16bebd93 bf66c16c 5555553e 3fc55555
a0000030: 3fe00000 e320f000 e92d47f0 ed2d8b04
a0000040: ec432b19 e59f3144 e24dd008 e59f2140
a0000050: e08f3003 ec554b19 e7938002 ec410b30
a0000060: e5983000 e3c59102 e58d3004 e1993004
a0000070: 1a000002 ee600689 eecOOba0 ea000037
optind=3

内存完好无损,正常运行,验证成功。