aboutsummaryrefslogtreecommitdiff
path: root/zh-cn/devices/bootloader/boot-image-header.html
blob: 6d9be66f2536b497d40e88dc0d14fd9e4a4cc1b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<html devsite><head>
  <title>启动映像标头版本控制</title>
  <meta name="project_path" value="/_project.yaml"/>
  <meta name="book_path" value="/_book.yaml"/>
</head>

<body>
  <!--
      Copyright 2018 The Android Open Source Project

      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
  -->

  <h2>启动映像标头版本编号</h2>

  <p>从 Android 9 起,启动映像标头开始包含一个用于指示标头版本的字段。引导加载程序必须检查该标头版本字段,并相应地解析标头。通过对启动映像标头进行版本编号,可在将来对标头进行修改,同时保持向后兼容性。</p>

  <p>所有搭载 Android 9 的设备都必须使用启动标头版本 1。</p>

  <h2 id="boot-image-header-changes">启动映像标头更改</h2>

  <p>对于搭载 Android 9 的设备,旧版启动映像标头(如下所示)中的 <code>unused</code> 字段将会转换为标头版本字段。</p>

  <pre class="prettyprint">struct boot_img_hdr
{
    uint8_t magic[BOOT_MAGIC_SIZE];
    uint32_t kernel_size;  /* size in bytes */
    uint32_t kernel_addr;  /* physical load addr */

    uint32_t ramdisk_size; /* size in bytes */
    uint32_t ramdisk_addr; /* physical load addr */

    uint32_t second_size;  /* size in bytes */
    uint32_t second_addr;  /* physical load addr */

    uint32_t tags_addr;    /* physical addr for kernel tags */
    uint32_t page_size;    /* flash page size we assume */
    uint32_t unused;
    uint32_t os_version;
    uint8_t name[BOOT_NAME_SIZE]; /* asciiz product name */
    uint8_t cmdline[BOOT_ARGS_SIZE];
    uint32_t id[8]; /* timestamp / checksum / sha1 / etc */
    uint8_t extra_cmdline[BOOT_EXTRA_ARGS_SIZE];
};</pre>

  <p>如果设备搭载 Android 9 之前的版本且使用旧版启动映像标头,则会被视为使用启动映像标头版本 0。所有搭载 Android 9 的设备都必须使用以下启动映像标头结构,同时标头版本设为 1。</p>

  <pre class="prettyprint">struct boot_img_hdr
{
    uint8_t magic[BOOT_MAGIC_SIZE];
    uint32_t kernel_size;  /* size in bytes */
    uint32_t kernel_addr;  /* physical load addr */

    uint32_t ramdisk_size; /* size in bytes */
    uint32_t ramdisk_addr; /* physical load addr */

    uint32_t second_size;  /* size in bytes */
    uint32_t second_addr;  /* physical load addr */

    uint32_t tags_addr;    /* physical addr for kernel tags */
    uint32_t page_size;    /* flash page size we assume */
    uint32_t header_version;
    uint32_t os_version;
    uint8_t name[BOOT_NAME_SIZE]; /* asciiz product name */
    uint8_t cmdline[BOOT_ARGS_SIZE];
    uint32_t id[8]; /* timestamp / checksum / sha1 / etc */
    uint8_t extra_cmdline[BOOT_EXTRA_ARGS_SIZE];
    uint32_t recovery_dtbo_size;   /* size of recovery dtbo image */
    uint64_t recovery_dtbo_offset; /* offset in boot image */
    uint32_t header_size;   /* size of boot image header in bytes */
};</pre>

  <p><code>header_size</code> 字段包含启动映像标头大小。如果启动映像标头版本设为 1,则除了内核、ramdisk 和 second 部分之外,ID 字段还包含启动映像 <code>recovery_dtbo</code> 部分的 SHA1 摘要。要详细了解 <code>recovery_dtbo_size</code> 和 <code>recovery_dtbo_offset</code> 字段,请参阅<em><a href="/devices/bootloader/recovery-image">在非 A/B 设备的恢复映像中添加 DTBO</a></em>。</p>

  <h2 id="implementation">实现</h2>

  <p>用于创建启动映像的 <code>mkbootimg</code> 工具添加了以下参数,以支持新的启动映像标头:</p>

  <table>
    <tbody><tr>
      <td><strong>参数</strong>
      </td>

      <td><strong>说明</strong>
      </td>
    </tr>

    <tr>
      <td><code>header_version</code>
      </td>

      <td>设置启动映像标头版本。</td>
    </tr>

    <tr>
      <td><code>recovery_dtbo</code>
      </td>

      <td>要添加到恢复映像的恢复 DTBO 映像的路径。</td>
    </tr>
  </tbody></table>

  <p>设备 <code>BoardConfig.mk</code> 使用 <code>BOARD_MKBOOTIMG_ARGS</code> 配置,以便将 <code>header version</code> 添加到 <code>mkbootimg</code> 的其他专门针对主板的参数。例如:</p>

  <pre class="prettyprint">
  BOARD_MKBOOTIMG_ARGS := --ramdisk_offset $(BOARD_RAMDISK_OFFSET) --tags_offset $(BOARD_KERNEL_TAGS_OFFSET) --header_version $(BOARD_BOOTIMG_HEADER_VERSION)</pre>

  <p>Android 编译系统使用 BoardConfig 变量 <code>BOARD_PREBUILT_DTBOIMAGE</code>,以便在创建恢复映像期间设置 <code>mkbootimg</code> 工具的 <code>recovery_dtbo</code> 参数。</p>

  <p>要详细了解 Android 开源项目 (AOSP) 的变化,请查看<a href="https://android-review.googlesource.com/q/topic:%22recovery_dtbo%22+(status:open%20OR%20status:merged)">与启动映像标头版本编号相关的更改列表</a>。</p>

  <h2 id="validation">验证</h2>

  <p>对于所有搭载 Android 9 的设备,<a href="/compatibility/vts/">供应商测试套件 (VTS)</a> 都会检查启动/恢复映像的格式,以确保启动映像标头使用版本 1。</p>

</body></html>