[置顶] 泰晓 RISC-V 实验箱,配套 30+ 讲嵌入式 Linux 系统开发公开课
[置顶] Linux Lab v1.4 升级部分内核到 v6.10,新增泰晓 RISC-V 实验箱支持,新增最小化内核配置支持大幅提升内核编译速度,在单终端内新增多窗口调试功能等Linux Lab 发布 v1.4 正式版,升级部分内核到 v6.10,新增泰晓实验箱支持
[置顶] 泰晓社区近日发布了一款儿童益智版 Linux 系统盘,集成了数十个教育类与益智游戏类开源软件国内首个儿童 Linux 系统来了,既可打字编程学习数理化,还能下棋研究数独提升智力
Break through Linux image size limitation of Uboot
by falcon wuzhangjin@gmail.com of TinyLab.org 2013/11/28
Background
During the booting procedure of an embedded Linux system, before decompressing the Linux kernel image, the Uboot loads the compressed Linux kernel image and Ramdisk image into two fixed contiguous memory spaces. That means, the size of the memory spacereserved for the Linux kernel image is limited by the difference between the start addresses of these two memory spaces, if the size of the compressed (anddecompressed) Linux kernel image is bigger than the size of the first reserved memory space, the ramdisk image will be overritten and result in kernel crash!
Requirement & Issue
After the release of a product, the users maywant new functionalities, the developers may want more debug features, with the new functionalities and more debug features, the (decompressed) kernel image size may exceed the above limitation and result in system boot failure eventually.
Since Uboot has been released in the products, and there is no (easy/safe) way to update the Uboot, so, what’s the solution?
Solution
As we know, Linux has added the compressed kernel image support for most of the processors, including X86, MIPS and ARM, here uses ARM as an example.
In arch/arm/boot/compressed/misc.c, as we can see, there is a decompress_kernel() function, it calls do_decompress() to do the real decompression.
This is exactly the key to solve the above issue:
Before the calling to do_compress() function, If we hook the decompress_kernel() function, and move the ramdisk image forward and reserve more memory space for the decompressed kernel image, the isssue would be solved.
Patch
A patch is prepared for ARM, see the patch ARM: compressed: Move ramdisk forward to reserve more memory for kernel image posted. To enable the feature, the MOVE_RAMDISK configure option must be enabled and the MOVE_RAMDISK_OFFSET_M must be configured at least to be bigger than the decompressed kernel image: vmlinux, for example, reserve +20M for an ARM board:
$ make menuconfig ARCH=arm
General setup --->
[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
[*] Move ramdisk forward to reserve more memory for kernel image
(20) Set the move offset of ramdisk (in Mbytes) (NEW)
Notice
Please note, the patch is only tested for exynos boards, it may not work for the others.
If the boards don’t provide the PLAT_PHYS_OFFSET symbol, you need to define your own TAG_BASE_ADDR, otherwise, the kernel will not build. The TAG_BASE_ADDR should be defined as the tag address used by your Uboot, it is often the physical base address, please grep DDR_PHYS_BASE under your board’s header files, for example:
$ grep DDR_PHYS_BASE -ur arch/arm/
Or, you can print the real tag base address after the following line of the setup_machine_tags() in arch/arm/kernel/atags_parse.c and then define TAG_BASE_ADDR as it.
default_tags.mem.start = PHYS_OFFSET;
pr_info("%s: TAG_BASE_ADDR = %lx\n", default_tags.mem.start);
This patch is still in the RFC stage, welcome your comments and patches.
猜你喜欢:
- 我要投稿:发表原创技术文章,收获福利、挚友与行业影响力
- 知识星球:独家 Linux 实战经验与技巧,订阅「Linux知识星球」
- 视频频道:泰晓学院,B 站,发布各类 Linux 视频课
- 开源小店:欢迎光临泰晓科技自营店,购物支持泰晓原创
- 技术交流:Linux 用户技术交流微信群,联系微信号:tinylab
支付宝打赏 ¥9.68元 | 微信打赏 ¥9.68元 | |
请作者喝杯咖啡吧 |