Commit Graph

58 Commits

Author SHA1 Message Date
Joseph Chen cc0848dfb9 common: android: simplify image verify/un-verify
Support hash verify if header version < 3.

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I2ade1a50aa26cd94c4464c25c86836421d973f00
2020-10-30 18:27:07 +08:00
Jason Zhu 651b0d0dfc common: android: move crypto_sha_init() after load IMG_RK_DTB
We call crypto to verify dtb alone, so move the crypto_sha_init()
after load IMG_RK_DTB when begin another hash verification.

Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
Change-Id: I12f36172a5d03fa8baa0236503be5627fa18adf0
2020-10-30 15:18:37 +08:00
Lin Jinhan 1817f8c289 common: android: crypto v2 hash need length in crypto_sha_init
if not set ctx.length, you will get zero length hash value.

Change-Id: I9e653c845a36b4caea986c328c48ea8b2835da75
Signed-off-by: Lin Jinhan <troy.lin@rock-chips.com>
2020-10-30 09:58:59 +08:00
Joseph Chen e7498cb05b common: android: show ramdisk size of boot and vendor-boot
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: Ia8eca7010989e64d10b09628a12bcfc5aaeb988c
2020-10-10 16:17:06 +08:00
Joseph Chen 745aeb1a7d common: android: add boot_img_hdr_v3 and vendor boot support
Android Header v3 and vendor boot partition are introduced
from Android-11(R).

Header populate:
  Header v3 is no longer compatible with v0/1/2 header, we
  add populate_andr_img_hdr() to merge boot and vendor_boot
  partition header into struct andr_img_hdr in order to
  compatible with v0/1/2 header.

resource.img:
  The second_addr and second_size fields are removed in v3,
  so we require resource partition to restore resource.img.

A/B system:
  If not A/B system, the boot.img header version is 3 and
  recovery header is version 2.

AVB load image:
  - If allow verification error: the image is loaded by
    ops->get_preloaded_partition() which auto populates
    boot_img_hdr_v3.
  - If not allow verification error: the image is full loaded
    by ops->read_from_partition() which doesn't populate
    boot_img_hdr_v3, we need to fix it.

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I2afce53c43d782fc57baa01acf9c05518b580840
2020-09-18 14:41:37 +08:00
Joseph Chen 69b1ad4693 common: android: clean up code
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I98dfd54edd813f892c5f2717a694b2424b8ecded
2020-09-15 10:55:29 +08:00
Joseph Chen e1e9b173e4 Merge branch 'next-dev' into thunder-boot 2020-03-28 15:01:31 +08:00
Joseph Chen ed5d3403b4 common: android: clean 32-bit compress load address
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I5ef930062cea5de354c9e5d9c4edbfe4875d04d4
2020-03-25 16:23:52 +08:00
Joseph Chen 7460c07a1d common: android: simplify fdt/ramdisk skip reloc
bootm_board_start() takes over it.

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I8a9e3287ad5ca5964809f689bd204cbc2e37468f
2020-03-19 09:54:27 +08:00
Joseph Chen 15f6b6d065 common: android: correct 32-bit non-compressed kernel address
The page size should be reserved before kernel load address.

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: Iaa13fbc9a7a2872c5fb32a388ce96dd94654fc3d
2020-03-13 17:35:40 +08:00
Joseph Chen 591f14a84b common: android: correct address setting api
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: Ic9026d00abc0855aae18cc1a8018ed3549a9482b
2020-03-13 17:35:40 +08:00
Joseph Chen 01918c3fa9 common: android: update image end get for android v2
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I4b2cddec072657d69b294dbddf300cf4d0471695
2020-02-28 11:37:14 +08:00
Joseph Chen c01d448924 sysmem: simplify the memblk name
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: Icfe908ade21d1d8f568db796298f67ba9f013da6
2020-02-28 11:22:04 +08:00
Joseph Chen b6b05c7154 common: android: skip blk read and memcpy if image size is 0
blk_read() may return error code if image size is 0, it depends
on block layer implementation.

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I29bab10835e9029780a957e871a600a6fbdf6068
2019-12-20 10:53:44 +08:00
Joseph Chen 7b2520c78e common: android: not go further if image is in-place
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I7ba27cd704638af933b8581f08192c3ab53c1928
2019-12-17 15:05:19 +08:00
Joseph Chen c484df2f85 common: android: refactor image load and sha1 verify
Unify single image load/memcpy to image_read(), containing
sha1 update.

Not support verify image by RK legacy mkbootimg tools.

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: Ide88d2dda79f3335a6c34e41bdce56eac0d66408
2019-12-10 12:48:27 +08:00
Joseph Chen e1b9a8426d common: android: support decompress kernel for AVB bootflow
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: If253d573384d697338f92b591b28efde9dab48bf
2019-12-10 12:47:52 +08:00
Joseph Chen 3f7fb06b24 common: android: make image separate load mandory
Since this feature is stable and helpful to save boot time,
let't make it mandory.

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I36f244c6d319d6b54ed3d54730352c8d5b4cc6bd
2019-12-10 12:47:52 +08:00
Joseph Chen c092b1390d common: image: provide BCB offset according to android os version
Rockchip platforms defines BCB message at the 16KB offset of
misc partition while the Google defines it at 0x0 offset.

From Android-Q, the 0x0 offset is mandary on Google VTS.

Change-Id: Iac36d421ed605684353c30bfe0e9982bdd5de065
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-11-14 11:08:45 +08:00
Joseph Chen 3c9d2903a9 common: image: fix parse kernel compressed type issue
This issue happens on the SDK version < 8.1. The reason is we don't
read enough blocks from storage for kernel compressed type validation.

ANDROID_ROCKCHIP_LEGACY_PAGE_SIZE(16KB) is defined by rockchip legacy
mkboot tool(SDK version < 8.1) and larger than Google defined.

To compatible this, we malloc enough buffer but only read android
header and kernel image(1 block) from storage.

Change-Id: I9800e4150985adcd5dbd78c28c471604eb403eae
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-11-07 14:58:09 +08:00
Joseph Chen 481590e871 common: android: print boot_img_hdr_v2 new members
Change-Id: I0d87d0ea71c1495c90d123ceaef13aed7af11d70
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-09-06 11:45:32 +08:00
Joseph Chen 0cb72e53ea common: android: add image hash verify support
- mkbootimg tool always use SHA1 for images;
- make the the crypto higher priority;
- AVB images does not need this verify;

Change-Id: I543a3a53da61b920b83ba464a71959518437c436
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-08-29 13:03:17 +08:00
Joseph Chen 98c1299759 common: android: add android_image_memcpy_separate() interface
This is a encapsulation of android_image_load_separate(). It is used
for AVB boot/recovery.img which has been loaded to ram by AVB bootflow,
and we memcpy kernel/ramdisk/dtb to where we expect.

Change-Id: Iea4ea3404b84e9d3c091954ab27fb8c9d2ad84bc
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-08-29 13:03:08 +08:00
Joseph Chen ad5a4d82a5 common: android: add android image header check
Change-Id: I0872eeb02955396b086de448ff69296323628591
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-07-08 09:08:18 +08:00
Joseph Chen 29cdb69100 common: image-android: print separate load fail message
Change-Id: I2bb06d24ce7cfa22a7c197932b67d6bd2055a03d
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-06-25 08:28:54 +08:00
Joseph Chen fe5b67570a common: image-android: don't print fdt load addr/size info
The fdt load addr doesn't make any sense from android hdr,
and it's easy to make user to be confused with "fdt_addr_r".

Change-Id: I20c9047a1a3cef6987d3a1a1c85b6a0f3af15ad2
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-06-19 21:56:04 +08:00
Joseph Chen 39c46c24ef common: android: correct kernel memcpy size when load separate
The hdr->page_size should be included.

fixes: 503a892f5a
(common: android: avb support load android image separate)

Change-Id: I2de2c9957fd47c7f95bf863f7b0c679cc64633d9
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-28 20:30:36 +08:00
Joseph Chen 503a892f5a common: android: avb support load android image separate
Skip fdt and ramdisk relocation to save boot time.

Change-Id: I56fd2fca97fa7795024aa542f0a45d0512be01d4
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-22 15:34:12 +08:00
Jon Lin d92ffd1e48 common: android: do not start kernel when read kernel failed
Change-Id: I032776022378078baae8e59ed8d746ccf13ed373
Signed-off-by: Jon Lin <jon.lin@rock-chips.com>
2019-05-07 17:21:39 +08:00
Joseph Chen 6115fdb3c0 common: android: improve os image information
android_image_parse_kernel_comp() doesn't return valid os
compressed type after android_image_set_kload(), so we add
the env "os_comp" to record compressed type.

Change-Id: Ie175649d348c0578ce78e139bdbbf4b6f9ea1101
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-04-09 10:54:14 +08:00
Joseph Chen 8d681e4412 common: android: only adjust load address for ARM64 compressed kernel
If there is not "kernel_addr_c", using "kernel_addr_r" for Image/zImage
on 32-bit platform.

If there is not "kernel_addr_c", adjust load address to promise compressed
kernel can normal boot on 64-bit platform.

Change-Id: I42cc3c9074eb8f1caaa44d9256d2abdae6cd97b8
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-04-09 10:54:14 +08:00
Joseph Chen 6e15146eff lib: sysmem: refactor code
- import memblk id to manage memory blocks;
- change "sysmem_property" to generic "memblock";
- use alloc instead of reserve for all memory blocks;
- clean up and fix some logic;
- add U-Boot cmd for sysmem;

Change-Id: I614223ce3bf97a7b3566412a9d1864fb30b68fd8
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-26 11:04:33 +08:00
Joseph Chen 2c9d117912 sysmem: fdt: reserve more CONFIG_SYS_FDT_PAD size for fdt
Sometimes, framework or user would call fdt_increase_size() to update
fdt size, it's better reserve more space to avoid sysmem gives the fdt
region overflow report.

The CONFIG_SYS_FDT_PAD default value is sync with bootm framework
in: common/image-fdt.c

Change-Id: I363e9a4182e13b1628a76666acd8272d25db659d
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-02-19 14:37:36 +08:00
Joseph Chen 8e66ecd25d 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>
2019-01-30 16:51:22 +08:00
Joseph Chen 644e344181 android: support loading android image separate
This patch support loading android image separate for the
kernel/ramdisk/second images. It is disabled when android
AVB is enabled, because AVB need verify the full android image.

It brings some benefits, mainly for saving a lot of boot time:
  - allow skip load second content when kernel dtb is enabled;
  - allow skip fdt and ramdisk relocation during bootm boot flow;
  - allow loading fdt/ramdisk to "fdt_addr_r"/"ramdisk_addr_r";
  - avoid android image too large when load to ram;

Change-Id: Ia040b3031307a8a7c98b011ce038ec61fee6804a
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-01-24 15:33:12 +08:00
Joseph Chen eaec55340e common: android: add more clear description for getting fdt
Change-Id: I66865eaed98d08d37047cda50d262d637c8865f8
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-01-08 15:05:41 +08:00
Joseph Chen eb94a25c6f android: fix android load address missing reserve page size
fixes: ee465021fe
(android: support boot images packed with rockchip android hdr)

Change-Id: Iaf340c828196553e433b17322929eaeed6afbf55
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2018-12-10 16:27:07 +08:00
Joseph Chen 7c233ca637 android: read two blocks of kernel image
this patch fixes zboot.img boot up failed due to getting kernel
compress type failed(reading IH_COMP_NONE).

we need to read a few kernel image info, i.e. compress type.
Assume 2 blocks maybe enough.

fixes: ee465021fe
(android: support boot images packed with rockchip android hdr)

Change-Id: I140832a899102984aebaad160a3902cfc483bfeb
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2018-11-13 14:06:36 +08:00
Joseph Chen ee465021fe android: support boot images packed with rockchip android hdr
For some legacy reasons, rockchip use mkbootimg tool to pack android
images with special pack parameters(SDK version lower than 8.1) to
assign kernel/ramdisk/seconds address and page size.

Android hdr on RK3399 SDK-7.1:
   kernel size:      1299808
   kernel address:   60408000
   ramdisk size:     1e6b80
   ramdisk addrress: 62000000
   second size:      41c00
   second address:   60f00000
   tags address:     60088000
   page size:        4000
   header_version:   0
   os_version:       e041114 (ver: 1.7.2, level: 2017.4)
   name:
   cmdline:          buildvariant=userdebug

The kernel/ramdisk/seconds address base is not from 0x10000000 and
page size is not 0x800!

This patch makes bootflow to compatible with above legacy packing.

Change-Id: I663a0d1386694658c97586706ff21ed887d6a2e7
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2018-11-01 08:42:27 +08:00
Joseph Chen 5af94f7887 android: get fdt by suitable ways
We may have special operations for fdt(optional):
- apply fdt overlay;
- select fdt by adc or gpio;

We can't read default rk-kernel.dtb and pass it to kernel,
call rockchip_read_dtb_file() to get dtb.

Change-Id: I3aba002b0cfe324cc7c3852bf8b9561575590fd4
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2018-10-07 09:19:03 +08:00
Joseph Chen f8dbe86116 android: support dtb overlay
- read dtbo from recovery or dtbo partition;
- append "androidboot.dtbo_idx" to cmdline;
- apply dtb overlay when first read kernel dtb;
- pass dtb that first time read to kernel;

Change-Id: Iba5c02c1307d3dad69ef96d3b3b0927fb507be8f
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2018-08-06 11:15:19 +08:00
Joseph Chen c67b8746fb image: android: use debug to print cmdline
if cmdline is too long, it wastes time.

Change-Id: Ie8658fca11c3706df50d1eaae2ee479af6e8de08
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2018-08-06 11:15:19 +08:00
Joseph Chen 09f4e561ac android: update android image header to support new version
mainly to support android P.

Change-Id: I34a49e4eedcde06a9e40792c7c908737dc10b426
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2018-08-06 11:15:19 +08:00
Andy Yan 79bdfc405d android: only handle compressed kernel after read a valid android image
We shouldn't go on with the compress/decompress flow
when we get a invalid andoird image.

Change-Id: Ied7266b8791fe571c670cacafffdd393161c8189
Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
2018-07-16 16:00:10 +08:00
Andy Yan 008aee876a boot_android: add runtime compatible for un/compressed kernel image
This patch add auto parse the compress format of kernel image.
Then decompress the compressed kernel image for arm64, as for
arm32 zImage, we only need to load it to a higher memory, then
the kernel will handle the decompress itself.

Test on RK3308 AARCH64 mode (Cortex A35 816 MHZ) boot with eMMC:

------------------------------------------------------------------
Format    |  Size(Byte) | Ratio | Decomp time(ms) | Boot time(ms) |
-------------------------------------------------------------------
Image     | 7720968     |       |                 |     488       |
-------------------------------------------------------------------
Image.lz4 | 4119448     | 53%   |       59        |     455       |
-------------------------------------------------------------------
Image.lzo | 3858322     | 49%   |       141       |     536       |
-------------------------------------------------------------------
Image.gz  | 3529108     | 45%   |       222       |     609       |
-------------------------------------------------------------------
Image.bz2 | 3295914     | 42%   |       2940      |               |
-------------------------------------------------------------------
Image.lzma| 2683750     | 34%   |                 |               |
-------------------------------------------------------------------

Note: the boot time is counted from first ddr init log to first Kernel log.

Change-Id: I73b12ec944fbc8238b0e061a37e2f31aa3093231
Signed-off-by: Andy Yan <andy.yan@rock-chips.com>
2018-07-14 11:39:04 +08:00
Jason Zhu 6e806ac8f7 android: fix rockchip_get_resource_file compile warning
Change-Id: Ie510718333ef379f733ee50fed40058225281a7e
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2018-01-31 14:56:34 +08:00
Joseph Chen 1f5bcda2a8 android: replace CONFIG_ROCKCHIP_BOOTLOADER with CONFIG_RKIMG_BOOTLOADER
Change-Id: I24db85313652bd21aada68cd472bdf888b7d022d
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2018-01-24 18:17:48 +08:00
Jason Zhu 830c86d992 image-android: get real fdt addr in android_image_get_fdt
Change-Id: Ie9c632c767962f8580bd9adf7727738f28479e4c
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2018-01-18 10:19:23 +08:00
Kever Yang 270f9eac73 image-android: add a api to get fdt from boot img
Get the dtb file from boot img second position or inside resource for
Rockchip image.

Change-Id: I843366b32f79ea8fb320d695d79420607a496d68
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
2017-12-08 18:13:25 +08:00
Alex Deymo 76e2a5a6c6 Move Android Image loading logic to image-android.c
This patch moves the Android Image loading logic from the load_android
command to a new android_load_image() function in image-android.c so it
can be re-used from other commands.

Bug: 32707546
Test: Booted the rpi3 with this patch.
Signed-off-by: Alex Deymo <deymo@google.com>
Change-Id: I12d206141ead1b94ebbcc90ee05512a276c7595a
2017-11-14 10:55:46 +08:00