update aosp modules from upstream
Goodbye 2022 a year of the Tiger a year of lock down a year of all the messpull/140/head
parent
078930b7c7
commit
e14887192a
Binary file not shown.
@ -0,0 +1,14 @@
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA2ASv49OEbH4NiT3CjNMS
|
||||
VeliyfEPXswWcqtEfCxlSpS1FisAuwbvEwdTTPlkuSh6G4SYiNhnpCP5p0vcSg/3
|
||||
OhiuVKgV/rCtrDXaO60nvK/o0y83NNZRK2xaJ9eWBq9ruIDK+jC0sYWzTaqqwxY0
|
||||
Grjnx/r5CXerl5PrRK7PILzwgBHbIwxHcblt1ntgR4cWVpO3wiqasEwBDDDYk4fw
|
||||
7W6LvjBb9qav3YB8RV6PkZNeRP64ggfuecq/MXNiWOPNxLzCER2hSr/+J32h9jWj
|
||||
XsrcVy8+8Mldhmr4r2an7c247aFfupuFGtUJrpROO8/LXMl5gPfMpkqoatjTMRH5
|
||||
9gJjKhot0RpmGxZBvb33TcBK5SdJX39Y4yct5clmDlI4Fjj7FutTP+b96aJeJVnY
|
||||
eUX/A0wmogBajsJRoRX5e/RcgZsYRzXYLQXprQ81dBWjjovMJ9p8XeT6BNMFC7o6
|
||||
sklFL0fHDUE/l4BNP8G1u3BfpzevSCISRS71D4eS4oQB+RIPFBUkzomZ7rnEF3Bw
|
||||
Feq+xmwfYrP0LRaH+1YeRauuMuReke1TZl697a3mEjkNg8noa2wtpe7EWmaujJfX
|
||||
DWxJx/XEkjGLCe4z2qk3tkkY+A5gRcgzke8gVxC+eC2DJtbKYfkv4L8FMFJaEhwA
|
||||
p13MfC7FlYujO/BDLl7dANsCAwEAAQ==
|
||||
-----END PUBLIC KEY-----
|
@ -1,16 +0,0 @@
|
||||
diff --git a/aosp/libavb/src/avb/c/avb_sysdeps_posix.c b/aosp/libavb/src/avb/c/avb_sysdeps_posix.c
|
||||
index e26c3ef..f1572a5 100644
|
||||
--- a/aosp/libavb/src/avb/c/avb_sysdeps_posix.c
|
||||
+++ b/aosp/libavb/src/avb/c/avb_sysdeps_posix.c
|
||||
@@ -22,7 +22,11 @@
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
+#if defined(__APPLE__) && defined(__MACH__)
|
||||
+#include <machine/endian.h>
|
||||
+#else
|
||||
#include <endian.h>
|
||||
+#endif
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
@ -1,114 +1,66 @@
|
||||
/*-
|
||||
* COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or
|
||||
* code or tables extracted from it, as desired without restriction.
|
||||
*/
|
||||
|
||||
/*
|
||||
* First, the polynomial itself and its table of feedback terms. The
|
||||
* polynomial is
|
||||
* X^32+X^26+X^23+X^22+X^16+X^12+X^11+X^10+X^8+X^7+X^5+X^4+X^2+X^1+X^0
|
||||
*
|
||||
* Note that we take it "backwards" and put the highest-order term in
|
||||
* the lowest-order bit. The X^32 term is "implied"; the LSB is the
|
||||
* X^31 term, etc. The X^0 term (usually shown as "+1") results in
|
||||
* the MSB being 1
|
||||
*
|
||||
* Note that the usual hardware shift register implementation, which
|
||||
* is what we're using (we're merely optimizing it by doing eight-bit
|
||||
* chunks at a time) shifts bits into the lowest-order term. In our
|
||||
* implementation, that means shifting towards the right. Why do we
|
||||
* do it this way? Because the calculated CRC must be transmitted in
|
||||
* order from highest-order term to lowest-order term. UARTs transmit
|
||||
* characters in order from LSB to MSB. By storing the CRC this way
|
||||
* we hand it to the UART in the order low-byte to high-byte; the UART
|
||||
* sends each low-bit to hight-bit; and the result is transmission bit
|
||||
* by bit from highest- to lowest-order term without requiring any bit
|
||||
* shuffling on our part. Reception works similarly
|
||||
* Copyright 2020 The Android Open Source Project
|
||||
*
|
||||
* The feedback terms table consists of 256, 32-bit entries. Notes
|
||||
* 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
|
||||
*
|
||||
* The table can be generated at runtime if desired; code to do so
|
||||
* is shown later. It might not be obvious, but the feedback
|
||||
* terms simply represent the results of eight shift/xor opera
|
||||
* tions for all combinations of data and CRC register values
|
||||
*
|
||||
* The values must be right-shifted by eight bits by the "updcrc
|
||||
* logic; the shift must be unsigned (bring in zeroes). On some
|
||||
* hardware you could probably optimize the shift in assembler by
|
||||
* using byte-swap instructions
|
||||
* polynomial $edb88320
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* See https://en.wikipedia.org/wiki/Computation_of_cyclic_redundancy_checks
|
||||
* for info on the general algorithm. We use the following configuration:
|
||||
* 32-bit CRC
|
||||
* Polynomial = 0x04C11DB7
|
||||
* MSB-first
|
||||
* Input and output complement
|
||||
* Input and output bit reversal
|
||||
*
|
||||
* CRC32 code derived from work by Gary S. Brown.
|
||||
* This implementation optimizes for size and readability. We only need this for
|
||||
* 28 bytes of A/B booting metadata, so efficiency is largely irrelevant whereas
|
||||
* a 1KiB lookup table can be a significant cost for bootloaders.
|
||||
*/
|
||||
|
||||
#include "avb_sysdeps.h"
|
||||
#include "avb_util.h"
|
||||
|
||||
/* Code taken from FreeBSD 8 */
|
||||
/* Lookup table for reversing 4 bits. */
|
||||
/* clang-format off */
|
||||
static uint8_t reverse_4bit_table[] = {
|
||||
0x0, 0x8, 0x4, 0xC,
|
||||
0x2, 0xA, 0x6, 0xE,
|
||||
0x1, 0x9, 0x5, 0xD,
|
||||
0x3, 0xB, 0x7, 0xF
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
static uint32_t iavb_crc32_tab[] = {
|
||||
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
|
||||
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
|
||||
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
|
||||
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
|
||||
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
|
||||
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
|
||||
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
|
||||
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
|
||||
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
|
||||
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
|
||||
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
|
||||
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
|
||||
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
|
||||
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
|
||||
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
|
||||
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
|
||||
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
|
||||
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
|
||||
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
|
||||
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
|
||||
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
|
||||
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
|
||||
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
|
||||
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
|
||||
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
|
||||
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
|
||||
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
|
||||
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
|
||||
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
|
||||
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
|
||||
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
|
||||
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
|
||||
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
|
||||
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
|
||||
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d};
|
||||
|
||||
/*
|
||||
* A function that calculates the CRC-32 based on the table above is
|
||||
* given below for documentation purposes. An equivalent implementation
|
||||
* of this function that's actually used in the kernel can be found
|
||||
* in sys/libkern.h, where it can be inlined.
|
||||
*/
|
||||
|
||||
static uint32_t iavb_crc32(uint32_t crc_in, const uint8_t* buf, int size) {
|
||||
const uint8_t* p = buf;
|
||||
uint32_t crc;
|
||||
static uint8_t reverse_byte(uint8_t val) {
|
||||
return (reverse_4bit_table[val & 0xF] << 4) | reverse_4bit_table[val >> 4];
|
||||
}
|
||||
|
||||
crc = crc_in ^ ~0U;
|
||||
while (size--)
|
||||
crc = iavb_crc32_tab[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
|
||||
return crc ^ ~0U;
|
||||
static uint32_t reverse_uint32(uint32_t val) {
|
||||
return (reverse_byte(val) << 24) | (reverse_byte(val >> 8) << 16) |
|
||||
(reverse_byte(val >> 16) << 8) | reverse_byte(val >> 24);
|
||||
}
|
||||
|
||||
uint32_t avb_crc32(const uint8_t* buf, size_t size) {
|
||||
return iavb_crc32(0, buf, size);
|
||||
uint32_t crc = 0xFFFFFFFF;
|
||||
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
crc = crc ^ ((uint32_t)reverse_byte(buf[i]) << 24);
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
if (crc & 0x80000000) {
|
||||
crc = (crc << 1) ^ 0x04C11DB7;
|
||||
} else {
|
||||
crc <<= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return reverse_uint32(~crc);
|
||||
}
|
||||
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source Project
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use, copy,
|
||||
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifdef AVB_INSIDE_LIBAVB_H
|
||||
#error "You can't include avb_crypto_ops_impl.h in the public header libavb.h."
|
||||
#endif
|
||||
|
||||
#ifndef AVB_COMPILATION
|
||||
#error "Never include this file, it may only be used from internal avb code."
|
||||
#endif
|
||||
|
||||
#ifndef AVB_CRYPTO_OPS_IMPL_H_
|
||||
#define AVB_CRYPTO_OPS_IMPL_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "avb_sysdeps.h"
|
||||
|
||||
/* Block size in bytes of a SHA-256 digest. */
|
||||
#define AVB_SHA256_BLOCK_SIZE 64
|
||||
|
||||
/* Block size in bytes of a SHA-512 digest. */
|
||||
#define AVB_SHA512_BLOCK_SIZE 128
|
||||
|
||||
/* Data structure used for SHA-256. */
|
||||
typedef struct {
|
||||
uint32_t h[8];
|
||||
uint64_t tot_len;
|
||||
size_t len;
|
||||
uint8_t block[2 * AVB_SHA256_BLOCK_SIZE];
|
||||
} AvbSHA256ImplCtx;
|
||||
|
||||
/* Data structure used for SHA-512. */
|
||||
typedef struct {
|
||||
uint64_t h[8];
|
||||
uint64_t tot_len;
|
||||
size_t len;
|
||||
uint8_t block[2 * AVB_SHA512_BLOCK_SIZE];
|
||||
} AvbSHA512ImplCtx;
|
||||
|
||||
#define AVB_SHA256_CONTEXT_SIZE sizeof(AvbSHA256ImplCtx)
|
||||
#define AVB_SHA512_CONTEXT_SIZE sizeof(AvbSHA512ImplCtx)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AVB_CRYPTO_OPS_IMPL_H_ */
|
@ -1,36 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2022 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.
|
||||
#
|
||||
|
||||
_gsi_gki_product_names := \
|
||||
aosp_arm \
|
||||
aosp_arm64 \
|
||||
aosp_x86 \
|
||||
aosp_x86_64 \
|
||||
gsi_arm \
|
||||
gsi_arm64 \
|
||||
gsi_x86 \
|
||||
gsi_x86_64 \
|
||||
gki_arm64 \
|
||||
gki_x86_64 \
|
||||
|
||||
# Add gki_retrofitting_tools to `m dist` of GSI/GKI for easy pickup.
|
||||
ifneq (,$(filter $(_gsi_gki_product_names),$(TARGET_PRODUCT)))
|
||||
|
||||
droidcore-unbundled: gki_retrofitting_tools
|
||||
|
||||
endif
|
||||
|
||||
_gsi_gki_product_names :=
|
@ -1,74 +0,0 @@
|
||||
# GKI boot image retrofitting tools for upgrading devices
|
||||
|
||||
Starting from Android T the GKI boot images consist of the generic `boot.img`
|
||||
and `init_boot.img`. The `boot.img` contains the generic kernel, and
|
||||
`init_boot.img` contains the generic ramdisk.
|
||||
For upgrading devices whose `vendor_boot` partition is non-existent, this tool
|
||||
(or spec) can be used to retrofit a set of Android T GKI `boot`, `init_boot` and
|
||||
OEM `vendor_boot` partition images back into a single boot image containing the
|
||||
GKI kernel plus generic and vendor ramdisks.
|
||||
|
||||
## Retrofitting the boot images
|
||||
|
||||
1. Download the certified GKI `boot.img`.
|
||||
2. Go to the build artifacts page of `aosp_arm64` on `aosp-master` branch on
|
||||
https://ci.android.com/ and download `gki_retrofitting_tools.zip`.
|
||||
3. Unzip and make sure the tool is in `${PATH}`.
|
||||
|
||||
```bash
|
||||
unzip gki_retrofitting_tools.zip
|
||||
export PATH="$(pwd)/gki_retrofitting_tools:${PATH}"
|
||||
# See tool usage:
|
||||
retrofit_gki --help
|
||||
```
|
||||
|
||||
4. Create the retrofitted image. The `--version` argument lets you choose the
|
||||
boot image header version of the retrofitted boot image. Only version 2 is
|
||||
supported at the moment.
|
||||
|
||||
```bash
|
||||
retrofit_gki --boot boot.img --init_boot init_boot.img \
|
||||
--vendor_boot vendor_boot.img --version 2 -o boot.retrofitted.img
|
||||
```
|
||||
|
||||
## Spec of the retrofitted images
|
||||
|
||||
* The SOURCE `boot.img` must be officially certified Android T (or later) GKI.
|
||||
* The DEST retrofitted boot image must not set the security patch level in its
|
||||
header. This is because the SOURCE images might have different SPL value, thus
|
||||
making the boot header SPL of the retrofitted image ill-defined. The SPL value
|
||||
must be defined by the chained vbmeta image of the `boot` partition.
|
||||
* The `boot signature` of the DEST image is the `boot signature` of the DEST
|
||||
`boot.img`.
|
||||
* The DEST retrofitted boot image must pass the `vts_gki_compliance_test`
|
||||
testcase.
|
||||
|
||||
### Retrofit to boot image V2
|
||||
|
||||
* The `kernel` of the DEST image must be from the SOURCE `boot.img`.
|
||||
* The `ramdisk` of the DEST image must be from the SOURCE `vendor_boot.img` and
|
||||
`init_boot.img`. The DEST `ramdisk` is the ramdisk concatenation of the vendor
|
||||
ramdisk and generic ramdisk.
|
||||
* The `recovery dtbo / acpio` must be empty.
|
||||
* The `dtb` of the DEST image must be from the SOURCE `vendor_boot.img`.
|
||||
* The `boot_signature` section must be appended to the end of the boot image,
|
||||
and its size is zero-padded to 16KiB.
|
||||
|
||||
```
|
||||
+---------------------+
|
||||
| boot header | 1 page
|
||||
+---------------------+
|
||||
| kernel | n pages
|
||||
+---------------------+
|
||||
| * vendor ramdisk |
|
||||
| +generic ramdisk | m pages
|
||||
+---------------------+
|
||||
| second stage | o pages
|
||||
+---------------------+
|
||||
| recovery dtbo/acpio | 0 byte
|
||||
+---------------------+
|
||||
| dtb | q pages
|
||||
+---------------------+
|
||||
| * boot signature | 16384 (16K) bytes
|
||||
+---------------------+
|
||||
```
|
@ -1,231 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2022 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.
|
||||
#
|
||||
|
||||
#
|
||||
# Retrofits GKI boot images for upgrading devices.
|
||||
#
|
||||
|
||||
set -eo errtrace
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage:
|
||||
$0 --boot BOOT --init_boot INIT_BOOT --version {3,4} -o OUTPUT
|
||||
$0 --boot BOOT --init_boot INIT_BOOT --vendor_boot VENDOR_BOOT --version 2 -o OUTPUT
|
||||
|
||||
Options:
|
||||
--boot FILE
|
||||
Path to the generic boot image.
|
||||
--init_boot FILE
|
||||
Path to the generic init_boot image.
|
||||
--vendor_boot FILE
|
||||
Path to the vendor boot image.
|
||||
--version {2,3,4}
|
||||
Boot image header version to retrofit to.
|
||||
-o, --output FILE
|
||||
Path to the output boot image.
|
||||
-v, --verbose
|
||||
Show debug messages.
|
||||
-h, --help, --usage
|
||||
Show this help message.
|
||||
EOF
|
||||
}
|
||||
|
||||
die() {
|
||||
echo >&2 "ERROR:" "${@}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
file_size() {
|
||||
stat -c '%s' "$1"
|
||||
}
|
||||
|
||||
get_arg() {
|
||||
local arg="$1"
|
||||
shift
|
||||
while [[ "$#" -gt 0 ]]; do
|
||||
if [[ "$1" == "${arg}" ]]; then
|
||||
shift
|
||||
echo "$1"
|
||||
return
|
||||
fi
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
TEMP_DIR="$(mktemp -d --tmpdir retrofit_gki.XXXXXXXX)"
|
||||
readonly TEMP_DIR
|
||||
|
||||
exit_handler() {
|
||||
readonly EXIT_CODE="$?"
|
||||
rm -rf "${TEMP_DIR}" ||:
|
||||
exit "${EXIT_CODE}"
|
||||
}
|
||||
|
||||
trap exit_handler EXIT
|
||||
trap 'die "line ${LINENO}, ${FUNCNAME:-<main>}(): \"${BASH_COMMAND}\" returned \"$?\"" ' ERR
|
||||
|
||||
while [[ "$1" =~ ^- ]]; do
|
||||
case "$1" in
|
||||
--boot )
|
||||
shift
|
||||
BOOT_IMAGE="$1"
|
||||
;;
|
||||
--init_boot )
|
||||
shift
|
||||
INIT_BOOT_IMAGE="$1"
|
||||
;;
|
||||
--vendor_boot )
|
||||
shift
|
||||
VENDOR_BOOT_IMAGE="$1"
|
||||
;;
|
||||
--version )
|
||||
shift
|
||||
OUTPUT_BOOT_IMAGE_VERSION="$1"
|
||||
;;
|
||||
-o | --output )
|
||||
shift
|
||||
OUTPUT_BOOT_IMAGE="$1"
|
||||
;;
|
||||
-v | --verbose )
|
||||
VERBOSE=true
|
||||
;;
|
||||
-- )
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-h | --help | --usage )
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
* )
|
||||
echo >&2 "Unexpected flag: '$1'"
|
||||
usage >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
declare -ir OUTPUT_BOOT_IMAGE_VERSION
|
||||
readonly BOOT_IMAGE
|
||||
readonly INIT_BOOT_IMAGE
|
||||
readonly VENDOR_BOOT_IMAGE
|
||||
readonly OUTPUT_BOOT_IMAGE
|
||||
readonly VERBOSE
|
||||
|
||||
# Make sure the input arguments make sense.
|
||||
[[ -f "${BOOT_IMAGE}" ]] ||
|
||||
die "argument '--boot': not a regular file: '${BOOT_IMAGE}'"
|
||||
[[ -f "${INIT_BOOT_IMAGE}" ]] ||
|
||||
die "argument '--init_boot': not a regular file: '${INIT_BOOT_IMAGE}'"
|
||||
if [[ "${OUTPUT_BOOT_IMAGE_VERSION}" -lt 2 ]] || [[ "${OUTPUT_BOOT_IMAGE_VERSION}" -gt 4 ]]; then
|
||||
die "argument '--version': valid choices are {2, 3, 4}"
|
||||
elif [[ "${OUTPUT_BOOT_IMAGE_VERSION}" -eq 2 ]]; then
|
||||
[[ -f "${VENDOR_BOOT_IMAGE}" ]] ||
|
||||
die "argument '--vendor_boot': not a regular file: '${VENDOR_BOOT_IMAGE}'"
|
||||
fi
|
||||
[[ -z "${OUTPUT_BOOT_IMAGE}" ]] &&
|
||||
die "argument '--output': cannot be empty"
|
||||
|
||||
readonly BOOT_IMAGE_WITHOUT_AVB_FOOTER="${TEMP_DIR}/boot.img.without_avb_footer"
|
||||
readonly BOOT_DIR="${TEMP_DIR}/boot"
|
||||
readonly INIT_BOOT_DIR="${TEMP_DIR}/init_boot"
|
||||
readonly VENDOR_BOOT_DIR="${TEMP_DIR}/vendor_boot"
|
||||
readonly VENDOR_BOOT_MKBOOTIMG_ARGS="${TEMP_DIR}/vendor_boot.mkbootimg_args"
|
||||
readonly OUTPUT_RAMDISK="${TEMP_DIR}/out.ramdisk"
|
||||
readonly OUTPUT_BOOT_SIGNATURE="${TEMP_DIR}/out.boot_signature"
|
||||
|
||||
readonly AVBTOOL="${AVBTOOL:-avbtool}"
|
||||
readonly MKBOOTIMG="${MKBOOTIMG:-mkbootimg}"
|
||||
readonly UNPACK_BOOTIMG="${UNPACK_BOOTIMG:-unpack_bootimg}"
|
||||
|
||||
# Fixed boot signature size for easy discovery in VTS.
|
||||
readonly BOOT_SIGNATURE_SIZE=$(( 16 << 10 ))
|
||||
|
||||
|
||||
#
|
||||
# Preparations are done. Now begin the actual work.
|
||||
#
|
||||
|
||||
# Copy the boot image because `avbtool erase_footer` edits the file in-place.
|
||||
cp "${BOOT_IMAGE}" "${BOOT_IMAGE_WITHOUT_AVB_FOOTER}"
|
||||
( [[ -n "${VERBOSE}" ]] && set -x
|
||||
"${AVBTOOL}" erase_footer --image "${BOOT_IMAGE_WITHOUT_AVB_FOOTER}" 2>/dev/null ||:
|
||||
tail -c "${BOOT_SIGNATURE_SIZE}" "${BOOT_IMAGE_WITHOUT_AVB_FOOTER}" > "${OUTPUT_BOOT_SIGNATURE}"
|
||||
"${UNPACK_BOOTIMG}" --boot_img "${BOOT_IMAGE}" --out "${BOOT_DIR}" >/dev/null
|
||||
"${UNPACK_BOOTIMG}" --boot_img "${INIT_BOOT_IMAGE}" --out "${INIT_BOOT_DIR}" >/dev/null
|
||||
)
|
||||
if [[ "$(file_size "${OUTPUT_BOOT_SIGNATURE}")" -ne "${BOOT_SIGNATURE_SIZE}" ]]; then
|
||||
die "boot signature size must be equal to ${BOOT_SIGNATURE_SIZE}"
|
||||
fi
|
||||
|
||||
declare -a mkbootimg_args=()
|
||||
|
||||
if [[ "${OUTPUT_BOOT_IMAGE_VERSION}" -eq 4 ]]; then
|
||||
mkbootimg_args+=( \
|
||||
--header_version 4 \
|
||||
--kernel "${BOOT_DIR}/kernel" \
|
||||
--ramdisk "${INIT_BOOT_DIR}/ramdisk" \
|
||||
)
|
||||
elif [[ "${OUTPUT_BOOT_IMAGE_VERSION}" -eq 3 ]]; then
|
||||
mkbootimg_args+=( \
|
||||
--header_version 3 \
|
||||
--kernel "${BOOT_DIR}/kernel" \
|
||||
--ramdisk "${INIT_BOOT_DIR}/ramdisk" \
|
||||
)
|
||||
elif [[ "${OUTPUT_BOOT_IMAGE_VERSION}" -eq 2 ]]; then
|
||||
( [[ -n "${VERBOSE}" ]] && set -x
|
||||
"${UNPACK_BOOTIMG}" --boot_img "${VENDOR_BOOT_IMAGE}" --out "${VENDOR_BOOT_DIR}" \
|
||||
--format=mkbootimg -0 > "${VENDOR_BOOT_MKBOOTIMG_ARGS}"
|
||||
cat "${VENDOR_BOOT_DIR}/vendor_ramdisk" "${INIT_BOOT_DIR}/ramdisk" > "${OUTPUT_RAMDISK}"
|
||||
)
|
||||
|
||||
declare -a vendor_boot_args=()
|
||||
while IFS= read -r -d '' ARG; do
|
||||
vendor_boot_args+=("${ARG}")
|
||||
done < "${VENDOR_BOOT_MKBOOTIMG_ARGS}"
|
||||
|
||||
pagesize="$(get_arg --pagesize "${vendor_boot_args[@]}")"
|
||||
kernel_offset="$(get_arg --kernel_offset "${vendor_boot_args[@]}")"
|
||||
ramdisk_offset="$(get_arg --ramdisk_offset "${vendor_boot_args[@]}")"
|
||||
tags_offset="$(get_arg --tags_offset "${vendor_boot_args[@]}")"
|
||||
dtb_offset="$(get_arg --dtb_offset "${vendor_boot_args[@]}")"
|
||||
kernel_cmdline="$(get_arg --vendor_cmdline "${vendor_boot_args[@]}")"
|
||||
|
||||
mkbootimg_args+=( \
|
||||
--header_version 2 \
|
||||
--base 0 \
|
||||
--kernel_offset "${kernel_offset}" \
|
||||
--ramdisk_offset "${ramdisk_offset}" \
|
||||
--second_offset 0 \
|
||||
--tags_offset "${tags_offset}" \
|
||||
--dtb_offset "${dtb_offset}" \
|
||||
--cmdline "${kernel_cmdline}" \
|
||||
--pagesize "${pagesize}" \
|
||||
--kernel "${BOOT_DIR}/kernel" \
|
||||
--ramdisk "${OUTPUT_RAMDISK}" \
|
||||
)
|
||||
if [[ -f "${VENDOR_BOOT_DIR}/dtb" ]]; then
|
||||
mkbootimg_args+=(--dtb "${VENDOR_BOOT_DIR}/dtb")
|
||||
fi
|
||||
fi
|
||||
|
||||
( [[ -n "${VERBOSE}" ]] && set -x
|
||||
"${MKBOOTIMG}" "${mkbootimg_args[@]}" --output "${OUTPUT_BOOT_IMAGE}"
|
||||
cat "${OUTPUT_BOOT_SIGNATURE}" >> "${OUTPUT_BOOT_IMAGE}"
|
||||
)
|
@ -1,144 +0,0 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2022 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.
|
||||
#
|
||||
|
||||
set -eo errtrace
|
||||
|
||||
die() {
|
||||
echo >&2 "ERROR:" "${@}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
trap 'die "line ${LINENO}, ${FUNCNAME:-<main>}(): \"${BASH_COMMAND}\" returned \"$?\"" ' ERR
|
||||
|
||||
# Figure out where we are and where to look for test executables.
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||
TEST_DIR="$(pwd)"
|
||||
readonly TEST_DIR
|
||||
readonly TEMP_DIR="${TEST_DIR}/stage.retrofit_gki_test"
|
||||
|
||||
export PATH="${TEST_DIR}:${PATH}"
|
||||
rm -rf "${TEMP_DIR}"
|
||||
mkdir -p "${TEMP_DIR}"
|
||||
|
||||
# Generate some test files.
|
||||
readonly TEST_DTB="${TEMP_DIR}/dtb"
|
||||
readonly TEST_KERNEL="${TEMP_DIR}/kernel"
|
||||
readonly TEST_RAMDISK="${TEMP_DIR}/ramdisk"
|
||||
readonly TEST_VENDOR_RAMDISK="${TEMP_DIR}/vendor_ramdisk"
|
||||
readonly TEST_BOOT_SIGNATURE="${TEMP_DIR}/boot.boot_signature"
|
||||
readonly TEST_V2_RETROFITTED_RAMDISK="${TEMP_DIR}/retrofitted.ramdisk"
|
||||
readonly TEST_BOOT_IMAGE="${TEMP_DIR}/boot.img"
|
||||
readonly TEST_INIT_BOOT_IMAGE="${TEMP_DIR}/init_boot.img"
|
||||
readonly TEST_VENDOR_BOOT_IMAGE="${TEMP_DIR}/vendor_boot.img"
|
||||
|
||||
( # Run these in subshell because dd is noisy.
|
||||
dd if=/dev/urandom of="${TEST_DTB}" bs=1024 count=10
|
||||
dd if=/dev/urandom of="${TEST_KERNEL}" bs=1024 count=10
|
||||
dd if=/dev/urandom of="${TEST_RAMDISK}" bs=1024 count=10
|
||||
dd if=/dev/urandom of="${TEST_VENDOR_RAMDISK}" bs=1024 count=10
|
||||
dd if=/dev/urandom of="${TEST_BOOT_SIGNATURE}" bs=1024 count=16
|
||||
) 2> /dev/null
|
||||
|
||||
cat "${TEST_VENDOR_RAMDISK}" "${TEST_RAMDISK}" > "${TEST_V2_RETROFITTED_RAMDISK}"
|
||||
|
||||
mkbootimg \
|
||||
--header_version 4 \
|
||||
--kernel "${TEST_KERNEL}" \
|
||||
--output "${TEST_BOOT_IMAGE}"
|
||||
cat "${TEST_BOOT_SIGNATURE}" >> "${TEST_BOOT_IMAGE}"
|
||||
avbtool add_hash_footer --image "${TEST_BOOT_IMAGE}" --partition_name boot --partition_size $((20 << 20))
|
||||
|
||||
mkbootimg \
|
||||
--header_version 4 \
|
||||
--ramdisk "${TEST_RAMDISK}" \
|
||||
--output "${TEST_INIT_BOOT_IMAGE}"
|
||||
mkbootimg \
|
||||
--header_version 4 \
|
||||
--pagesize 4096 \
|
||||
--dtb "${TEST_DTB}" \
|
||||
--vendor_ramdisk "${TEST_VENDOR_RAMDISK}" \
|
||||
--vendor_boot "${TEST_VENDOR_BOOT_IMAGE}"
|
||||
|
||||
readonly RETROFITTED_IMAGE="${TEMP_DIR}/retrofitted_boot.img"
|
||||
readonly RETROFITTED_IMAGE_DIR="${TEMP_DIR}/retrofitted_boot.img.unpack"
|
||||
readonly BOOT_SIGNATURE_SIZE=$(( 16 << 10 ))
|
||||
|
||||
|
||||
#
|
||||
# Begin test.
|
||||
#
|
||||
echo >&2 "TEST: retrofit to boot v4"
|
||||
|
||||
retrofit_gki.sh \
|
||||
--boot "${TEST_BOOT_IMAGE}" \
|
||||
--init_boot "${TEST_INIT_BOOT_IMAGE}" \
|
||||
--version 4 \
|
||||
--output "${RETROFITTED_IMAGE}"
|
||||
|
||||
rm -rf "${RETROFITTED_IMAGE_DIR}"
|
||||
unpack_bootimg --boot_img "${RETROFITTED_IMAGE}" --out "${RETROFITTED_IMAGE_DIR}" > /dev/null
|
||||
tail -c "${BOOT_SIGNATURE_SIZE}" "${RETROFITTED_IMAGE}" > "${RETROFITTED_IMAGE_DIR}/boot_signature"
|
||||
|
||||
cmp -s "${TEST_KERNEL}" "${RETROFITTED_IMAGE_DIR}/kernel" ||
|
||||
die "unexpected diff: kernel"
|
||||
cmp -s "${TEST_RAMDISK}" "${RETROFITTED_IMAGE_DIR}/ramdisk" ||
|
||||
die "unexpected diff: ramdisk"
|
||||
cmp -s "${TEST_BOOT_SIGNATURE}" "${RETROFITTED_IMAGE_DIR}/boot_signature" ||
|
||||
die "unexpected diff: boot signature"
|
||||
|
||||
|
||||
echo >&2 "TEST: retrofit to boot v3"
|
||||
|
||||
retrofit_gki.sh \
|
||||
--boot "${TEST_BOOT_IMAGE}" \
|
||||
--init_boot "${TEST_INIT_BOOT_IMAGE}" \
|
||||
--version 3 \
|
||||
--output "${RETROFITTED_IMAGE}"
|
||||
|
||||
rm -rf "${RETROFITTED_IMAGE_DIR}"
|
||||
unpack_bootimg --boot_img "${RETROFITTED_IMAGE}" --out "${RETROFITTED_IMAGE_DIR}" > /dev/null
|
||||
tail -c "${BOOT_SIGNATURE_SIZE}" "${RETROFITTED_IMAGE}" > "${RETROFITTED_IMAGE_DIR}/boot_signature"
|
||||
|
||||
cmp -s "${TEST_KERNEL}" "${RETROFITTED_IMAGE_DIR}/kernel" ||
|
||||
die "unexpected diff: kernel"
|
||||
cmp -s "${TEST_RAMDISK}" "${RETROFITTED_IMAGE_DIR}/ramdisk" ||
|
||||
die "unexpected diff: ramdisk"
|
||||
cmp -s "${TEST_BOOT_SIGNATURE}" "${RETROFITTED_IMAGE_DIR}/boot_signature" ||
|
||||
die "unexpected diff: boot signature"
|
||||
|
||||
|
||||
echo >&2 "TEST: retrofit to boot v2"
|
||||
|
||||
retrofit_gki.sh \
|
||||
--boot "${TEST_BOOT_IMAGE}" \
|
||||
--init_boot "${TEST_INIT_BOOT_IMAGE}" \
|
||||
--vendor_boot "${TEST_VENDOR_BOOT_IMAGE}" \
|
||||
--version 2 \
|
||||
--output "${RETROFITTED_IMAGE}"
|
||||
|
||||
rm -rf "${RETROFITTED_IMAGE_DIR}"
|
||||
unpack_bootimg --boot_img "${RETROFITTED_IMAGE}" --out "${RETROFITTED_IMAGE_DIR}" > /dev/null
|
||||
tail -c "${BOOT_SIGNATURE_SIZE}" "${RETROFITTED_IMAGE}" > "${RETROFITTED_IMAGE_DIR}/boot_signature"
|
||||
|
||||
cmp -s "${TEST_DTB}" "${RETROFITTED_IMAGE_DIR}/dtb" ||
|
||||
die "unexpected diff: dtb"
|
||||
cmp -s "${TEST_KERNEL}" "${RETROFITTED_IMAGE_DIR}/kernel" ||
|
||||
die "unexpected diff: kernel"
|
||||
cmp -s "${TEST_V2_RETROFITTED_RAMDISK}" "${RETROFITTED_IMAGE_DIR}/ramdisk" ||
|
||||
die "unexpected diff: ramdisk"
|
||||
cmp -s "${TEST_BOOT_SIGNATURE}" "${RETROFITTED_IMAGE_DIR}/boot_signature" ||
|
||||
die "unexpected diff: boot signature"
|
@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
Loading…
Reference in New Issue