本文主要是介绍bootz启动 Linux内核过程中涉及的全局变量images,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一. bootz启动Linux
uboot 启动Linux内核使用bootz命令。当然还有其它的启动命令,例如,bootm命令等等。
本文只分析 bootz命令启动 Linux内核的过程。
本文具体分析 bootz启动 Linux内核过程涉及的一个重要的全局变量 images。
二. bootz 启动 Linux 内核过程
1. images 全局变量
不管是 bootz 还是 bootm 命令,在启动 Linux 内核的时候都会用到一个重要的全局变量:
images , images保存Linux内核镜像的信息。
images 在文件 cmd/bootm.c 中有如下定义:
bootm_headers_t images; /* pointers to os/initrd/fdt images */
images 是 bootm_headers_t 类型的全局变量, bootm_headers_t 是个 boot 头结构体,在文件
include/image.h 中的定义如下 ( 删除了一些条件编译代码 ) :
typedef struct bootm_headers {/** Legacy os image header, if it is a multi component image* then boot_get_ramdisk() and get_fdt() will attempt to get* data from second and third component accordingly.*/image_header_t *legacy_hdr_os; /* image header pointer */image_header_t legacy_hdr_os_copy; /* header copy */ulong legacy_hdr_valid;
.......
#ifndef USE_HOSTCCimage_info_t os; /* os image info */ulong ep; /* entry point of OS */ulong rd_start, rd_end;/* ramdisk start/end */char *ft_addr; /* flat dev tree address */ulong ft_len; /* length of flat device tree */ulong initrd_start;ulong initrd_end;ulong cmdline_start;ulong cmdline_end;bd_t *kbd;
#endifint verify; /* getenv("verify")[0] != 'n' */#define BOOTM_STATE_START (0x00000001)
#define BOOTM_STATE_FINDOS (0x00000002)
#define BOOTM_STATE_FINDOTHER (0x00000004)
#define BOOTM_STATE_LOADOS (0x00000008)
#define BOOTM_STATE_RAMDISK (0x00000010)
#define BOOTM_STATE_FDT (0x00000020)
#define BOOTM_STATE_OS_CMDLINE (0x00000040)
#define BOOTM_STATE_OS_BD_T (0x00000080)
#define BOOTM_STATE_OS_PREP (0x00000100)
#define BOOTM_STATE_OS_FAKE_GO (0x00000200) /* 'Almost' run the OS */
#define BOOTM_STATE_OS_GO (0x00000400)int state;#ifdef CONFIG_LMBstruct lmb lmb; /* for memory mgmt */
#endif
} bootm_headers_t;
第 12 行的 os 成员变量,是 image_info_t 类型的,为系统镜像信息。
成员变量 ep:Linx内核镜像存放的起始地址。
第 29~39 行这些宏, 表示 BOOT 的不同阶段。
接下来看一下结构体 image_info_t ,也就是系统镜像信息结构体,此结构体在文件 include/image.h 中的定义如下:
typedef struct image_info {ulong start, end; /* start/end of blob */ulong image_start, image_len; /* start of image within blob, len of image */ulong load; /* load addr for the image */uint8_t comp, type, os; /* compression, type of image, os type */uint8_t arch; /* CPU architecture */
} image_info_t;
全局变量 images 会在 bootz 命令的执行中频繁使用到,相当于 Linux 内核启动的“灵魂”。
这篇关于bootz启动 Linux内核过程中涉及的全局变量images的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!