• 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 中的定义如下 ( 删除了一些条件编译代码 )
    1. typedef struct bootm_headers {
    2. /*
    3. * Legacy os image header, if it is a multi component image
    4. * then boot_get_ramdisk() and get_fdt() will attempt to get
    5. * data from second and third component accordingly.
    6. */
    7. image_header_t *legacy_hdr_os; /* image header pointer */
    8. image_header_t legacy_hdr_os_copy; /* header copy */
    9. ulong legacy_hdr_valid;
    10. .......
    11. #ifndef USE_HOSTCC
    12. image_info_t os; /* os image info */
    13. ulong ep; /* entry point of OS */
    14. ulong rd_start, rd_end;/* ramdisk start/end */
    15. char *ft_addr; /* flat dev tree address */
    16. ulong ft_len; /* length of flat device tree */
    17. ulong initrd_start;
    18. ulong initrd_end;
    19. ulong cmdline_start;
    20. ulong cmdline_end;
    21. bd_t *kbd;
    22. #endif
    23. int verify; /* getenv("verify")[0] != 'n' */
    24. #define BOOTM_STATE_START (0x00000001)
    25. #define BOOTM_STATE_FINDOS (0x00000002)
    26. #define BOOTM_STATE_FINDOTHER (0x00000004)
    27. #define BOOTM_STATE_LOADOS (0x00000008)
    28. #define BOOTM_STATE_RAMDISK (0x00000010)
    29. #define BOOTM_STATE_FDT (0x00000020)
    30. #define BOOTM_STATE_OS_CMDLINE (0x00000040)
    31. #define BOOTM_STATE_OS_BD_T (0x00000080)
    32. #define BOOTM_STATE_OS_PREP (0x00000100)
    33. #define BOOTM_STATE_OS_FAKE_GO (0x00000200) /* 'Almost' run the OS */
    34. #define BOOTM_STATE_OS_GO (0x00000400)
    35. int state;
    36. #ifdef CONFIG_LMB
    37. struct lmb lmb; /* for memory mgmt */
    38. #endif
    39. } bootm_headers_t;

    12 行的 os 成员变量,是 image_info_t 类型的,为系统镜像信息。

    成员变量 epLinx内核镜像存放的起始地址。

    29~39 行这些宏, 表示 BOOT 的不同阶段。

    接下来看一下结构体 image_info_t ,也就是系统镜像信息结构体,此结构体在文件 include/image.h 中的定义如下:
    1. typedef struct image_info {
    2. ulong start, end; /* start/end of blob */
    3. ulong image_start, image_len; /* start of image within blob, len of image */
    4. ulong load; /* load addr for the image */
    5. uint8_t comp, type, os; /* compression, type of image, os type */
    6. uint8_t arch; /* CPU architecture */
    7. } image_info_t;

    全局变量 images 会在 bootz 命令的执行中频繁使用到,相当于 Linux 内核启动的“灵魂”。

  • 相关阅读:
    机器人控制算法——两轮差速驱动运动模型
    Python基础之输入输出
    关于语雀 23 日故障的公告
    TypeScript学习笔记
    Terraform 系列-使用Dynamic Blocks对Blocks进行迭代
    httprunner4 – 录制生成测试用例
    Android | 再探 RecyclerView 之名词解析
    php实战案例记录(22)smarty模版引擎数组循环的方式
    黑眼圈大神程序员用5000字带你通透读懂Elasticsearch的注意事项
    安装python-igraph报错
  • 原文地址:https://blog.csdn.net/wojiaxiaohuang2014/article/details/133752255