- 论坛徽章:
- 0
|
回复 #1 duyaolin 的帖子
走一遍initrd处理的过程吧
2.6.12, arch\arm\kernel\setup.c
- static void __init early_initrd(char **p)
- {
- unsigned long start, size;
- start = memparse(*p, p);
- if (**p == ',') {
- size = memparse((*p) + 1, p);
- phys_initrd_start = start;
- phys_initrd_size = size;
- }
- }
- __early_param("initrd=", early_initrd);
复制代码
这里先解析你的initrd参数,把你给的物理地址和大小信息存入全局的phys_initrd_start和phys_initrd_size中
转到arch/arm/mm/init.c, bootmem_init()
- #ifdef CONFIG_BLK_DEV_INITRD
- if (phys_initrd_size && initrd_node >= 0) {
- reserve_bootmem_node(NODE_DATA(initrd_node), phys_initrd_start,
- phys_initrd_size);
- initrd_start = __phys_to_virt(phys_initrd_start);
- initrd_end = initrd_start + phys_initrd_size;
- }
- #endif
复制代码
把物理地址转换成内核虚拟地址initrd_start和initrd_end后,再到init/initramfs.c, populate_rootfs()
- #ifdef CONFIG_BLK_DEV_INITRD
- if (initrd_start) {
- int fd;
- printk(KERN_INFO "checking if image is initramfs...");
- err = unpack_to_rootfs((char *)initrd_start,
- initrd_end - initrd_start, 1);
- if (!err) {
- printk(" it is\n");
- unpack_to_rootfs((char *)initrd_start,
- initrd_end - initrd_start, 0);
- free_initrd_mem(initrd_start, initrd_end);
- return;
- }
- printk("it isn't (%s); looks like an initrd\n", err);
- fd = sys_open("/initrd.image", O_WRONLY|O_CREAT, 700);
- if (fd >= 0) {
- sys_write(fd, (char *)initrd_start,
- initrd_end - initrd_start);
- sys_close(fd);
- free_initrd_mem(initrd_start, initrd_end);
- }
- }
- #endif
复制代码
代码很明显,对于initrd,作为文件存储为/initrd.image,再到init/do_mounts_initrd.c, initrd_load()
- create_dev("/dev/ram", Root_RAM0, NULL);
- /*
- * Load the initrd data into /dev/ram0. Execute it as initrd
- * unless /dev/ram0 is supposed to be our actual root device,
- * in that case the ram disk is just set up here, and gets
- * mounted in the normal path.
- */
- if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
- sys_unlink("/initrd.image");
- handle_initrd();
- return 1;
- }
复制代码
这里的注释就是initrd的"终结者"了,到了/dev/ram就很没有疑问了 |
|