common: android: clean up code
Signed-off-by: Joseph Chen <chenjh@rock-chips.com> Change-Id: I98dfd54edd813f892c5f2717a694b2424b8ecded
This commit is contained in:
parent
f870210e35
commit
69b1ad4693
|
|
@ -846,11 +846,10 @@ __weak int board_select_fdt_index(ulong dt_table_hdr)
|
|||
|
||||
static int android_get_dtbo(ulong *fdt_dtbo,
|
||||
const struct andr_img_hdr *hdr,
|
||||
int *index, int boot_mode)
|
||||
int *index, const char *part_dtbo)
|
||||
{
|
||||
struct dt_table_header *dt_hdr = NULL;
|
||||
struct blk_desc *dev_desc;
|
||||
const char *part_name;
|
||||
disk_partition_t part_info;
|
||||
u32 blk_offset, blk_cnt;
|
||||
void *buf;
|
||||
|
|
@ -859,49 +858,34 @@ static int android_get_dtbo(ulong *fdt_dtbo,
|
|||
int e_idx;
|
||||
int ret;
|
||||
|
||||
/* Get partition according to boot mode */
|
||||
if (boot_mode == BOOT_MODE_RECOVERY)
|
||||
part_name = PART_RECOVERY;
|
||||
else
|
||||
part_name = PART_DTBO;
|
||||
|
||||
/* Get partition info */
|
||||
dev_desc = rockchip_get_bootdev();
|
||||
if (!dev_desc) {
|
||||
printf("%s: dev_desc is NULL!\n", __func__);
|
||||
if (!dev_desc)
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = part_get_info_by_name(dev_desc, part_name, &part_info);
|
||||
ret = part_get_info_by_name(dev_desc, part_dtbo, &part_info);
|
||||
if (ret < 0) {
|
||||
printf("%s: failed to get %s part info, ret=%d\n",
|
||||
__func__, part_name, ret);
|
||||
printf("No %s partition, ret=%d\n", part_dtbo, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Check dt table header */
|
||||
if (!strcmp(part_name, PART_RECOVERY))
|
||||
if (!strcmp(part_dtbo, PART_RECOVERY))
|
||||
blk_offset = part_info.start +
|
||||
(hdr->recovery_dtbo_offset / part_info.blksz);
|
||||
else
|
||||
blk_offset = part_info.start;
|
||||
|
||||
dt_hdr = memalign(ARCH_DMA_MINALIGN, part_info.blksz);
|
||||
if (!dt_hdr) {
|
||||
printf("%s: out of memory for dt header!\n", __func__);
|
||||
if (!dt_hdr)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
ret = blk_dread(dev_desc, blk_offset, 1, dt_hdr);
|
||||
if (ret != 1) {
|
||||
printf("%s: failed to read dt table header\n",
|
||||
__func__);
|
||||
if (ret != 1)
|
||||
goto out1;
|
||||
}
|
||||
|
||||
if (!android_dt_check_header((ulong)dt_hdr)) {
|
||||
printf("%s: Error: invalid dt table header: 0x%x\n",
|
||||
__func__, dt_hdr->magic);
|
||||
printf("DTBO: invalid dt table header: 0x%x\n", dt_hdr->magic);
|
||||
ret = -EINVAL;
|
||||
goto out1;
|
||||
}
|
||||
|
|
@ -915,17 +899,13 @@ static int android_get_dtbo(ulong *fdt_dtbo,
|
|||
/* Read all DT Image */
|
||||
buf = memalign(ARCH_DMA_MINALIGN, part_info.blksz * blk_cnt);
|
||||
if (!buf) {
|
||||
printf("%s: out of memory for %s part!\n", __func__, part_name);
|
||||
ret = -ENOMEM;
|
||||
goto out1;
|
||||
}
|
||||
|
||||
ret = blk_dread(dev_desc, blk_offset, blk_cnt, buf);
|
||||
if (ret != blk_cnt) {
|
||||
printf("%s: failed to read dtbo, blk_cnt=%d, ret=%d\n",
|
||||
__func__, blk_cnt, ret);
|
||||
if (ret != blk_cnt)
|
||||
goto out2;
|
||||
}
|
||||
|
||||
e_idx = board_select_fdt_index((ulong)buf);
|
||||
if (e_idx < 0) {
|
||||
|
|
@ -948,7 +928,7 @@ static int android_get_dtbo(ulong *fdt_dtbo,
|
|||
|
||||
free(dt_hdr);
|
||||
debug("ANDROID: Loading dt entry to 0x%lx size 0x%x idx %d from \"%s\" part\n",
|
||||
e_addr, e_size, e_idx, part_name);
|
||||
e_addr, e_size, e_idx, part_dtbo);
|
||||
|
||||
return 0;
|
||||
|
||||
|
|
@ -964,38 +944,31 @@ int android_fdt_overlay_apply(void *fdt_addr)
|
|||
{
|
||||
struct andr_img_hdr *hdr;
|
||||
struct blk_desc *dev_desc;
|
||||
const char *part_name;
|
||||
const char *part_boot;
|
||||
disk_partition_t part_info;
|
||||
char *part_dtbo;
|
||||
char buf[32] = {0};
|
||||
u32 blk_cnt;
|
||||
ulong fdt_dtbo = -1;
|
||||
int boot_mode;
|
||||
int index = -1;
|
||||
int ret;
|
||||
|
||||
boot_mode = rockchip_get_boot_mode();
|
||||
#ifdef CONFIG_ANDROID_AB
|
||||
if (boot_mode == BOOT_MODE_RECOVERY)
|
||||
boot_mode = BOOT_MODE_NORMAL;
|
||||
#endif
|
||||
if (boot_mode == BOOT_MODE_RECOVERY)
|
||||
part_name = PART_RECOVERY;
|
||||
else
|
||||
part_name = PART_BOOT;
|
||||
if (IS_ENABLED(CONFIG_ANDROID_AB) ||
|
||||
(rockchip_get_boot_mode() != BOOT_MODE_RECOVERY)) {
|
||||
part_boot = PART_BOOT;
|
||||
part_dtbo = PART_DTBO;
|
||||
} else {
|
||||
part_boot = PART_RECOVERY;
|
||||
part_dtbo = PART_RECOVERY;
|
||||
}
|
||||
|
||||
/* Get partition info */
|
||||
dev_desc = rockchip_get_bootdev();
|
||||
if (!dev_desc) {
|
||||
printf("%s: dev_desc is NULL!\n", __func__);
|
||||
if (!dev_desc)
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = part_get_info_by_name(dev_desc, part_name, &part_info);
|
||||
if (ret < 0) {
|
||||
printf("%s: failed to get %s part info, ret=%d\n",
|
||||
__func__, part_name, ret);
|
||||
ret = part_get_info_by_name(dev_desc, part_boot, &part_info);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
blk_cnt = DIV_ROUND_UP(sizeof(*hdr), part_info.blksz);
|
||||
hdr = memalign(ARCH_DMA_MINALIGN, part_info.blksz * blk_cnt);
|
||||
|
|
@ -1006,7 +979,7 @@ int android_fdt_overlay_apply(void *fdt_addr)
|
|||
|
||||
ret = blk_dread(dev_desc, part_info.start, blk_cnt, hdr);
|
||||
if (ret != blk_cnt) {
|
||||
printf("%s: failed to read %s hdr!\n", __func__, part_name);
|
||||
printf("%s: failed to read %s hdr!\n", __func__, part_boot);
|
||||
goto out;
|
||||
}
|
||||
|
||||
|
|
@ -1024,7 +997,7 @@ int android_fdt_overlay_apply(void *fdt_addr)
|
|||
goto out;
|
||||
}
|
||||
|
||||
ret = android_get_dtbo(&fdt_dtbo, (void *)hdr, &index, boot_mode);
|
||||
ret = android_get_dtbo(&fdt_dtbo, (void *)hdr, &index, part_dtbo);
|
||||
if (!ret) {
|
||||
phys_size_t fdt_size;
|
||||
/* Must incease size before overlay */
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
#define ANDROID_IMAGE_DEFAULT_KERNEL_ADDR 0x10008000
|
||||
#define ANDROID_ARG_FDT_FILENAME "rk-kernel.dtb"
|
||||
#define ANDROID_ARG_FDT_FILENAME "rk-kernel.dtb"
|
||||
#define ANDROID_Q_VER 10
|
||||
|
||||
/* Defined by rockchip legacy mkboot tool(SDK version < 8.1) */
|
||||
|
|
@ -47,15 +47,15 @@ u32 android_bcb_msg_sector_offset(void)
|
|||
{
|
||||
/*
|
||||
* Rockchip platforms defines BCB message at the 16KB offset of
|
||||
* misc partition while the Google defines it at 0x0 offset.
|
||||
* misc partition while the Google defines it at 0x00 offset.
|
||||
*
|
||||
* From Android-Q, the 0x0 offset is mandary on Google VTS, so that
|
||||
* From Android-Q, the 0x00 offset is mandary on Google VTS, so that
|
||||
* this is a compatibility according to android image 'os_version'.
|
||||
*/
|
||||
#ifdef CONFIG_RKIMG_BOOTLOADER
|
||||
return (android_image_major_version() >= ANDROID_Q_VER) ? 0x0 : 0x20;
|
||||
return (android_image_major_version() >= ANDROID_Q_VER) ? 0x00 : 0x20;
|
||||
#else
|
||||
return 0x0;
|
||||
return 0x00;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -296,7 +296,7 @@ typedef enum {
|
|||
IMG_MAX,
|
||||
} img_t;
|
||||
|
||||
static int image_read(img_t img, struct andr_img_hdr *hdr,
|
||||
static int image_load(img_t img, struct andr_img_hdr *hdr,
|
||||
ulong blkstart, void *ram_base,
|
||||
struct udevice *crypto)
|
||||
{
|
||||
|
|
@ -422,7 +422,7 @@ static int android_image_separate(struct andr_img_hdr *hdr,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* set for image_read(IMG_KERNEL, ...) */
|
||||
/* set for image_load(IMG_KERNEL, ...) */
|
||||
env_set_hex("android_addr_r", (ulong)load_address);
|
||||
bstart = part ? part->start : 0;
|
||||
|
||||
|
|
@ -457,20 +457,20 @@ static int android_image_separate(struct andr_img_hdr *hdr,
|
|||
crypto_sha_init(dev, &ctx);
|
||||
|
||||
/* load, never change order ! */
|
||||
if (image_read(IMG_RK_DTB, hdr, bstart, ram_base, NULL))
|
||||
if (image_load(IMG_RK_DTB, hdr, bstart, ram_base, NULL))
|
||||
return -1;
|
||||
if (image_read(IMG_KERNEL, hdr, bstart, ram_base, dev))
|
||||
if (image_load(IMG_KERNEL, hdr, bstart, ram_base, dev))
|
||||
return -1;
|
||||
if (image_read(IMG_RAMDISK, hdr, bstart, ram_base, dev))
|
||||
if (image_load(IMG_RAMDISK, hdr, bstart, ram_base, dev))
|
||||
return -1;
|
||||
if (image_read(IMG_SECOND, hdr, bstart, ram_base, dev))
|
||||
if (image_load(IMG_SECOND, hdr, bstart, ram_base, dev))
|
||||
return -1;
|
||||
if (hdr->header_version > 0) {
|
||||
if (image_read(IMG_RECOVERY_DTBO, hdr, bstart, ram_base, dev))
|
||||
if (image_load(IMG_RECOVERY_DTBO, hdr, bstart, ram_base, dev))
|
||||
return -1;
|
||||
}
|
||||
if (hdr->header_version > 1) {
|
||||
if (image_read(IMG_DTB, hdr, bstart, ram_base, dev))
|
||||
if (image_load(IMG_DTB, hdr, bstart, ram_base, dev))
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -484,20 +484,20 @@ static int android_image_separate(struct andr_img_hdr *hdr,
|
|||
}
|
||||
|
||||
#else /* !(CONFIG_DM_CRYPTO && CONFIG_ANDROID_BOOT_IMAGE_HASH) */
|
||||
if (image_read(IMG_RK_DTB, hdr, bstart, ram_base, NULL))
|
||||
if (image_load(IMG_RK_DTB, hdr, bstart, ram_base, NULL))
|
||||
return -1;
|
||||
if (image_read(IMG_KERNEL, hdr, bstart, ram_base, NULL))
|
||||
if (image_load(IMG_KERNEL, hdr, bstart, ram_base, NULL))
|
||||
return -1;
|
||||
if (image_read(IMG_RAMDISK, hdr, bstart, ram_base, NULL))
|
||||
if (image_load(IMG_RAMDISK, hdr, bstart, ram_base, NULL))
|
||||
return -1;
|
||||
if (image_read(IMG_SECOND, hdr, bstart, ram_base, NULL))
|
||||
if (image_load(IMG_SECOND, hdr, bstart, ram_base, NULL))
|
||||
return -1;
|
||||
if (hdr->header_version > 0) {
|
||||
if (image_read(IMG_RECOVERY_DTBO, hdr, bstart, ram_base, NULL))
|
||||
if (image_load(IMG_RECOVERY_DTBO, hdr, bstart, ram_base, NULL))
|
||||
return -1;
|
||||
}
|
||||
if (hdr->header_version > 1) {
|
||||
if (image_read(IMG_DTB, hdr, bstart, ram_base, NULL))
|
||||
if (image_load(IMG_DTB, hdr, bstart, ram_base, NULL))
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -508,17 +508,12 @@ static int android_image_separate(struct andr_img_hdr *hdr,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* 'boot_android' cmd use "kernel_addr_r" as default load address !
|
||||
* We update it according to compress type and "kernel_addr_c/r".
|
||||
*/
|
||||
int android_image_parse_comp(struct andr_img_hdr *hdr, ulong *load_addr)
|
||||
static ulong android_image_get_comp_addr(struct andr_img_hdr *hdr, int comp)
|
||||
{
|
||||
ulong kernel_addr_c;
|
||||
int comp;
|
||||
ulong load_addr = 0;
|
||||
|
||||
kernel_addr_c = env_get_ulong("kernel_addr_c", 16, 0);
|
||||
comp = android_image_parse_kernel_comp(hdr);
|
||||
|
||||
#ifdef CONFIG_ARM64
|
||||
/*
|
||||
|
|
@ -538,7 +533,7 @@ int android_image_parse_comp(struct andr_img_hdr *hdr, ulong *load_addr)
|
|||
env_set_hex("kernel_addr_c", comp_addr);
|
||||
}
|
||||
|
||||
*load_addr = comp_addr - hdr->page_size;
|
||||
load_addr = comp_addr - hdr->page_size;
|
||||
}
|
||||
#else
|
||||
/*
|
||||
|
|
@ -555,22 +550,40 @@ int android_image_parse_comp(struct andr_img_hdr *hdr, ulong *load_addr)
|
|||
/* input load_addr is for Image, nothing to do */
|
||||
} else {
|
||||
/* input load_addr is for lz4/zImage, set default addr for Image */
|
||||
*load_addr = CONFIG_SYS_SDRAM_BASE + 0x8000;
|
||||
env_set_hex("kernel_addr_r", *load_addr);
|
||||
load_addr = CONFIG_SYS_SDRAM_BASE + 0x8000;
|
||||
env_set_hex("kernel_addr_r", load_addr);
|
||||
|
||||
*load_addr -= hdr->page_size;
|
||||
load_addr -= hdr->page_size;
|
||||
}
|
||||
} else {
|
||||
if (kernel_addr_c) {
|
||||
/* input load_addr is for Image, so use another for lz4/zImage */
|
||||
*load_addr = kernel_addr_c - hdr->page_size;
|
||||
load_addr = kernel_addr_c - hdr->page_size;
|
||||
} else {
|
||||
/* input load_addr is for lz4/zImage, nothing to do */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return load_addr;
|
||||
}
|
||||
|
||||
/*
|
||||
* 'boot_android' cmd use "kernel_addr_r" as default load address !
|
||||
* We update it according to compress type and "kernel_addr_c/r".
|
||||
*/
|
||||
int android_image_parse_comp(struct andr_img_hdr *hdr, ulong *load_addr)
|
||||
{
|
||||
ulong new_load_addr;
|
||||
int comp;
|
||||
|
||||
comp = android_image_parse_kernel_comp(hdr);
|
||||
env_set_ulong("os_comp", comp);
|
||||
|
||||
new_load_addr = android_image_get_comp_addr(hdr, comp);
|
||||
if (new_load_addr != 0)
|
||||
*load_addr = new_load_addr;
|
||||
|
||||
return comp;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue