android: fix get wrong ramdisk address when avb verify
- add interface to get android avb enable state;
- get ramdisk from "ramdisk_addr_r" only when android avb disabled
and CONFIG_ANDROID_BOOT_IMAGE_SEPARATE is enabled;
(fixes: 644e344 android: support loading android image separate)
Change-Id: I7280f911a0c5db851d119acb458b3f335dc28bce
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
This commit is contained in:
parent
ecc8fa7230
commit
8e66ecd25d
|
|
@ -863,6 +863,17 @@ static int load_android_image(struct blk_desc *dev_desc,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static bool avb_enabled;
|
||||
void android_avb_set_enabled(bool enable)
|
||||
{
|
||||
avb_enabled = enable;
|
||||
}
|
||||
|
||||
bool android_avb_is_enabled(void)
|
||||
{
|
||||
return avb_enabled;
|
||||
}
|
||||
|
||||
int android_bootloader_boot_flow(struct blk_desc *dev_desc,
|
||||
unsigned long load_address)
|
||||
{
|
||||
|
|
@ -958,6 +969,7 @@ int android_bootloader_boot_flow(struct blk_desc *dev_desc,
|
|||
|
||||
if (vboot_flag) {
|
||||
printf("SecureBoot enabled, AVB verify\n");
|
||||
android_avb_set_enabled(false);
|
||||
if (android_slot_verify(boot_partname, &load_address,
|
||||
slot_suffix))
|
||||
return -1;
|
||||
|
|
@ -970,11 +982,13 @@ int android_bootloader_boot_flow(struct blk_desc *dev_desc,
|
|||
printf("SecureBoot disabled, AVB skip\n");
|
||||
env_update("bootargs",
|
||||
"androidboot.verifiedbootstate=orange");
|
||||
android_avb_set_enabled(false);
|
||||
if (load_android_image(dev_desc, boot_partname,
|
||||
slot_suffix, &load_address))
|
||||
return -1;
|
||||
} else {
|
||||
printf("SecureBoot enabled, AVB verify\n");
|
||||
android_avb_set_enabled(true);
|
||||
if (android_slot_verify(boot_partname, &load_address,
|
||||
slot_suffix))
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <common.h>
|
||||
#include <image.h>
|
||||
#include <android_image.h>
|
||||
#include <android_bootloader.h>
|
||||
#include <malloc.h>
|
||||
#include <mapmem.h>
|
||||
#include <errno.h>
|
||||
|
|
@ -193,30 +194,37 @@ ulong android_image_get_kload(const struct andr_img_hdr *hdr)
|
|||
int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
|
||||
ulong *rd_data, ulong *rd_len)
|
||||
{
|
||||
bool avb_enabled = false;
|
||||
|
||||
#ifdef CONFIG_ANDROID_BOOTLOADER
|
||||
avb_enabled = android_avb_is_enabled();
|
||||
#endif
|
||||
|
||||
if (!hdr->ramdisk_size) {
|
||||
*rd_data = *rd_len = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* We load ramdisk at "ramdisk_addr_r" when CONFIG_ANDROID_BOOT_IMAGE_SEPARATE
|
||||
* CONFIG_USING_KERNEL_DTB is enabled.
|
||||
*/
|
||||
#ifdef CONFIG_ANDROID_BOOT_IMAGE_SEPARATE
|
||||
ulong ramdisk_addr_r;
|
||||
/*
|
||||
* We have load ramdisk at "ramdisk_addr_r" when android avb is
|
||||
* disabled and CONFIG_ANDROID_BOOT_IMAGE_SEPARATE enabled.
|
||||
*/
|
||||
if (!avb_enabled && IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE_SEPARATE)) {
|
||||
ulong ramdisk_addr_r;
|
||||
|
||||
ramdisk_addr_r = env_get_ulong("ramdisk_addr_r", 16, 0);
|
||||
if (!ramdisk_addr_r) {
|
||||
printf("No Found Ramdisk Load Address.\n");
|
||||
return -1;
|
||||
ramdisk_addr_r = env_get_ulong("ramdisk_addr_r", 16, 0);
|
||||
if (!ramdisk_addr_r) {
|
||||
printf("No Found Ramdisk Load Address.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*rd_data = ramdisk_addr_r;
|
||||
} else {
|
||||
*rd_data = (unsigned long)hdr;
|
||||
*rd_data += hdr->page_size;
|
||||
*rd_data += ALIGN(hdr->kernel_size, hdr->page_size);
|
||||
}
|
||||
|
||||
*rd_data = ramdisk_addr_r;
|
||||
#else
|
||||
*rd_data = (unsigned long)hdr;
|
||||
*rd_data += hdr->page_size;
|
||||
*rd_data += ALIGN(hdr->kernel_size, hdr->page_size);
|
||||
#endif
|
||||
*rd_len = hdr->ramdisk_size;
|
||||
|
||||
printf("RAM disk load addr 0x%08lx size %u KiB\n",
|
||||
|
|
@ -228,32 +236,40 @@ int android_image_get_ramdisk(const struct andr_img_hdr *hdr,
|
|||
int android_image_get_fdt(const struct andr_img_hdr *hdr,
|
||||
ulong *rd_data)
|
||||
{
|
||||
bool avb_enabled = false;
|
||||
|
||||
#ifdef CONFIG_ANDROID_BOOTLOADER
|
||||
avb_enabled = android_avb_is_enabled();
|
||||
#endif
|
||||
|
||||
if (!hdr->second_size) {
|
||||
*rd_data = 0;
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
* We load fdt at "fdt_addr_r" when CONFIG_ANDROID_BOOT_IMAGE_SEPARATE or
|
||||
* or CONFIG_USING_KERNEL_DTB is enabled.
|
||||
*/
|
||||
#if defined(CONFIG_ANDROID_BOOT_IMAGE_SEPARATE) || \
|
||||
defined(CONFIG_USING_KERNEL_DTB)
|
||||
ulong fdt_addr_r;
|
||||
|
||||
fdt_addr_r = env_get_ulong("fdt_addr_r", 16, 0);
|
||||
if (!fdt_addr_r) {
|
||||
printf("No Found FDT Load Address.\n");
|
||||
return -1;
|
||||
/*
|
||||
* We have load fdt at "fdt_addr_r" when android avb is
|
||||
* disabled and CONFIG_ANDROID_BOOT_IMAGE_SEPARATE enabled;
|
||||
* or CONFIG_USING_KERNEL_DTB is enabled.
|
||||
*/
|
||||
if (IS_ENABLED(CONFIG_USING_KERNEL_DTB) ||
|
||||
(!avb_enabled && IS_ENABLED(CONFIG_ANDROID_BOOT_IMAGE_SEPARATE))) {
|
||||
ulong fdt_addr_r;
|
||||
|
||||
fdt_addr_r = env_get_ulong("fdt_addr_r", 16, 0);
|
||||
if (!fdt_addr_r) {
|
||||
printf("No Found FDT Load Address.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*rd_data = fdt_addr_r;
|
||||
} else {
|
||||
*rd_data = (unsigned long)hdr;
|
||||
*rd_data += hdr->page_size;
|
||||
*rd_data += ALIGN(hdr->kernel_size, hdr->page_size);
|
||||
*rd_data += ALIGN(hdr->ramdisk_size, hdr->page_size);
|
||||
}
|
||||
|
||||
*rd_data = fdt_addr_r;
|
||||
#else
|
||||
*rd_data = (unsigned long)hdr;
|
||||
*rd_data += hdr->page_size;
|
||||
*rd_data += ALIGN(hdr->kernel_size, hdr->page_size);
|
||||
*rd_data += ALIGN(hdr->ramdisk_size, hdr->page_size);
|
||||
#endif
|
||||
|
||||
printf("FDT load addr 0x%08x size %u KiB\n",
|
||||
hdr->second_addr, DIV_ROUND_UP(hdr->second_size, 1024));
|
||||
|
||||
|
|
@ -361,7 +377,6 @@ long android_image_load(struct blk_desc *dev_desc,
|
|||
u32 kload_addr;
|
||||
u32 blkcnt;
|
||||
struct andr_img_hdr *hdr;
|
||||
__maybe_unused uint8_t vboot_flag = 0;
|
||||
|
||||
if (max_size < part_info->blksz)
|
||||
return -1;
|
||||
|
|
@ -417,13 +432,8 @@ long android_image_load(struct blk_desc *dev_desc,
|
|||
debug("Loading Android Image (%lu blocks) to 0x%lx... ",
|
||||
blk_cnt, load_address);
|
||||
|
||||
#if defined(CONFIG_ANDROID_AVB) && defined(CONFIG_OPTEE_CLIENT)
|
||||
if (trusty_read_vbootkey_enable_flag(&vboot_flag))
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ANDROID_BOOT_IMAGE_SEPARATE
|
||||
if (!vboot_flag) {
|
||||
if (!android_avb_is_enabled()) {
|
||||
char *fdt_high = env_get("fdt_high");
|
||||
char *ramdisk_high = env_get("initrd_high");
|
||||
|
||||
|
|
|
|||
|
|
@ -94,4 +94,10 @@ char *android_str_append(char *base_name, char *slot_suffix);
|
|||
*/
|
||||
int android_fdt_overlay_apply(void *fdt_addr);
|
||||
|
||||
/** android_avb_is_enabled- get avb enable state.
|
||||
* *
|
||||
* @return true on enabled, otherwise disabled;
|
||||
*/
|
||||
bool android_avb_is_enabled(void);
|
||||
|
||||
#endif /* __ANDROID_BOOTLOADER_H */
|
||||
|
|
|
|||
Loading…
Reference in New Issue