Merge "Update retrofit_gki.sh for new init_boot plan" am: ac75382f8b am: 7782ab502d

Original change: https://android-review.googlesource.com/c/platform/system/tools/mkbootimg/+/1976890

Change-Id: I606e4a3050556bdd2302fdeaff2b772cecd2e919
diff --git a/gki/README.md b/gki/README.md
index d080f53..628e52a 100644
--- a/gki/README.md
+++ b/gki/README.md
@@ -1,15 +1,16 @@
-# Android T GKI boot image retrofitting tools
+# 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 `init_boot` partition is non-existent, this tool
-(or spec) can be used to retrofit a set of Android T GKI `boot` and `init_boot`
-partition images back into a single *retrofitted GKI boot image*.
+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` and `init_boot.img`.
+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}`.
@@ -22,68 +23,26 @@
    ```
 
 4. Create the retrofitted image. The `--version` argument lets you choose the
-   boot image header version of the retrofitted image. You would have to choose
-   this value according to the bootloader capabilities.
+   boot image header version of the retrofitted boot image. Only version 2 is
+   supported at the moment.
 
    ```bash
-   # Retrofit to boot v4:
-   retrofit_gki --boot boot.img --init_boot init_boot.img \
-     --version 4 -o boot.retrofitted.img
-   # Retrofit to boot v2:
    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` and `init_boot.img` must be officially certified Android
-  T (or later) GKI.
+* 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 `boot.img` and `init_boot.img` 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 concatenation of the
-  `boot signature` from the DEST `boot.img` and `init_boot.img`.
+  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 V4
-
-* The `kernel` of the DEST image must be from the SOURCE `boot.img`.
-* The `ramdisk` of the DEST image must be from the SOURCE `init_boot.img`.
-
-```
-  +---------------------+
-  | boot header         | 4096 bytes
-  +---------------------+
-  | kernel              | m pages
-  +---------------------+
-  | ramdisk             | n pages
-  +---------------------+
-  | boot signature      | g pages
-  +---------------------+
-```
-
-### Retrofit to boot image V3
-
-* The `kernel` of the DEST image must be from the SOURCE `boot.img`.
-* The `ramdisk` of the DEST image must be from the SOURCE `init_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         | 4096 bytes
-  +---------------------+
-  | kernel              | m pages
-  +---------------------+
-  | ramdisk             | n pages
-  +---------------------+
-  | * boot signature    | 16384 (16K) bytes
-  +---------------------+
-```
-
 ### Retrofit to boot image V2
 
 * The `kernel` of the DEST image must be from the SOURCE `boot.img`.
diff --git a/gki/retrofit_gki.sh b/gki/retrofit_gki.sh
index 880831d..6dec2e2 100755
--- a/gki/retrofit_gki.sh
+++ b/gki/retrofit_gki.sh
@@ -162,7 +162,7 @@
 ( [[ -n "${VERBOSE}" ]] && set -x
   "${UNPACK_BOOTIMG}" --boot_img "${BOOT_IMAGE}" --out "${BOOT_DIR}" >/dev/null
   "${UNPACK_BOOTIMG}" --boot_img "${INIT_BOOT_IMAGE}" --out "${INIT_BOOT_DIR}" >/dev/null
-  cat "${BOOT_DIR}/boot_signature" "${INIT_BOOT_DIR}/boot_signature" > "${OUTPUT_BOOT_SIGNATURE}"
+  cp "${BOOT_DIR}/boot_signature" "${OUTPUT_BOOT_SIGNATURE}"
 )
 
 declare -a mkbootimg_args=()
diff --git a/gki/retrofit_gki_test.sh b/gki/retrofit_gki_test.sh
index 5810798..41da2c3 100755
--- a/gki/retrofit_gki_test.sh
+++ b/gki/retrofit_gki_test.sh
@@ -40,7 +40,6 @@
 readonly TEST_RAMDISK="${TEMP_DIR}/ramdisk"
 readonly TEST_VENDOR_RAMDISK="${TEMP_DIR}/vendor_ramdisk"
 readonly TEST_KERNEL_SIGNATURE="${TEMP_DIR}/kernel.boot_signature"
-readonly TEST_RAMDISK_SIGNATURE="${TEMP_DIR}/ramdisk.boot_signature"
 
 readonly TEST_V2_RETROFITTED_RAMDISK="${TEMP_DIR}/retrofitted.ramdisk"
 readonly TEST_RETROFITTED_SIGNATURE="${TEMP_DIR}/retrofitted.boot_signature"
@@ -54,13 +53,12 @@
   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_KERNEL_SIGNATURE}" bs=1024 count=1
-  dd if=/dev/urandom of="${TEST_RAMDISK_SIGNATURE}" bs=1024 count=1
   dd if=/dev/urandom of="${TEST_DTB}" bs=1024 count=10
   dd if=/dev/urandom of="${TEST_VENDOR_RAMDISK}" bs=1024 count=10
 ) 2> /dev/null
 
 cat "${TEST_VENDOR_RAMDISK}" "${TEST_RAMDISK}" > "${TEST_V2_RETROFITTED_RAMDISK}"
-cat "${TEST_KERNEL_SIGNATURE}" "${TEST_RAMDISK_SIGNATURE}" > "${TEST_RETROFITTED_SIGNATURE}"
+cp "${TEST_KERNEL_SIGNATURE}" "${TEST_RETROFITTED_SIGNATURE}"
 cp "${TEST_RETROFITTED_SIGNATURE}" "${TEST_PADDED_RETROFITTED_SIGNATURE}"
 truncate -s $(( 16 << 10 )) "${TEST_PADDED_RETROFITTED_SIGNATURE}"
 
@@ -72,7 +70,6 @@
 mkbootimg \
   --header_version 4 \
   --ramdisk "${TEST_RAMDISK}" \
-  --boot_signature "${TEST_RAMDISK_SIGNATURE}" \
   --output "${TEST_INIT_BOOT_IMAGE}"
 mkbootimg \
   --header_version 4 \