Commit Graph

46 Commits

Author SHA1 Message Date
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
Simon Glass 00caae6d47 env: Rename getenv/_f() to env_get()
We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>
2017-08-16 08:30:24 -04:00
Simon Glass 382bee57f1 env: Rename setenv() to env_set()
We are now using an env_ prefix for environment functions. Rename setenv()
for consistency. Also add function comments in common.h.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>
2017-08-16 08:22:18 -04:00
Alex Deymo 210a7176ee image: Update include/android_image.h
Update the Android image header format to the latest version published
in AOSP. The original code moved to a new repository, so this patch also
updates the reference to that path.

Signed-off-by: Alex Deymo <deymo@google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2017-05-11 22:03:37 -04:00
Michael Trimarchi 4f1318b29c common: image: minimal android image iminfo support
We already support iminfo for other images. The idea
of this patch is start to have a minimal support for
android image format. We still need to print id[] array

Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2016-06-24 17:23:07 -04:00
Rob Herring 9950098e31 image: fix support for Android boot images with no ramdisk
If an Android boot image does not contain a ramdisk, make sure rd_len
and rd_data are returned to indicate no ramdisk rather than just relying
on returning an error.

Signed-off-by: Rob Herring <robh@kernel.org>
2015-10-11 17:12:10 -04:00
Maxime Ripard 87f02d5aee image: android: handle default kernel address
The two tools that create android boot images, mkbootimg and the fastboot
client, set the kernel address by default to 0x10008000.

U-boot always honors this field, and will try to relocate the kernel to
whatever value is set in the header, which won't be mapped to the actual RAM on
most platforms, resulting in the kernel obviously not booting.

All the targets in U-Boot right now will download the android boot image to
CONFIG_SYS_LOAD_ADDR, which means that it will already have been downloaded to
some location that is suitable for execution.

In order to have the kernel booting even with the default boot image kernel
address, if that address is used, just execute the kernel where it is.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
2015-05-08 17:24:17 -04:00
Ahmad Draidi 86f4695bd0 image: Fix Android boot image support
This patch makes the following changes:
- Set kernel entry point correctly
- Append bootargs from image to global bootargs instead
        of replacing them
- Return end address instead of size from android_image_get_end()
- Give correct parameter to genimg_get_format() in boot_get_ramdisk()
- Move ramdisk message printing from android_image_get_kernel() to
	android_image_get_ramdisk()

Signed-off-by: Ahmad Draidi <ar2000jp@gmail.com>
Cc: Tom Rini <trini@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
2014-10-27 17:54:12 -04:00
Sebastian Siewior 9ace3fc814 image: add support for Android's boot image format
This patch adds support for the Android boot-image format. The header
file is from the Android project and got slightly alterted so the struct +
its defines are not generic but have something like a namespace. The
header file is from bootloader/legacy/include/boot/bootimg.h. The header
parsing has been written from scratch and I looked at
bootloader/legacy/usbloader/usbloader.c for some details.
The image contains the physical address (load address) of the kernel and
ramdisk. This address is considered only for the kernel image.
The "second image" defined in the image header is currently not
supported. I haven't found anything that is creating this.

v3 (Rob Herring):
This is based on http://patchwork.ozlabs.org/patch/126797/ with the
following changes:
- Rebased to current mainline
- Moved android image handling to separate functions in
  common/image-android.c
- s/u8/char/ in header to fix string function warnings
- Use SPDX identifiers for licenses
- Cleaned-up file source information:
  android_image.h is from file include/boot/bootimg.h in repository:
  https://android.googlesource.com/platform/bootable/bootloader/legacy
  The git commit hash is 4205b865141ff2e255fe1d3bd16de18e217ef06a
  usbloader.c would be from the same commit, but it does not appear
  to have been used for any actual code.
v4:
- s/andriod/android/
- Use a separate flag ep_found to track if the entry point has been set
rather than using a magic value.

Cc: Wolfgang Denk <wd@denx.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Rob Herring <robh@kernel.org>
Reviewed-by: Tom Rini <trini@ti.com>
Reviewed-by: Lukasz Majewski <l.majewski@samsung.com>
2014-05-08 10:38:29 +02:00