Commit Graph

95 Commits

Author SHA1 Message Date
Jason Zhu fc04460b2e common: android: support boot recovery system
In android A/B system, there is no recovery partition, but in the linux
system, we need the recovery to update system.

Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
Change-Id: Idac88720b260791b1ad4c51a5ebc7aae9c66ca67
2021-02-21 14:38:23 +08:00
Joseph Chen 253ea6c67d common: android: independent on optee client
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I5c124c7bfcdfd3c2972a5310046b633324e3bdf0
2020-11-09 17:20:46 +08:00
Joseph Chen 713cdac3a7 common: android: allow failed to overly dtbo
Restore main fdt if it's destroyed by fdt_overlay_apply()
when overlay failed.

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: Id26085f2df89d208caadeb3c4ce33f21f896ee22
2020-11-09 14:51:56 +08:00
Jason Zhu beeaf83f44 common: android: support AVB_SLOT_VERIFY_FLAGS_NO_VBMETA_PARTITION
Usually, the recovery is updated alone, so attach the vbmeta to its tail.
Pass AVB_SLOT_VERIFY_FLAGS_NO_VBMETA_PARTITION to verify the recovery.

Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
Change-Id: Iaea6c8cd06f02ce946a84f8f568a7b91ef6dd40a
Signed-off-by: Yifeng Zhao <yifeng.zhao@rock-chips.com>
2020-10-26 16:39:25 +08:00
Jason Zhu cee2fb0e57 common: android_ab: move the ab functions to android_ab.c
Move the ab functions to android_ab.c and add "ab_" prefix to
api function.

Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
Change-Id: I4527a0c957aa7853a1b75d456ca3fabaf80c1c57
2020-10-22 19:38:57 +08:00
Jason Zhu cf87ffd351 include: android_image: move some android common definitions to this file
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
Change-Id: Ia0da707408bcd43b50b49cef89495af7f9d97cd7
2020-10-22 19:38:57 +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
Jason Zhu 01c0df48f9 common: android: decrease ab tries count after load firmware successfully
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
Change-Id: I31842eda26f05b03ea6a0274502a60814e00e6a0
2020-08-19 17:05:30 +08:00
Jason Zhu f141910278 common: android: fix compile error if only enable ab system
error: ‘reset_cpu_if_android_ab’ defined but not used
[-Werror=unused-function]

Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
Change-Id: I724ea99df27f9f572aa0913491eddb2b5e248e38
2020-04-27 14:32:51 +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 5cadaea8d7 common: android: replace do_bootm() with do_bootm_states()
Avoid dead nested when android_bootloader_boot_kernel() is called
in board_do_bootm(), this bootflow maybe:

CLI command "bootm" => do_bootm() => board_do_bootm() =>
android_bootloader_boot_kernel() => do_bootm().

Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I441d91c986921008752d403a72b7bfa57140d7c8
2020-03-19 09:54:27 +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 6527836d2a common: android: rename and export load_android_image()
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
Change-Id: I7398b83bff0fd0dedd77834ee2a8ff14f2ae11e0
2019-12-17 15:05:19 +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
Jason Zhu fd633ddcf6 android: add function android_bcb_write
Change-Id: Ie65068dc4fca751a9bcc959c56209aaf4729f638
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-11-22 08:41:53 +08:00
Dayao Ji 0a34d7e5db common: android: support A/B with DP support
Need to pass androidboot.force_normal_boot=1 instead of
skip_initramfs when A/B supporting dynamic partition.

Change-Id: I1748690d04d4ef16e121d8dc88f69745a3cbb77d
Signed-off-by: Dayao Ji <jdy@rock-chips.com>
2019-11-15 10:00:47 +08:00
Joseph Chen a84f21ebb8 rockchip: add misc BCB message offset compatibility
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, so this
patch is a compatibility according to android image 'os_version'.

Android os version >= 10 is at 0x0 offset, otherwise at 16KB offset.

Change-Id: I54a7674e2dc2e0c29fc624f17b4453663c9ea462
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-11-14 11:08:45 +08:00
Jason Zhu e1c1c23dd8 android: change the verification mode
The mode AVB_HASHTREE_ERROR_MODE_RESTART_AND_INVALIDATE will add
"androidboot.vbmeta.invalidate_on_error=yes" to cmdline, and kernel
will invalidate vbmeta if verified fail. This will modify the vbmeta.img
head and make uboot verify vbmeta.img fail in avb system. And in avb & ab
system, we can use the retry-count to change slot if verify fail without
modify the vbmeta. So just use the mode AVB_HASHTREE_ERROR_MODE_RESTART.

Change-Id: I98d60683d5365b996fcca2e85d4847d4a6df2ef6
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-11-06 14:41:53 +08:00
Joseph Chen c6666740ee common: android/rkimg: remove/clean android a/b (slot) code
- the partition disk layer takes over the responsibility of slot suffix
  appending, we remove relative code to make file clean;
- put android a/b code together and name them to be eary understood,
  this makes file esay to read.

Change-Id: Id8c838da682ce6098bd7192d7d7c64269f4e86ba
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-11-04 15:43:46 +08:00
Dayao Ji 5bc73b33ae common: android: add androidboot.dtbo_idx to cmdline
fix following vts issue:
0 == 0 Kernel command line missing androidboot.dtbo_idx

Change-Id: Ib2990b5e204d704d895662c60f18e9e0c8a05b25
Signed-off-by: Dayao Ji <jdy@rock-chips.com>
2019-10-22 14:47:59 +08:00
Jason Zhu 01973d127b common: android: support boot-fastboot
In android Q, the bootloader must implement a new Boot Control
Block (BCB) command of boot-fastboot in order to support fastbootd.
Then the bootloader is expected to load and boot into the recovery
image upon seeing boot-fastboot in the BCB command. Recovery then
parses the BCB message and switches to fastbootd mode.

Change-Id: Ie868912071f6a371ec83caa8d591281fc063e6ae
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-09-10 14:33:10 +08:00
Jason Zhu d901aece56 common: android: close optee client before jump to kernel
Change-Id: Icbcf65ecbb043b9119e6c65f9016390ef8f15935
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-09-10 14:09:15 +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 af4fa70793 common: android: format address with "0x%08lx"
Change-Id: Icbb0d31541fab9d66043834a28f995da8b9ab087
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-07-17 16:50:28 +08:00
Jason Zhu 35bc5ad915 common: android: reset the system when verify fail with ab & avb system
Change-Id: I641f6a6972534a785058d94154cbf9304ddac45b
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-07-09 20:28:42 +08:00
Jason Zhu 3120d9d50e avb: do not use lastboot if enable CONFIG_ANDROID_AVB
The avb process have verify next level firmware to ensure its
availability. So there is no need to support lastboot in avb
process.

Change-Id: I1623a2bd93c54802ce0067cad7061ade6cc56313
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-07-09 16:38:02 +08:00
Jason Zhu 87f9541a89 common: android: fix tries_remaining minus twice in avb & ab system
Change-Id: I422cb3c2f7e28849772a65b8060a0d8e26313d47
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-06-28 09:55:01 +08:00
Jason Zhu 4d432d92ae common: android: fix missing "root=" with linux a/b & avb system
Change-Id: I2f8320eb4f81f88e7ba1f2d62eee55010f243df5
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-06-27 08:30:57 +08:00
Joseph Chen 6d5e656643 common: android: add sysmem overflow check
Change-Id: I263bbc9f9f2a71322591ef3528b8fa6039eb3509
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-06-26 11:23:12 +08:00
Joseph Chen 27643361d9 common: android: add/update boot message
Make android bootflow more clear by message.

Change-Id: I6e022ae6fd22ce4b6933b085033c66b7bf79297c
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
Joseph Chen 8b9843df21 common: android: fix uncompress kernel region check
Change-Id: Ie8b6f7255eae3c2be86ccc2c33e04c8b21add75d
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-15 11:02:14 +08:00
Joseph Chen 0986a7dda1 common: android: add sysmem alloc for uncompress kernel
It helps check whether uncompress kernel overlap with other region
or not.

Change-Id: Ia7e6c027f68c2e8af398824afd8b7580531cb77e
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-05-09 17:21:19 +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 892d0a7f9b common: android: remove unnesscessary message
Change-Id: Iaa5da7da492f3fcb8021d175bb9a39a04d7f61d0
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-26 11:04:33 +08:00
Joseph Chen 32c868cf11 common: android: add hotkey for sysmem and bidram dump
Change-Id: Ic866dcc2b160ebd92d518e517e0bc8870aec84d0
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-26 11:04:33 +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
Jason Zhu f44ca27357 android: fix retry mechanism with ab system
Minus the retry-count in every boot with ab system. If the ab system
boot success, the system service boot_ctrl reset the retry-count or set
boot-successful.

Change-Id: Ic37f65b745d1feb978730332835246dc43d72dab
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-03-08 18:12:21 +08:00
Jason Zhu d2280c00f2 android: add brackets to fix compile error
There is a compile error when enable AB config. The error message is
"error: a label can only be part of a statement and a declaration isnot
a statement". Add brackets to fix this error.

Change-Id: I4ec3af984503e35fc1304d08cd7cd8ab587dfb0a
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-03-06 17:16:13 +08:00
Jason Zhu 332992a7f2 android: minus retry in AB system
Change-Id: Icc9764fb10dc87d3c4f2f7417b971338a7f98ca4
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-03-06 17:16:13 +08:00
Joseph Chen 785ce82a19 common: android: support misc partition absent
Change-Id: Ida7780a1fd0981d8dbf01c0f25e283dfc6332eca
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-03-05 14:11:41 +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
Kever Yang fd810b8003 android: return fail if not found misc partition
Return directly and do not continue read from misc partition
if there is no partition.

Change-Id: I549d123632aecc5bd29ebdc2c4c7917c76750247
Signed-off-by: Kever Yang <kever.yang@rock-chips.com>
2019-02-15 10:15:32 +08:00
Joseph Chen 10e1f9ebb7 android: fix avb enable state set error
Fixes: 8e66ecd25d
(android: fix get wrong ramdisk address when avb verify)

Change-Id: I6b28ee32824e97e7eaed4aa8a530903d8486004b
Signed-off-by: Joseph Chen <chenjh@rock-chips.com>
2019-01-31 20:00:49 +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
Jason Zhu e92f47e469 android: test the vbmeta to enable avb
Change-Id: I36d6473a247ab7fc012ceb9a7c9a43e14e701611
Signed-off-by: Jason Zhu <jason.zhu@rock-chips.com>
2019-01-22 16:59:11 +08:00
Jian Qiu c2ba77d93f lib: optee_client: Extract keymaster CA module
Extract keymaster CA module from OpteeClientInterface
refactoring code for keymaster reads and writes form caller module

Change-Id: I1069fce0d29d9d9815f71e7f3b4d231754382acd
Signed-off-by: Jian Qiu <qiujian@rock-chips.com>
2019-01-18 09:09:34 +08:00