Initial integration of AVB2.0
cover Initial integration of AVB2.0
This series of patches introduces support of Android Verified Boot 2.0, which provides integrity checking of Android partitions on MMC.
It integrates libavb/libavb_ab into the U-boot, provides implementation of AvbOps, subset of avb commands to run verification chain (and for debugging purposes), and it enables AVB2.0 verification on AM57xx HS SoC by default.
Currently, there is still no support for verification of A/B boot slots and no rollback protection (for storing rollback indexes there are plans to use eMMC RPMB)
Libavb/libavb_ab will be deviated from AOSP upstream in the future, that's why minimal amount of changes were introduced into the lib sources, so checkpatch may fail.
For additional details check [1] AVB 2.0 README and doc/README.avb2, which is a part of this patchset.
[1] https://android.googlesource.com/platform/external/avb/+/master/README.md
Igor Opaniuk (8):
avb2.0: add Android Verified Boot 2.0 libraries avb2.0: integrate avb 2.0 into the build system avb2.0: implement AVB ops
cmd: avb2.0: avb command for performing verification avb2.0: add boot states and dm-verity support
am57xx_hs: avb2.0: add support of AVB 2.0 test/py: avb2.0: add tests for avb commands
doc: avb2.0: add README about AVB2.0 integration
cmd/Kconfig | 15 + cmd/Makefile | 3 + cmd/avb.c | 366 ++++++++ common/Makefile | 2 + common/avb_verify.c | 748 ++++++++++++++++ configs/am57xx_hs_evm_defconfig | 3 + doc/README.avb2 | 100 +++ include/avb/avb_ab_flow.h | 235 ++++++ include/avb/avb_ab_ops.h | 61 ++ include/avb/avb_chain_partition_descriptor.h | 54 ++ include/avb/avb_crypto.h | 147 ++++ include/avb/avb_descriptor.h | 113 +++ include/avb/avb_footer.h | 68 ++ include/avb/avb_hash_descriptor.h | 55 ++ include/avb/avb_hashtree_descriptor.h | 65 ++ include/avb/avb_kernel_cmdline_descriptor.h | 63 ++ include/avb/avb_ops.h | 196 +++++ include/avb/avb_property_descriptor.h | 89 ++ include/avb/avb_rsa.h | 55 ++ include/avb/avb_sha.h | 72 ++ include/avb/avb_slot_verify.h | 239 ++++++ include/avb/avb_sysdeps.h | 97 +++ include/avb/avb_util.h | 259 ++++++ include/avb/avb_vbmeta_image.h | 272 ++++++ include/avb/avb_version.h | 45 + include/avb/libavb.h | 32 + include/avb/libavb_ab.h | 22 + include/avb_verify.h | 97 +++ include/configs/am57xx_evm.h | 11 + include/environment/ti/boot.h | 15 + lib/Kconfig | 20 + lib/Makefile | 2 + lib/libavb/Makefile | 15 + lib/libavb/avb_chain_partition_descriptor.c | 46 + lib/libavb/avb_crypto.c | 355 ++++++++ lib/libavb/avb_descriptor.c | 142 ++++ lib/libavb/avb_footer.c | 36 + lib/libavb/avb_hash_descriptor.c | 43 + lib/libavb/avb_hashtree_descriptor.c | 51 ++ lib/libavb/avb_kernel_cmdline_descriptor.c | 40 + lib/libavb/avb_property_descriptor.c | 167 ++++ lib/libavb/avb_rsa.c | 277 ++++++ lib/libavb/avb_sha256.c | 364 ++++++++ lib/libavb/avb_sha512.c | 362 ++++++++ lib/libavb/avb_slot_verify.c | 1169 ++++++++++++++++++++++++++ lib/libavb/avb_sysdeps_posix.c | 57 ++ lib/libavb/avb_util.c | 385 +++++++++ lib/libavb/avb_vbmeta_image.c | 290 +++++++ lib/libavb/avb_version.c | 16 + lib/libavb_ab/Makefile | 9 + lib/libavb_ab/avb_ab_flow.c | 502 +++++++++++ test/py/tests/test_avb.py | 111 +++ 52 files changed, 8058 insertions(+) create mode 100644 cmd/avb.c create mode 100644 common/avb_verify.c create mode 100644 doc/README.avb2 create mode 100644 include/avb/avb_ab_flow.h create mode 100644 include/avb/avb_ab_ops.h create mode 100644 include/avb/avb_chain_partition_descriptor.h create mode 100644 include/avb/avb_crypto.h create mode 100644 include/avb/avb_descriptor.h create mode 100644 include/avb/avb_footer.h create mode 100644 include/avb/avb_hash_descriptor.h create mode 100644 include/avb/avb_hashtree_descriptor.h create mode 100644 include/avb/avb_kernel_cmdline_descriptor.h create mode 100644 include/avb/avb_ops.h create mode 100644 include/avb/avb_property_descriptor.h create mode 100644 include/avb/avb_rsa.h create mode 100644 include/avb/avb_sha.h create mode 100644 include/avb/avb_slot_verify.h create mode 100644 include/avb/avb_sysdeps.h create mode 100644 include/avb/avb_util.h create mode 100644 include/avb/avb_vbmeta_image.h create mode 100644 include/avb/avb_version.h create mode 100644 include/avb/libavb.h create mode 100644 include/avb/libavb_ab.h create mode 100644 include/avb_verify.h create mode 100644 lib/libavb/Makefile create mode 100644 lib/libavb/avb_chain_partition_descriptor.c create mode 100644 lib/libavb/avb_crypto.c create mode 100644 lib/libavb/avb_descriptor.c create mode 100644 lib/libavb/avb_footer.c create mode 100644 lib/libavb/avb_hash_descriptor.c create mode 100644 lib/libavb/avb_hashtree_descriptor.c create mode 100644 lib/libavb/avb_kernel_cmdline_descriptor.c create mode 100644 lib/libavb/avb_property_descriptor.c create mode 100644 lib/libavb/avb_rsa.c create mode 100644 lib/libavb/avb_sha256.c create mode 100644 lib/libavb/avb_sha512.c create mode 100644 lib/libavb/avb_slot_verify.c create mode 100644 lib/libavb/avb_sysdeps_posix.c create mode 100644 lib/libavb/avb_util.c create mode 100644 lib/libavb/avb_vbmeta_image.c create mode 100644 lib/libavb/avb_version.c create mode 100644 lib/libavb_ab/Makefile create mode 100644 lib/libavb_ab/avb_ab_flow.c create mode 100644 test/py/tests/test_avb.py
Signature · 1 line
2.7.4
PATCH 1/8 avb2.0: add Android Verified Boot 2.0 libraries
Add libavb and libavb_ab libs (3rd party libraries from AOSP), that implement support of AVB 2.0. These libraries are utilized for integrity checking of Android partitions on eMMC (including A/B configurations, that can be used for seamless system updates)
Libraries were added as it is and minimal changes were introduced (license text were replaced with SPDX identifiers), because they would be probably deviated from AOSP upstream in the future
For additional details check [1] AVB 2.0 README.
As libavb/libavb_ab will be deviated from AOSP upstream in the future, minimal amount of changes were introduces into lib sources, so checkpatch checks may fail.
[1] https://android.googlesource.com/platform/external/avb/+/master/README.md
--- include/avb/avb_ab_flow.h | 235 ++++++ include/avb/avb_ab_ops.h | 61 ++ include/avb/avb_chain_partition_descriptor.h | 54 ++ include/avb/avb_crypto.h | 147 ++++ include/avb/avb_descriptor.h | 113 +++ include/avb/avb_footer.h | 68 ++ include/avb/avb_hash_descriptor.h | 55 ++ include/avb/avb_hashtree_descriptor.h | 65 ++ include/avb/avb_kernel_cmdline_descriptor.h | 63 ++ include/avb/avb_ops.h | 196 +++++ include/avb/avb_property_descriptor.h | 89 ++ include/avb/avb_rsa.h | 55 ++ include/avb/avb_sha.h | 72 ++ include/avb/avb_slot_verify.h | 239 ++++++ include/avb/avb_sysdeps.h | 97 +++ include/avb/avb_util.h | 259 ++++++ include/avb/avb_vbmeta_image.h | 272 ++++++ include/avb/avb_version.h | 45 + include/avb/libavb.h | 32 + include/avb/libavb_ab.h | 22 + lib/libavb/avb_chain_partition_descriptor.c | 46 + lib/libavb/avb_crypto.c | 355 ++++++++ lib/libavb/avb_descriptor.c | 142 ++++ lib/libavb/avb_footer.c | 36 + lib/libavb/avb_hash_descriptor.c | 43 + lib/libavb/avb_hashtree_descriptor.c | 51 ++ lib/libavb/avb_kernel_cmdline_descriptor.c | 40 + lib/libavb/avb_property_descriptor.c | 167 ++++ lib/libavb/avb_rsa.c | 277 ++++++ lib/libavb/avb_sha256.c | 364 ++++++++ lib/libavb/avb_sha512.c | 362 ++++++++ lib/libavb/avb_slot_verify.c | 1169 ++++++++++++++++++++++++++ lib/libavb/avb_sysdeps_posix.c | 57 ++ lib/libavb/avb_util.c | 385 +++++++++ lib/libavb/avb_vbmeta_image.c | 290 +++++++ lib/libavb/avb_version.c | 16 + lib/libavb_ab/avb_ab_flow.c | 502 +++++++++++ 37 files changed, 6541 insertions(+) create mode 100644 include/avb/avb_ab_flow.h create mode 100644 include/avb/avb_ab_ops.h create mode 100644 include/avb/avb_chain_partition_descriptor.h create mode 100644 include/avb/avb_crypto.h create mode 100644 include/avb/avb_descriptor.h create mode 100644 include/avb/avb_footer.h create mode 100644 include/avb/avb_hash_descriptor.h create mode 100644 include/avb/avb_hashtree_descriptor.h create mode 100644 include/avb/avb_kernel_cmdline_descriptor.h create mode 100644 include/avb/avb_ops.h create mode 100644 include/avb/avb_property_descriptor.h create mode 100644 include/avb/avb_rsa.h create mode 100644 include/avb/avb_sha.h create mode 100644 include/avb/avb_slot_verify.h create mode 100644 include/avb/avb_sysdeps.h create mode 100644 include/avb/avb_util.h create mode 100644 include/avb/avb_vbmeta_image.h create mode 100644 include/avb/avb_version.h create mode 100644 include/avb/libavb.h create mode 100644 include/avb/libavb_ab.h create mode 100644 lib/libavb/avb_chain_partition_descriptor.c create mode 100644 lib/libavb/avb_crypto.c create mode 100644 lib/libavb/avb_descriptor.c create mode 100644 lib/libavb/avb_footer.c create mode 100644 lib/libavb/avb_hash_descriptor.c create mode 100644 lib/libavb/avb_hashtree_descriptor.c create mode 100644 lib/libavb/avb_kernel_cmdline_descriptor.c create mode 100644 lib/libavb/avb_property_descriptor.c create mode 100644 lib/libavb/avb_rsa.c create mode 100644 lib/libavb/avb_sha256.c create mode 100644 lib/libavb/avb_sha512.c create mode 100644 lib/libavb/avb_slot_verify.c create mode 100644 lib/libavb/avb_sysdeps_posix.c create mode 100644 lib/libavb/avb_util.c create mode 100644 lib/libavb/avb_vbmeta_image.c create mode 100644 lib/libavb/avb_version.c create mode 100644 lib/libavb_ab/avb_ab_flow.c
include/avb/avb_ab_flow.h new file +235 -0
@@ -0,0 +1,235 @@ +/* +* Copyright (C) 2016 The Android Open Source Project +* +* SPDX-License-Identifier: MIT +*/ + +#if !defined(AVB_INSIDE_LIBAVB_AB_H ) && !defined(AVB_COMPILATION ) +#error \ + "Never include this file directly, include libavb_ab/libavb_ab.h instead." +#endif + +#ifndef AVB_AB_FLOW_H_ +#define AVB_AB_FLOW_H_ + +#include "avb/avb_ab_ops.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Magic for the A/B struct when serialized. */ +#define AVB_AB_MAGIC "\0AB0" +#define AVB_AB_MAGIC_LEN 4 + +/* Versioning for the on-disk A/B metadata - keep in sync with avbtool. */ +#define AVB_AB_MAJOR_VERSION 1 +#define AVB_AB_MINOR_VERSION 0 + +/* Size of AvbABData struct. */ +#define AVB_AB_DATA_SIZE 32 + +/* Maximum values for slot data */ +#define AVB_AB_MAX_PRIORITY 15 +#define AVB_AB_MAX_TRIES_REMAINING 7 + +/* Struct used for recording per-slot metadata. +* +* When serialized, data is stored in network byte-order. +*/ +typedef struct AvbABSlotData { +/* Slot priority. Valid values range from 0 to AVB_AB_MAX_PRIORITY, +* both inclusive with 1 being the lowest and AVB_AB_MAX_PRIORITY +* being the highest. The special value 0 is used to indicate the +* slot is unbootable. +*/ +uint8_t priority; + +/* Number of times left attempting to boot this slot ranging from 0 +* to AVB_AB_MAX_TRIES_REMAINING. +*/ +uint8_t tries_remaining; + +/* Non-zero if this slot has booted successfully, 0 otherwise. */ +uint8_t successful_boot; + +/* Reserved for future use. */ +uint8_t reserved[1 ]; +} AVB_ATTR_PACKED AvbABSlotData; + +/* Struct used for recording A/B metadata. +* +* When serialized, data is stored in network byte-order. +*/ +typedef struct AvbABData { +/* Magic number used for identification - see AVB_AB_MAGIC. */ +uint8_t magic[AVB_AB_MAGIC_LEN ]; + +/* Version of on-disk struct - see AVB_AB_{MAJOR,MINOR}_VERSION. */ +uint8_t version_major; +uint8_t version_minor; + +/* Padding to ensure |slots| field start eight bytes in. */ +uint8_t reserved1[2 ]; + +/* Per-slot metadata. */ +AvbABSlotData slots[2 ]; + +/* Reserved for future use. */ +uint8_t reserved2[12 ]; + +/* CRC32 of all 28 bytes preceding this field. */ +uint32_t crc32; +} AVB_ATTR_PACKED AvbABData; + +/* Copies |src| to |dest|, byte-swapping fields in the +* process. Returns false if the data is invalid (e.g. wrong magic, +* wrong CRC32 etc.), true otherwise. +*/ +bool avb_ab_data_verify_and_byteswap (const AvbABData * src,AvbABData * dest); + +/* Copies |src| to |dest|, byte-swapping fields in the process. Also +* updates the |crc32| field in |dest|. +*/ +void avb_ab_data_update_crc_and_byteswap (const AvbABData * src,AvbABData * dest); + +/* Initializes |data| such that it has two slots and both slots have +* maximum tries remaining. The CRC is not set. +*/ +void avb_ab_data_init (AvbABData * data); + +/* Reads A/B metadata from the 'misc' partition using |ops|. Returned +* data is properly byteswapped. Returns AVB_IO_RESULT_OK on +* success, error code otherwise. +* +* If the data read from disk is invalid (e.g. wrong magic or CRC +* checksum failure), the metadata will be reset using +* avb_ab_data_init() and then written to disk. +*/ +AvbIOResult avb_ab_data_read (AvbABOps * ab_ops,AvbABData * data); + +/* Writes A/B metadata to the 'misc' partition using |ops|. This will +* byteswap and update the CRC as needed. Returns AVB_IO_RESULT_OK on +* success, error code otherwise. +*/ +AvbIOResult avb_ab_data_write (AvbABOps * ab_ops,const AvbABData * data); + +/* Return codes used in avb_ab_flow(), see that function for +* documentation of each value. +*/ +typedef enum { +AVB_AB_FLOW_RESULT_OK , +AVB_AB_FLOW_RESULT_OK_WITH_VERIFICATION_ERROR , +AVB_AB_FLOW_RESULT_ERROR_OOM , +AVB_AB_FLOW_RESULT_ERROR_IO , +AVB_AB_FLOW_RESULT_ERROR_NO_BOOTABLE_SLOTS +}AvbABFlowResult ; + +/* Get a textual representation of |result|. */ +const char *avb_ab_flow_result_to_string (AvbABFlowResult result); + +/* High-level function to select a slot to boot. The following +* algorithm is used: +* +* 1. A/B metadata is loaded and validated using the +* read_ab_metadata() operation. Typically this means it's read from +* the 'misc' partition and if it's invalid then it's reset using +* avb_ab_data_init() and this reset metadata is returned. +* +* 2. All bootable slots listed in the A/B metadata are verified using +* avb_slot_verify(). If a slot is invalid or if it fails verification +* (and |allow_verification_error| is false, see below), it will be +* marked as unbootable in the A/B metadata and the metadata will be +* saved to disk before returning. +* +* 3. If there are no bootable slots, the value +* AVB_AB_FLOW_RESULT_ERROR_NO_BOOTABLE_SLOTS is returned. +* +* 4. For each bootable slot, the Stored Rollback Indexes are updated +* such that for each rollback index location, the Stored Rollback +* Index is the largest number smaller than or equal to the Rollback +* Index of each slot. +* +* 5. The bootable slot with the highest priority is selected and +* returned in |out_data|. If this slot is already marked as +* successful, the A/B metadata is not modified. However, if the slot +* is not marked as bootable its |tries_remaining| count is +* decremented and the A/B metadata is saved to disk before returning. +* In either case the value AVB_AB_FLOW_RESULT_OK is returning. +* +* The partitions to load is given in |requested_partitions| as a +* NULL-terminated array of NUL-terminated strings. Typically the +* |requested_partitions| array only contains a single item for the +* boot partition, 'boot'. +* +* If the device is unlocked (and _only_ if it's unlocked), true +* should be passed in the |allow_verification_error| parameter. This +* will allow considering slots as verified even when +* avb_slot_verify() returns +* AVB_SLOT_VERIFY_RESULT_ERROR_PUBLIC_KEY_REJECTED, +* AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION, or +* AVB_SLOT_VERIFY_RESULT_ERROR_ROLLBACK_INDEX for the slot in +* question. +* +* Note that androidboot.slot_suffix is not set in the |cmdline| field +* in |AvbSlotVerifyData| - you will have to pass this command-line +* option yourself. +* +* If a slot was selected and it verified then AVB_AB_FLOW_RESULT_OK +* is returned. +* +* If a slot was selected but it didn't verify then +* AVB_AB_FLOW_RESULT_OK_WITH_VERIFICATION_ERROR is returned. This can +* only happen when |allow_verification_error| is true. +* +* If an I/O operation - such as loading/saving metadata or checking +* rollback indexes - fail, the value AVB_AB_FLOW_RESULT_ERROR_IO is +* returned. +* +* If memory allocation fails, AVB_AB_FLOW_RESULT_ERROR_OOM is +* returned. +* +* Reasonable behavior for handling AVB_AB_FLOW_RESULT_ERROR_NO_BOOTABLE_SLOTS +* is to initiate device repair (which is device-dependent). +*/ +AvbABFlowResult avb_ab_flow (AvbABOps * ab_ops, +const char *const * requested_partitions, +bool allow_verification_error, +AvbSlotVerifyData ** out_data); + +/* Marks the slot with the given slot number as active. Returns +* AVB_IO_RESULT_OK on success, error code otherwise. +* +* This function is typically used by the OS updater when completing +* an update. It can also used by the firmware for implementing the +* "set_active" command. +*/ +AvbIOResult avb_ab_mark_slot_active (AvbABOps * ab_ops,unsigned int slot_number); + +/* Marks the slot with the given slot number as unbootable. Returns +* AVB_IO_RESULT_OK on success, error code otherwise. +* +* This function is typically used by the OS updater before writing to +* a slot. +*/ +AvbIOResult avb_ab_mark_slot_unbootable (AvbABOps * ab_ops, +unsigned int slot_number); + +/* Marks the slot with the given slot number as having booted +* successfully. Returns AVB_IO_RESULT_OK on success, error code +* otherwise. +* +* Calling this on an unbootable slot is an error - AVB_IO_RESULT_OK +* will be returned yet the function will have no side-effects. +* +* This function is typically used by the OS updater after having +* confirmed that the slot works as intended. +*/ +AvbIOResult avb_ab_mark_slot_successful (AvbABOps * ab_ops, +unsigned int slot_number); + +#ifdef __cplusplus +} +#endif + +#endif /* AVB_AB_FLOW_H_ */
include/avb/avb_ab_ops.h new file +61 -0
61 lines not on this page · raw message
include/avb/avb_chain_partition_descriptor.h new file +54 -0
54 lines not on this page · raw message
include/avb/avb_crypto.h new file +147 -0
147 lines not on this page · raw message
include/avb/avb_descriptor.h new file +113 -0
113 lines not on this page · raw message
include/avb/avb_footer.h new file +68 -0
68 lines not on this page · raw message
include/avb/avb_hash_descriptor.h new file +55 -0
55 lines not on this page · raw message
include/avb/avb_hashtree_descriptor.h new file +65 -0
65 lines not on this page · raw message
include/avb/avb_kernel_cmdline_descriptor.h new file +63 -0
63 lines not on this page · raw message
include/avb/avb_ops.h new file +196 -0
196 lines not on this page · raw message
include/avb/avb_property_descriptor.h new file +89 -0
89 lines not on this page · raw message
include/avb/avb_rsa.h new file +55 -0
55 lines not on this page · raw message
include/avb/avb_sha.h new file +72 -0
72 lines not on this page · raw message
include/avb/avb_slot_verify.h new file +239 -0
239 lines not on this page · raw message
include/avb/avb_sysdeps.h new file +97 -0
97 lines not on this page · raw message
include/avb/avb_util.h new file +259 -0
259 lines not on this page · raw message
include/avb/avb_vbmeta_image.h new file +272 -0
272 lines not on this page · raw message
include/avb/avb_version.h new file +45 -0
45 lines not on this page · raw message
include/avb/libavb.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright (C) 2016 The Android Open Source Project +* +* SPDX-License-Identifier: MIT +*/ + +#ifndef LIBAVB_H_ +#define LIBAVB_H_ + +/* The AVB_INSIDE_LIBAVB_H preprocessor symbol is used to enforce +* library users to include only this file. All public interfaces, and +* only public interfaces, must be included here. +*/ + +#define AVB_INSIDE_LIBAVB_H +#include "avb_chain_partition_descriptor.h" +#include "avb_crypto.h" +#include "avb_descriptor.h" +#include "avb_footer.h" +#include "avb_hash_descriptor.h" +#include "avb_hashtree_descriptor.h" +#include "avb_kernel_cmdline_descriptor.h" +#include "avb_ops.h" +#include "avb_property_descriptor.h" +#include "avb_slot_verify.h" +#include "avb_sysdeps.h" +#include "avb_util.h" +#include "avb_vbmeta_image.h" +#include "avb_version.h" +#undef AVB_INSIDE_LIBAVB_H + +#endif /* LIBAVB_H_ */
include/avb/libavb_ab.h new file +22 -0
@@ -0,0 +1,22 @@ +/* +* Copyright (C) 2016 The Android Open Source Project +* +* SPDX-License-Identifier: MIT +*/ + +#ifndef LIBAVB_AB_H_ +#define LIBAVB_AB_H_ + +#include <avb/libavb.h> + +/* The AVB_INSIDE_LIBAVB_AB_H preprocessor symbol is used to enforce +* library users to include only this file. All public interfaces, and +* only public interfaces, must be included here. +*/ + +#define AVB_INSIDE_LIBAVB_AB_H +#include "avb_ab_flow.h" +#include "avb_ab_ops.h" +#undef AVB_INSIDE_LIBAVB_AB_H + +#endif /* LIBAVB_AB_H_ */
lib/libavb/avb_chain_partition_descriptor.c new file +46 -0
46 lines not on this page · raw message
lib/libavb/avb_crypto.c new file +355 -0
355 lines not on this page · raw message
lib/libavb/avb_descriptor.c new file +142 -0
142 lines not on this page · raw message
lib/libavb/avb_footer.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Copyright (C) 2016 The Android Open Source Project +* +* SPDX-License-Identifier: MIT +*/ + +#include "avb/avb_footer.h" +#include "avb/avb_util.h" + +bool avb_footer_validate_and_byteswap (const AvbFooter * src,AvbFooter * dest) { +avb_memcpy (dest, src,sizeof (AvbFooter)); + + dest->version_major =avb_be32toh (dest->version_major); + dest->version_minor =avb_be32toh (dest->version_minor); + + dest->original_image_size =avb_be64toh (dest->original_image_size); + dest->vbmeta_offset =avb_be64toh (dest->vbmeta_offset); + dest->vbmeta_size =avb_be64toh (dest->vbmeta_size); + +/* Check that magic is correct. */ +if (avb_safe_memcmp (dest->magic,AVB_FOOTER_MAGIC ,AVB_FOOTER_MAGIC_LEN ) != +0 ) { +avb_error ("Footer magic is incorrect.\n" ); +return false; + } + +/* Ensure we don't attempt to access any fields if the footer major +* version is not supported. +*/ +if (dest->version_major >AVB_FOOTER_VERSION_MAJOR ) { +avb_error ("No support for footer version.\n" ); +return false; + } + +return true; +}
lib/libavb/avb_hash_descriptor.c new file +43 -0
43 lines not on this page · raw message
lib/libavb/avb_hashtree_descriptor.c new file +51 -0
51 lines not on this page · raw message
lib/libavb/avb_kernel_cmdline_descriptor.c new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Copyright (C) 2016 The Android Open Source Project +* +* SPDX-License-Identifier: MIT +*/ + +#include "avb/avb_kernel_cmdline_descriptor.h" +#include "avb/avb_util.h" + +bool avb_kernel_cmdline_descriptor_validate_and_byteswap ( +const AvbKernelCmdlineDescriptor * src,AvbKernelCmdlineDescriptor * dest) { +uint64_t expected_size; + +avb_memcpy (dest, src,sizeof (AvbKernelCmdlineDescriptor)); + +if (!avb_descriptor_validate_and_byteswap ((const AvbDescriptor *)src, + (AvbDescriptor *)dest)) +return false; + +if (dest->parent_descriptor.tag !=AVB_DESCRIPTOR_TAG_KERNEL_CMDLINE ) { +avb_error ("Invalid tag for kernel cmdline descriptor.\n" ); +return false; + } + + dest->flags =avb_be32toh (dest->flags); + dest->kernel_cmdline_length =avb_be32toh (dest->kernel_cmdline_length); + +/* Check that kernel_cmdline is fully contained. */ + expected_size =sizeof (AvbKernelCmdlineDescriptor) -sizeof (AvbDescriptor); +if (!avb_safe_add_to (&expected_size, dest->kernel_cmdline_length)) { +avb_error ("Overflow while adding up sizes.\n" ); +return false; + } +if (expected_size > dest->parent_descriptor.num_bytes_following) { +avb_error ("Descriptor payload size overflow.\n" ); +return false; + } + +return true; +}
lib/libavb/avb_property_descriptor.c new file +167 -0
48 lines not on this page · raw message
lib/libavb/avb_rsa.c new file +277 -0
277 lines not on this page · raw message
lib/libavb/avb_sha256.c new file +364 -0
364 lines not on this page · raw message
lib/libavb/avb_sha512.c new file +362 -0
362 lines not on this page · raw message
lib/libavb/avb_slot_verify.c new file +1169 -0
1,169 lines not on this page · raw message
lib/libavb/avb_sysdeps_posix.c new file +57 -0
57 lines not on this page · raw message
lib/libavb/avb_util.c new file +385 -0
385 lines not on this page · raw message
lib/libavb/avb_vbmeta_image.c new file +290 -0
290 lines not on this page · raw message
lib/libavb_ab/avb_ab_flow.c new file +502 -0
502 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.7.4
Part of the diff is not shown here. View the raw message.
PATCH 2/8 avb2.0: integrate avb 2.0 into the build system
In reply to Igor OpaniukIntegrate libavb/libavb_ab into the build system. Introduce CONFIG_LIBAVB and CONFIG_LIBAVB_AVB options for enabling build.
--- lib/Kconfig | 20 ++++++++++++++++++++ lib/Makefile | 2 ++ lib/libavb/Makefile | 15 +++++++++++++++ lib/libavb_ab/Makefile | 9 +++++++++ 4 files changed, 46 insertions(+) create mode 100644 lib/libavb/Makefile create mode 100644 lib/libavb_ab/Makefile
lib/Kconfig +20 -0
@@ -142,6 +142,26 @@ config TPM endmenu +menu "Android Verified Boot" + +config LIBAVB + bool "Android Verified Boot 2.0 support" + depends on ANDROID_BOOT_IMAGE + help + This enables support of Android Verified Boot 2.0 which can be used + to assure the end user of the integrity of the software running on a + device. Introduces such features as boot chain of trust, rollback + protection etc. + +config LIBAVB_AB + bool "Android Verified Boot 2.0 A/B slot support" + depends on LIBAVB + help + This enables support of Android Verified Boot for A/B slots, that + are used in seamless system updates. + +endmenu + menu "Hashing Support" config SHA1
lib/Makefile +2 -0
@@ -55,6 +55,8 @@ obj-$(CONFIG_$(SPL_)ZLIB) += zlib/ obj-$(CONFIG_$(SPL_)GZIP) += gunzip.o obj-$(CONFIG_$(SPL_)LZO) += lzo/ +obj-$(CONFIG_LIBAVB) += libavb/ +obj-$(CONFIG_LIBAVB_AB) += libavb_ab/ obj-$(CONFIG_$(SPL_TPL_)SAVEENV) += qsort.o obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += libfdt/
lib/libavb/Makefile new file +15 -0
@@ -0,0 +1,15 @@ +# +# (C) Copyright 2017 Linaro Limited +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-$(CONFIG_LIBAVB) += avb_chain_partition_descriptor.o avb_crypto.o +obj-$(CONFIG_LIBAVB) += avb_footer.o avb_hashtree_descriptor.o +obj-$(CONFIG_LIBAVB) += avb_property_descriptor.o avb_sha256.o +obj-$(CONFIG_LIBAVB) += avb_slot_verify.o avb_util.o avb_version.o +obj-$(CONFIG_LIBAVB) += avb_descriptor.o avb_hash_descriptor.o +obj-$(CONFIG_LIBAVB) += avb_kernel_cmdline_descriptor.o avb_rsa.o avb_sha512.o +obj-$(CONFIG_LIBAVB) += avb_sysdeps_posix.o avb_vbmeta_image.o + +ccflags-y = -DAVB_COMPILATION
lib/libavb_ab/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# +# (C) Copyright 2017 Linaro Limited +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-$(CONFIG_LIBAVB_AB) += avb_ab_flow.o + +ccflags-y = -DAVB_COMPILATION
Signature · 1 line
2.7.4
PATCH 3/8 avb2.0: implement AVB ops
In reply to Igor OpaniukImplement AVB ops on top of existing mmc subsystem API. Currently there is a full implementation of such operations, defined by [1] AVB2.0 specification:
.read_from_partition() - reads N bytes from a partition identified by a name.
.write_to_partition() - Writes N bytes to a partition identified by a name. .validate_vbmeta_public_key() - checks if the given public ‘vbmeta’ partition is trusted.
.get_unique_guid_for_partition() - Gets the GUID for a partition identified by a string name.
As [1] specification recommends to use tamper-evident storage for storing rollback indexes and device state (LOCKED/UNLOCKED),
currently are only stubs instead of full implementation for these ops:
.read_rollback_index() - Gets the rollback index for a given index location .write_rollback_index() - Sets the rollback index to a given location .read_is_device_unlocked() - Gets where the device is unlocked
[1] https://android.googlesource.com/platform/external/avb/+/master/README.md
--- common/Makefile | 2 + common/avb_verify.c | 614 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/avb_verify.h | 80 +++++++ 3 files changed, 696 insertions(+) create mode 100644 common/avb_verify.c create mode 100644 include/avb_verify.h
common/Makefile +2 -0
@@ -136,3 +136,5 @@ obj-$(CONFIG_$(SPL_)LOG) += log.o obj-$(CONFIG_$(SPL_)LOG_CONSOLE) += log_console.o obj-y += s_record.o obj-y += xyzModem.o + +obj-$(CONFIG_LIBAVB_AB) += avb_verify.o
common/avb_verify.c new file +614 -0
614 lines not on this page · raw message
include/avb_verify.h new file +80 -0
80 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 4/8 cmd: avb2.0: avb command for performing verification
In reply to Igor OpaniukEnable a "avb" command to execute Android Verified
Boot 2.0 operations. It includes such subcommands:
avb init - initialize avb2 subsystem
avb read_rb - read rollback index
avb write_rb - write rollback index
avb is_unlocked - check device lock state
avb get_uuid - read and print uuid of a partition
avb read_part - read data from partition
avb read_part_hex - read data from partition and output to stdout avb write_part - write data to partition
avb verify - run full verification chain
--- cmd/Kconfig | 15 +++ cmd/Makefile | 3 + cmd/avb.c | 351 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 369 insertions(+) create mode 100644 cmd/avb.c
cmd/Kconfig +15 -0
@@ -1675,6 +1675,21 @@ config CMD_TRACE for analsys (e.g. using bootchart). See doc/README.trace for full details. +config CMD_AVB + bool "avb - Android Verified Boot 2.0 operations" + depends on LIBAVB_AB + help + Enables a "avb" command to perform verification of partitions using + Android Verified Boot 2.0 functionality. It includes such subcommands: + avb init - initialize avb2 subsystem + avb read_rb - read rollback index + avb write_rb - write rollback index + avb is_unlocked - check device lock state + avb get_uuid - read and print uuid of a partition + avb read_part - read data from partition + avb read_part_hex - read data from partition and output to stdout + avb write_part - write data to partition + avb verify - run full verification chain endmenu config CMD_UBI
cmd/Makefile +3 -0
@@ -151,6 +151,9 @@ obj-$(CONFIG_CMD_REGULATOR) += regulator.o obj-$(CONFIG_CMD_BLOB) += blob.o +# Android Verified Boot 2.0 +obj-$(CONFIG_CMD_AVB) += avb.o + obj-$(CONFIG_X86) += x86/ endif # !CONFIG_SPL_BUILD
cmd/avb.c new file +351 -0
351 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 4/8 cmd: avb2.0: avb command for performing verification
Quoted 115 lines · Igor Opaniuk
Enable a "avb" command to execute Android Verified
Boot 2.0 operations. It includes such subcommands:
avb init - initialize avb2 subsystem
avbread_rb- read rollback index
avbwrite_rb- write rollback index
avbis_unlocked- check device lock state
avbget_uuid- read and print uuid of a partition
avbread_part- read data from partition
avbread_part_hex- read data from partition and output to stdout avbwrite_part- write data to partition
avb verify - run full verification chainSigned-off-by Igor Opaniuk <[email protected]>--- cmd/Kconfig | 15 +++ cmd/Makefile | 3 + cmd/avb.c | 351 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 369 insertions(+) create mode 100644 cmd/avb.ccmd/Kconfig +15
-0@@ -1675,6 +1675,21 @@ config CMD_TRACE for analsys (e.g. using bootchart). See doc/README.trace for full details. +config CMD_AVB + bool "avb - Android Verified Boot 2.0 operations" + depends on LIBAVB_AB + help + Enables a "avb" command to perform verification of partitions using + Android Verified Boot 2.0 functionality. It includes such subcommands: + avb init - initialize avb2 subsystem + avb read_rb - read rollback index + avb write_rb - write rollback index + avb is_unlocked - check device lock state + avb get_uuid - read and print uuid of a partition + avb read_part - read data from partition + avb read_part_hex - read data from partition and output to stdout + avb write_part - write data to partition + avb verify - run full verification chain endmenu config CMD_UBIcmd/Makefile +3
-0@@ -151,6 +151,9 @@ obj-$(CONFIG_CMD_REGULATOR) += regulator.o obj-$(CONFIG_CMD_BLOB) += blob.o +# Android Verified Boot 2.0 +obj-$(CONFIG_CMD_AVB) += avb.o + obj-$(CONFIG_X86) += x86/ endif # !CONFIG_SPL_BUILDcmd/avb.c new file +49
-0@@ -0,0 +1,351 @@ + +/* +* (C) Copyright 2018, Linaro Limited +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <avb_verify.h> +#include <command.h> +#include <image.h> +#include <malloc.h> +#include <mmc.h> + +#define AVB_BOOTARGS "avb_bootargs" +static struct AvbOps *avb_ops; + +static const char *const requested_partitions[] = {"boot" , +"system" , +"vendor" , +NULL }; + +int do_avb_init (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +unsigned long mmc_dev; + +if (argc !=2 ) +return CMD_RET_USAGE ; + + mmc_dev =simple_strtoul (argv[1 ],NULL ,16 ); + +if (avb_ops) +avb_ops_free (avb_ops); + + avb_ops =avb_ops_alloc (mmc_dev); +if (avb_ops) +return CMD_RET_SUCCESS ; + +return CMD_RET_FAILURE ; +} + +int do_avb_read_part (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +const char *part; +s64 offset; +size_t bytes, bytes_read =0 ; +void *buffer; + +if (!avb_ops) { +printf ("AVB 2.0 is not initialized, please run 'avb init'\n" );
cmd/avb.c line 59
Quoted 10 lines
cmd/avb.c new file +10
-0+return CMD_RET_USAGE ; + } + +if (argc !=5 ) +return CMD_RET_USAGE ; + + part = argv[1 ]; + offset =simple_strtoul (argv[2 ],NULL ,16 ); + bytes =simple_strtoul (argv[3 ],NULL ,16 ); + buffer = (void *)simple_strtoul (argv[4 ],NULL ,16 );
+ Simon Glass
AFAIU, to make it possible to run this command on "sandbox", you should use map_sysmem() and friends.
Quoted 295 lines
cmd/avb.c new file +292
-1+ +if (avb_ops->read_from_partition (avb_ops, part, offset, bytes, + buffer, &bytes_read) == +AVB_IO_RESULT_OK ) { +printf ("Read %zu bytes\n" , bytes_read); +return CMD_RET_SUCCESS ; + } + +return CMD_RET_FAILURE ; +} + +int do_avb_read_part_hex (cmd_tbl_t *cmdtp,int flag,int argc, +char *const argv[]) +{ +const char *part; +s64 offset; +size_t bytes, bytes_read =0 ; +char *buffer; + +if (!avb_ops) { +printf ("AVB 2.0 is not initialized, please run 'avb init'\n" ); +return CMD_RET_USAGE ; + } + +if (argc !=4 ) +return CMD_RET_USAGE ; + + part = argv[1 ]; + offset =simple_strtoul (argv[2 ],NULL ,16 ); + bytes =simple_strtoul (argv[3 ],NULL ,16 ); + + buffer =malloc (bytes); +if (!buffer) { +printf ("Failed to tlb_allocate buffer for data\n" ); +return CMD_RET_FAILURE ; + } +memset (buffer,0 , bytes); + +if (avb_ops->read_from_partition (avb_ops, part, offset, bytes, buffer, + &bytes_read) ==AVB_IO_RESULT_OK ) { +printf ("Requested %zu, read %zu bytes\n" , bytes, bytes_read); +printf ("Data: " ); +for (int i =0 ; i < bytes_read; i++) +printf ("%02X" , buffer[i]); + +printf ("\n" ); + +free (buffer); +return CMD_RET_SUCCESS ; + } + +free (buffer); +return CMD_RET_FAILURE ; +} + +int do_avb_write_part (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +const char *part; +s64 offset; +size_t bytes; +void *buffer; + +if (!avb_ops) { +printf ("AVB 2.0 is not initialized, run 'avb init' first\n" ); +return CMD_RET_FAILURE ; + } + +if (argc !=5 ) +return CMD_RET_USAGE ; + + part = argv[1 ]; + offset =simple_strtoul (argv[2 ],NULL ,16 ); + bytes =simple_strtoul (argv[3 ],NULL ,16 ); + buffer = (void *)simple_strtoul (argv[4 ],NULL ,16 ); + +if (avb_ops->write_to_partition (avb_ops, part, offset, bytes, buffer) == +AVB_IO_RESULT_OK ) { +printf ("Wrote %zu bytes\n" , bytes); +return CMD_RET_SUCCESS ; + } + +return CMD_RET_FAILURE ; +} + +int do_avb_read_rb (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +size_t index; +u64 rb_idx; + +if (!avb_ops) { +printf ("AVB 2.0 is not initialized, run 'avb init' first\n" ); +return CMD_RET_FAILURE ; + } + +if (argc !=2 ) +return CMD_RET_USAGE ; + + index = (size_t )simple_strtoul (argv[1 ],NULL ,16 ); + +if (avb_ops->read_rollback_index (avb_ops, index, &rb_idx) == +AVB_IO_RESULT_OK ) { +printf ("Rollback index: %llu\n" , rb_idx); +return CMD_RET_SUCCESS ; + } +return CMD_RET_FAILURE ; +} + +int do_avb_write_rb (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +size_t index; +u64 rb_idx; + +if (!avb_ops) { +printf ("AVB 2.0 is not initialized, run 'avb init' first\n" ); +return CMD_RET_FAILURE ; + } + +if (argc !=3 ) +return CMD_RET_USAGE ; + + index = (size_t )simple_strtoul (argv[1 ],NULL ,16 ); + rb_idx =simple_strtoul (argv[2 ],NULL ,16 ); + +if (avb_ops->write_rollback_index (avb_ops, index, rb_idx) == +AVB_IO_RESULT_OK ) +return CMD_RET_SUCCESS ; + +return CMD_RET_FAILURE ; +} + +int do_avb_get_uuid (cmd_tbl_t *cmdtp,int flag, +int argc,char *const argv[]) +{ +const char *part; +char buffer[UUID_STR_LEN +1 ]; + +if (!avb_ops) { +printf ("AVB 2.0 is not initialized, run 'avb init' first\n" ); +return CMD_RET_FAILURE ; + } + +if (argc !=2 ) +return CMD_RET_USAGE ; + + part = argv[1 ]; + +if (avb_ops->get_unique_guid_for_partition (avb_ops, part, buffer, +UUID_STR_LEN +1 ) == +AVB_IO_RESULT_OK ) { +printf ("'%s' UUID: %s\n" , part, buffer); +return CMD_RET_SUCCESS ; + } + +return CMD_RET_FAILURE ; +} + +int do_avb_verify_part (cmd_tbl_t *cmdtp,int flag, +int argc,char *const argv[]) +{ +AvbSlotVerifyResult slot_result; +AvbSlotVerifyData *out_data; + +bool unlocked = false; +int res =CMD_RET_FAILURE ; + +if (!avb_ops) { +printf ("AVB 2.0 is not initialized, run 'avb init' first\n" ); +return CMD_RET_FAILURE ; + } + +if (argc !=1 ) +return CMD_RET_USAGE ; + +printf ("## Android Verified Boot 2.0 version %s\n" , +avb_version_string ()); + +if (avb_ops->read_is_device_unlocked (avb_ops, &unlocked) != +AVB_IO_RESULT_OK ) { +printf ("Can't determine device lock state.\n" ); +return CMD_RET_FAILURE ; + } + + slot_result =avb_slot_verify (avb_ops, requested_partitions, +"" , unlocked, &out_data); +switch (slot_result) { +case AVB_SLOT_VERIFY_RESULT_OK : +printf ("Verification passed successfully\n" ); + +/* export additional bootargs to AVB_BOOTARGS env var */ +env_set (AVB_BOOTARGS , out_data->cmdline); + + res =CMD_RET_SUCCESS ; +break ; +case AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION : +printf ("Verification failed\n" ); +break ; +case AVB_SLOT_VERIFY_RESULT_ERROR_IO : +printf ("I/O error occurred during verification\n" ); +break ; +case AVB_SLOT_VERIFY_RESULT_ERROR_OOM : +printf ("OOM error occurred during verification\n" ); +break ; +case AVB_SLOT_VERIFY_RESULT_ERROR_INVALID_METADATA : +printf ("Corrupted dm-verity metadata detected\n" ); +break ; +case AVB_SLOT_VERIFY_RESULT_ERROR_UNSUPPORTED_VERSION : +printf ("Unsupported version avbtool was used\n" ); +break ; +case AVB_SLOT_VERIFY_RESULT_ERROR_ROLLBACK_INDEX : +printf ("Checking rollback index failed\n" ); +break ; +case AVB_SLOT_VERIFY_RESULT_ERROR_PUBLIC_KEY_REJECTED : +printf ("Public key was rejected\n" ); +break ; +default : +printf ("Unknown error occurred\n" ); + } + +return res; +} + +int do_avb_is_unlocked (cmd_tbl_t *cmdtp,int flag, +int argc,char *const argv[]) +{ +bool unlock; + +if (!avb_ops) { +printf ("AVB not initialized, run 'avb init' first\n" ); +return CMD_RET_FAILURE ; + } + +if (argc !=1 ) { +printf ("--%s(-1)\n" , __func__); +return CMD_RET_USAGE ; + } + +if (avb_ops->read_is_device_unlocked (avb_ops, &unlock) == +AVB_IO_RESULT_OK ) { +printf ("Unlocked = %d\n" , unlock); +return CMD_RET_SUCCESS ; + } + +return CMD_RET_FAILURE ; +} + +static cmd_tbl_t cmd_avb[] = { +U_BOOT_CMD_MKENT (init,2 ,0 , do_avb_init,"" ,"" ), +U_BOOT_CMD_MKENT (read_rb,2 ,0 , do_avb_read_rb,"" ,"" ), +U_BOOT_CMD_MKENT (write_rb,3 ,0 , do_avb_write_rb,"" ,"" ), +U_BOOT_CMD_MKENT (is_unlocked,1 ,0 , do_avb_is_unlocked,"" ,"" ), +U_BOOT_CMD_MKENT (get_uuid,2 ,0 , do_avb_get_uuid,"" ,"" ), +U_BOOT_CMD_MKENT (read_part,5 ,0 , do_avb_read_part,"" ,"" ), +U_BOOT_CMD_MKENT (read_part_hex,4 ,0 , do_avb_read_part_hex,"" ,"" ), +U_BOOT_CMD_MKENT (write_part,5 ,0 , do_avb_write_part,"" ,"" ), +U_BOOT_CMD_MKENT (verify,1 ,0 , do_avb_verify_part,"" ,"" ), +}; + +static int do_avb (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +cmd_tbl_t *cp; + + cp =find_cmd_tbl (argv[1 ], cmd_avb,ARRAY_SIZE (cmd_avb)); + + argc--; + argv++; + +if (!cp || argc > cp->maxargs) +return CMD_RET_USAGE ; + +if (flag ==CMD_FLAG_REPEAT ) +return CMD_RET_FAILURE ; + +return cp->cmd (cmdtp, flag, argc, argv); +} + +U_BOOT_CMD ( + avb,29 ,0 , do_avb, +"Provides commands for testing Android Verified Boot 2.0 functionality" , +"init <dev> - initialize avb2 for <dev>\n" +"avb read_rb <num> - read rollback index at location <num>\n" +"avb write_rb <num> <rb> - write rollback index <rb> to <num>\n" +"avb is_unlocked - returns unlock status of the device\n" +"avb get_uuid <partname> - read and print uuid of partition <part>\n" +"avb read_part <partname> <offset> <num> <addr> - read <num> bytes from\n" +" partition <partname> to buffer <addr>\n" +"avb read_part_hex <partname> <offset> <num> - read <num> bytes from\n" +" partition <partname> and print to stdout\n" +"avb write_part <partname> <offset> <num> <addr> - write <num> bytes to\n" +" <partname> by <offset> using data from <addr>\n" +"avb verify - run verification process using hash data\n" +" from vbmeta structure\n" + ); --2.7.4
PATCH 4/8 cmd: avb2.0: avb command for performing verification
In reply to Igor OpaniukHi Igor,
Quoted 119 lines · Igor Opaniuk
Enable a "avb" command to execute Android Verified
Boot 2.0 operations. It includes such subcommands:
avb init - initialize avb2 subsystem
avbread_rb- read rollback index
avbwrite_rb- write rollback index
avbis_unlocked- check device lock state
avbget_uuid- read and print uuid of a partition
avbread_part- read data from partition
avbread_part_hex- read data from partition and output to stdout avbwrite_part- write data to partition
avb verify - run full verification chainSigned-off-by Igor Opaniuk <[email protected]>--- cmd/Kconfig | 15 +++ cmd/Makefile | 3 + cmd/avb.c | 351 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 369 insertions(+) create mode 100644 cmd/avb.ccmd/Kconfig +15
-0@@ -1675,6 +1675,21 @@ config CMD_TRACE for analsys (e.g. using bootchart). See doc/README.trace for full details. +config CMD_AVB + bool "avb - Android Verified Boot 2.0 operations" + depends on LIBAVB_AB + help + Enables a "avb" command to perform verification of partitions using + Android Verified Boot 2.0 functionality. It includes such subcommands: + avb init - initialize avb2 subsystem + avb read_rb - read rollback index + avb write_rb - write rollback index + avb is_unlocked - check device lock state + avb get_uuid - read and print uuid of a partition + avb read_part - read data from partition + avb read_part_hex - read data from partition and output to stdout + avb write_part - write data to partition + avb verify - run full verification chain endmenu config CMD_UBIcmd/Makefile +3
-0@@ -151,6 +151,9 @@ obj-$(CONFIG_CMD_REGULATOR) += regulator.o obj-$(CONFIG_CMD_BLOB) += blob.o +# Android Verified Boot 2.0 +obj-$(CONFIG_CMD_AVB) += avb.o + obj-$(CONFIG_X86) += x86/ endif # !CONFIG_SPL_BUILDcmd/avb.c new file +53
-0@@ -0,0 +1,351 @@ + +/* +* (C) Copyright 2018, Linaro Limited +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <avb_verify.h> +#include <command.h> +#include <image.h> +#include <malloc.h> +#include <mmc.h> + +#define AVB_BOOTARGS "avb_bootargs" +static struct AvbOps *avb_ops; + +static const char *const requested_partitions[] = {"boot" , +"system" , +"vendor" , +NULL }; + +int do_avb_init (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +unsigned long mmc_dev; + +if (argc !=2 ) +return CMD_RET_USAGE ; + + mmc_dev =simple_strtoul (argv[1 ],NULL ,16 ); + +if (avb_ops) +avb_ops_free (avb_ops); + + avb_ops =avb_ops_alloc (mmc_dev); +if (avb_ops) +return CMD_RET_SUCCESS ; + +return CMD_RET_FAILURE ; +} + +int do_avb_read_part (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +const char *part; +s64 offset; +size_t bytes, bytes_read =0 ; +void *buffer; + +if (!avb_ops) { +printf ("AVB 2.0 is not initialized, please run 'avb init'\n" ); +return CMD_RET_USAGE ; + } + +if (argc !=5 )
cmd/avb.c line 63
Quoted 10 lines
cmd/avb.c new file +10
-0+return CMD_RET_USAGE ; + + part = argv[1 ]; + offset =simple_strtoul (argv[2 ],NULL ,16 ); + bytes =simple_strtoul (argv[3 ],NULL ,16 ); + buffer = (void *)simple_strtoul (argv[4 ],NULL ,16 ); + +if (avb_ops->read_from_partition (avb_ops, part, offset, bytes, + buffer, &bytes_read) == +AVB_IO_RESULT_OK ) {
Please can you make sure this uses driver model, and put wrappers for these function calls in the uclass?
Regards,
Simon
PATCH 4/8 cmd: avb2.0: avb command for performing verification
Hi Simon,
I've dug into DriverModel documentation and even created a PoC for existing avb commands. The problem is that (maybe I missed out some key concepts) I'm still
not sure if it makes sense to follow it driver mode in the context of AVB 2.0 feature and
what kind of extra devices can be used within the same uclass in this case? Could you please explain in detail.
Thanks
Hi Sam,
Thanks, will fix!
Quoted 138 lines · Simon Glass
Hi Igor,
Quoted 119 lines · Igor Opaniuk
Enable a "avb" command to execute Android Verified
Boot 2.0 operations. It includes such subcommands:
avb init - initialize avb2 subsystem
avbread_rb- read rollback index
avbwrite_rb- write rollback index
avbis_unlocked- check device lock state
avbget_uuid- read and print uuid of a partition
avbread_part- read data from partition
avbread_part_hex- read data from partition and output to stdout avbwrite_part- write data to partition
avb verify - run full verification chainSigned-off-by Igor Opaniuk <[email protected]>--- cmd/Kconfig | 15 +++ cmd/Makefile | 3 + cmd/avb.c | 351 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 369 insertions(+) create mode 100644 cmd/avb.ccmd/Kconfig +15
-0@@ -1675,6 +1675,21 @@ config CMD_TRACE for analsys (e.g. using bootchart). See doc/README.trace for full details. +config CMD_AVB + bool "avb - Android Verified Boot 2.0 operations" + depends on LIBAVB_AB + help + Enables a "avb" command to perform verification of partitions using + Android Verified Boot 2.0 functionality. It includes such subcommands: + avb init - initialize avb2 subsystem + avb read_rb - read rollback index + avb write_rb - write rollback index + avb is_unlocked - check device lock state + avb get_uuid - read and print uuid of a partition + avb read_part - read data from partition + avb read_part_hex - read data from partition and output to stdout + avb write_part - write data to partition + avb verify - run full verification chain endmenu config CMD_UBIcmd/Makefile +3
-0@@ -151,6 +151,9 @@ obj-$(CONFIG_CMD_REGULATOR) += regulator.o obj-$(CONFIG_CMD_BLOB) += blob.o +# Android Verified Boot 2.0 +obj-$(CONFIG_CMD_AVB) += avb.o + obj-$(CONFIG_X86) += x86/ endif # !CONFIG_SPL_BUILDcmd/avb.c new file +53
-0@@ -0,0 +1,351 @@ + +/* +* (C) Copyright 2018, Linaro Limited +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <avb_verify.h> +#include <command.h> +#include <image.h> +#include <malloc.h> +#include <mmc.h> + +#define AVB_BOOTARGS "avb_bootargs" +static struct AvbOps *avb_ops; + +static const char *const requested_partitions[] = {"boot" , +"system" , +"vendor" , +NULL }; + +int do_avb_init (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +unsigned long mmc_dev; + +if (argc !=2 ) +return CMD_RET_USAGE ; + + mmc_dev =simple_strtoul (argv[1 ],NULL ,16 ); + +if (avb_ops) +avb_ops_free (avb_ops); + + avb_ops =avb_ops_alloc (mmc_dev); +if (avb_ops) +return CMD_RET_SUCCESS ; + +return CMD_RET_FAILURE ; +} + +int do_avb_read_part (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +const char *part; +s64 offset; +size_t bytes, bytes_read =0 ; +void *buffer; + +if (!avb_ops) { +printf ("AVB 2.0 is not initialized, please run 'avb init'\n" ); +return CMD_RET_USAGE ; + } + +if (argc !=5 )cmd/avb.c line 63
Quoted 10 lines
cmd/avb.c new file +10
-0+return CMD_RET_USAGE ; + + part = argv[1 ]; + offset =simple_strtoul (argv[2 ],NULL ,16 ); + bytes =simple_strtoul (argv[3 ],NULL ,16 ); + buffer = (void *)simple_strtoul (argv[4 ],NULL ,16 ); + +if (avb_ops->read_from_partition (avb_ops, part, offset, bytes, + buffer, &bytes_read) == +AVB_IO_RESULT_OK ) {Please can you make sure this uses driver model, and put wrappers for these function calls in the uclass?
Regards,
Simon
Signature · 2 lines
Regards, Igor Opaniuk
PATCH 4/8 cmd: avb2.0: avb command for performing verification
Hi Igor,
Quoted 10 lines · Igor Opaniuk
Hi Simon,
I've dug into DriverModel documentation and even created a PoC for existing avb commands. The problem is that (maybe I missed out some key concepts) I'm still
not sure if it makes sense to follow it driver mode in the context of AVB 2.0 feature and
what kind of extra devices can be used within the same uclass in this case? Could you please explain in detail.
Thanks
avb_ops_alloc() is allocating a struct and then assigning operations to its members.
This is what driver model is designed to do. It handles the allocations and the operations become part of the uclass interface.
At present it looks like you only have one driver. I'm not sure if it would make sense to have a second one.
As a counter example see cros_ec uclass, which does things differently. It models the EC interface (I2C, SPI, LPC) using DM, with just a single impl on top.
Also can you please drop the CamelCase in the patches? We don't use that in U-Boot.
Quoted 141 lines
Hi Sam,
Thanks, will fix!Quoted 135 lines · Simon Glass
Hi Igor,
Quoted 119 lines · Igor Opaniuk
Enable a "avb" command to execute Android Verified
Boot 2.0 operations. It includes such subcommands:
avb init - initialize avb2 subsystem
avbread_rb- read rollback index
avbwrite_rb- write rollback index
avbis_unlocked- check device lock state
avbget_uuid- read and print uuid of a partition
avbread_part- read data from partition
avbread_part_hex- read data from partition and output to stdout avbwrite_part- write data to partition
avb verify - run full verification chainSigned-off-by Igor Opaniuk <[email protected]>--- cmd/Kconfig | 15 +++ cmd/Makefile | 3 + cmd/avb.c | 351 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 369 insertions(+) create mode 100644 cmd/avb.ccmd/Kconfig +15
-0@@ -1675,6 +1675,21 @@ config CMD_TRACE for analsys (e.g. using bootchart). See doc/README.trace for full details. +config CMD_AVB + bool "avb - Android Verified Boot 2.0 operations" + depends on LIBAVB_AB + help + Enables a "avb" command to perform verification of partitions using + Android Verified Boot 2.0 functionality. It includes such subcommands: + avb init - initialize avb2 subsystem + avb read_rb - read rollback index + avb write_rb - write rollback index + avb is_unlocked - check device lock state + avb get_uuid - read and print uuid of a partition + avb read_part - read data from partition + avb read_part_hex - read data from partition and output to stdout + avb write_part - write data to partition + avb verify - run full verification chain endmenu config CMD_UBIcmd/Makefile +3
-0@@ -151,6 +151,9 @@ obj-$(CONFIG_CMD_REGULATOR) += regulator.o obj-$(CONFIG_CMD_BLOB) += blob.o +# Android Verified Boot 2.0 +obj-$(CONFIG_CMD_AVB) += avb.o + obj-$(CONFIG_X86) += x86/ endif # !CONFIG_SPL_BUILDcmd/avb.c new file +53
-0@@ -0,0 +1,351 @@ + +/* +* (C) Copyright 2018, Linaro Limited +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <avb_verify.h> +#include <command.h> +#include <image.h> +#include <malloc.h> +#include <mmc.h> + +#define AVB_BOOTARGS "avb_bootargs" +static struct AvbOps *avb_ops; + +static const char *const requested_partitions[] = {"boot" , +"system" , +"vendor" , +NULL }; + +int do_avb_init (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +unsigned long mmc_dev; + +if (argc !=2 ) +return CMD_RET_USAGE ; + + mmc_dev =simple_strtoul (argv[1 ],NULL ,16 ); + +if (avb_ops) +avb_ops_free (avb_ops); + + avb_ops =avb_ops_alloc (mmc_dev); +if (avb_ops) +return CMD_RET_SUCCESS ; + +return CMD_RET_FAILURE ; +} + +int do_avb_read_part (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +const char *part; +s64 offset; +size_t bytes, bytes_read =0 ; +void *buffer; + +if (!avb_ops) { +printf ("AVB 2.0 is not initialized, please run 'avb init'\n" ); +return CMD_RET_USAGE ; + } + +if (argc !=5 )cmd/avb.c line 63
Quoted 10 lines
cmd/avb.c new file +10
-0+return CMD_RET_USAGE ; + + part = argv[1 ]; + offset =simple_strtoul (argv[2 ],NULL ,16 ); + bytes =simple_strtoul (argv[3 ],NULL ,16 ); + buffer = (void *)simple_strtoul (argv[4 ],NULL ,16 ); + +if (avb_ops->read_from_partition (avb_ops, part, offset, bytes, + buffer, &bytes_read) == +AVB_IO_RESULT_OK ) {Please can you make sure this uses driver model, and put wrappers for these function calls in the uclass?
Regards,
Simon
PATCH 4/8 cmd: avb2.0: avb command for performing verification
Quoted 20 lines · Simon Glass
Hi Igor,
Quoted 10 lines · Igor Opaniuk
Hi Simon,
I've dug into DriverModel documentation and even created a PoC for existing avb commands. The problem is that (maybe I missed out some key concepts) I'm still
not sure if it makes sense to follow it driver mode in the context of AVB 2.0 feature and
what kind of extra devices can be used within the same uclass in this case? Could you please explain in detail.
Thanks
avb_ops_alloc()is allocating a struct and then assigning operations to its members.This is what driver model is designed to do. It handles the allocations and the operations become part of the uclass interface.
Quoted 6 lines
At present it looks like you only have one driver. I'm not sure if it would make sense to have a second one.
As a counter example see
cros_ecuclass, which does things differently. It models the EC interface (I2C, SPI, LPC) using DM, with just a single impl on top.
Right, I do understand what DriverModel is and why it should be used in the case of real-device drivers. But regarding Android Verified Boot 2.0 feature, which introduces verification capabilities and leverages only device-independent APIs,
I see no reason why it should be used here.
Could you please check [1] and confirm that this set of commands should really follow this model.
Quoted 2 lines
Also can you please drop the CamelCase in the patches? We don't use that in U-Boot.
Frankly, I don't like it also, bit all CamelCase instances in the code relate to libavb/libavb_ab library ([2]), which is planned to be deviated from AOSP upstream in the future.
That's why a decision was made to not introduce any changes to simplify this process, as Google intensively introduces new changes to it. (I've left a notice in the cover letter that checkpatch
will fail on the commit, which introduces libavb; also, there is the ongoing discussion there regarding why libavb/libavb_ab should be
kept as it's. Please join us, if you don't mind).
Thanks!
Best regards,
Igor
[1] https://android.googlesource.com/platform/external/avb/+/master/README.md
[2] https://android.googlesource.com/platform/external/avb/
Quoted 144 lines
Quoted 141 lines
Hi Sam,
Thanks, will fix!Quoted 135 lines · Simon Glass
Hi Igor,
Quoted 119 lines · Igor Opaniuk
Enable a "avb" command to execute Android Verified
Boot 2.0 operations. It includes such subcommands:
avb init - initialize avb2 subsystem
avbread_rb- read rollback index
avbwrite_rb- write rollback index
avbis_unlocked- check device lock state
avbget_uuid- read and print uuid of a partition
avbread_part- read data from partition
avbread_part_hex- read data from partition and output to stdout avbwrite_part- write data to partition
avb verify - run full verification chainSigned-off-by Igor Opaniuk <[email protected]>--- cmd/Kconfig | 15 +++ cmd/Makefile | 3 + cmd/avb.c | 351 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 369 insertions(+) create mode 100644 cmd/avb.ccmd/Kconfig +15
-0@@ -1675,6 +1675,21 @@ config CMD_TRACE for analsys (e.g. using bootchart). See doc/README.trace for full details. +config CMD_AVB + bool "avb - Android Verified Boot 2.0 operations" + depends on LIBAVB_AB + help + Enables a "avb" command to perform verification of partitions using + Android Verified Boot 2.0 functionality. It includes such subcommands: + avb init - initialize avb2 subsystem + avb read_rb - read rollback index + avb write_rb - write rollback index + avb is_unlocked - check device lock state + avb get_uuid - read and print uuid of a partition + avb read_part - read data from partition + avb read_part_hex - read data from partition and output to stdout + avb write_part - write data to partition + avb verify - run full verification chain endmenu config CMD_UBIcmd/Makefile +3
-0@@ -151,6 +151,9 @@ obj-$(CONFIG_CMD_REGULATOR) += regulator.o obj-$(CONFIG_CMD_BLOB) += blob.o +# Android Verified Boot 2.0 +obj-$(CONFIG_CMD_AVB) += avb.o + obj-$(CONFIG_X86) += x86/ endif # !CONFIG_SPL_BUILDcmd/avb.c new file +53
-0@@ -0,0 +1,351 @@ + +/* +* (C) Copyright 2018, Linaro Limited +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <avb_verify.h> +#include <command.h> +#include <image.h> +#include <malloc.h> +#include <mmc.h> + +#define AVB_BOOTARGS "avb_bootargs" +static struct AvbOps *avb_ops; + +static const char *const requested_partitions[] = {"boot" , +"system" , +"vendor" , +NULL }; + +int do_avb_init (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +unsigned long mmc_dev; + +if (argc !=2 ) +return CMD_RET_USAGE ; + + mmc_dev =simple_strtoul (argv[1 ],NULL ,16 ); + +if (avb_ops) +avb_ops_free (avb_ops); + + avb_ops =avb_ops_alloc (mmc_dev); +if (avb_ops) +return CMD_RET_SUCCESS ; + +return CMD_RET_FAILURE ; +} + +int do_avb_read_part (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +const char *part; +s64 offset; +size_t bytes, bytes_read =0 ; +void *buffer; + +if (!avb_ops) { +printf ("AVB 2.0 is not initialized, please run 'avb init'\n" ); +return CMD_RET_USAGE ; + } + +if (argc !=5 )cmd/avb.c line 63
Quoted 10 lines
cmd/avb.c new file +10
-0+return CMD_RET_USAGE ; + + part = argv[1 ]; + offset =simple_strtoul (argv[2 ],NULL ,16 ); + bytes =simple_strtoul (argv[3 ],NULL ,16 ); + buffer = (void *)simple_strtoul (argv[4 ],NULL ,16 ); + +if (avb_ops->read_from_partition (avb_ops, part, offset, bytes, + buffer, &bytes_read) == +AVB_IO_RESULT_OK ) {Please can you make sure this uses driver model, and put wrappers for these function calls in the uclass?
Regards,
Simon
Signature · 2 lines
Regards, Igor Opaniuk
PATCH 4/8 cmd: avb2.0: avb command for performing verification
(Tom can you please comment on the CamelCase question?)
Hi Igor,
Quoted 28 lines · Igor Opaniuk
Quoted 20 lines · Simon Glass
Hi Igor,
Quoted 10 lines · Igor Opaniuk
Hi Simon,
I've dug into DriverModel documentation and even created a PoC for existing avb commands. The problem is that (maybe I missed out some key concepts) I'm still
not sure if it makes sense to follow it driver mode in the context of AVB 2.0 feature and
what kind of extra devices can be used within the same uclass in this case? Could you please explain in detail.
Thanks
avb_ops_alloc()is allocating a struct and then assigning operations to its members.This is what driver model is designed to do. It handles the allocations and the operations become part of the uclass interface.
Quoted 6 lines
At present it looks like you only have one driver. I'm not sure if it would make sense to have a second one.
As a counter example see
cros_ecuclass, which does things differently. It models the EC interface (I2C, SPI, LPC) using DM, with just a single impl on top.
Quoted 7 lines
Right, I do understand what DriverModel is and why it should be used in the case of real-device drivers. But regarding Android Verified Boot 2.0 feature, which introduces verification capabilities and leverages only device-independent APIs,
I see no reason why it should be used here.
Could you please check [1] and confirm that this set of commands should really follow this model.
If there is no need for operations and indirection through function pointers, why not just call the functions directly?
I do think (as the code is currently structured) that DM makes sense, even though I understand that you are not creating a device. Perhaps Tom might have thoughts on this though?
Quoted 9 lines
Quoted 3 lines
Also can you please drop the CamelCase in the patches? We don't use that in U-Boot.
Frankly, I don't like it also, bit all CamelCase instances in the code relate to libavb/libavb_ab library ([2]), which is planned to be deviated from AOSP upstream in the future.
That's why a decision was made to not introduce any changes to simplify this process, as Google intensively introduces new changes to it.
Tom, what do you think? It's not how things usually work, but perhaps there is precedent for this?
Quoted 4 lines
(I've left a notice in the cover letter that checkpatch
will fail on the commit, which introduces libavb; also, there is the ongoing discussion there regarding why libavb/libavb_ab should be
kept as it's. Please join us, if you don't mind).
I do see the cover letter thread but could not find the camel case discussion. Can you please point me to it?
Quoted 9 lines
Thanks!
Best regards,
Igor[1] https://android.googlesource.com/platform/external/avb/+/master/README.md
[2] https://android.googlesource.com/platform/external/avb/Quoted 1 line
Quoted 1 line
[..]
Regards,
Simon
PATCH 4/8 cmd: avb2.0: avb command for performing verification
Hi Simon,
Quoted 2 lines
If there is no need for operations and indirection through function pointers, why not just call the functions directly?
This is the way how libavb is integrated into bootloader. libavb interfaces with the bootloader through the supplied AvbOps struct. This includes operations to read and write data from partitions, read and write rollback indexes, check if the public key used to make a signature should be accepted, and so on. This is what Google AVB 2.0 specification says.
For additional details please check [1].
In this particular patch, all avb commands, except the main "avb verify", are used
to debug these particular callback implementations
(can be used when enabling this feature on new platform etc.). The reason I use indirection through function pointers is that they are not supposed
to be public, and are not intended to be used somehow directly, only by libavb (check [2] how libavb is using it)
Quoted 7 lines
Quoted 4 lines
(I've left a notice in the cover letter that checkpatch
will fail on the commit, which introduces libavb; also, there is the ongoing discussion there regarding why libavb/libavb_ab should be
kept as it's. Please join us, if you don't mind).I do see the cover letter thread but could not find the camel case discussion. Can you please point me to it?
There is no any particular discussion about CamelCase, but a few general statements why I should avoid introducing any changes in libavb/libavb_ab libraries.
Regarding our particular case, AvbSlotVerifyResult and AvbSlotVerifyData types (I guess you're talking about these CamelCase instances) are defined inside libavb library, so obviously I can't simply replace it with something, that conforms to the Linux kernel coding style
Thanks
[1] https://android.googlesource.com/platform/external/avb/+/master/README.md#system-dependencies
[2] https://android.googlesource.com/platform/external/avb/+/master/libavb/avb_cmdline.c#71
Quoted 83 lines · Simon Glass
(Tom can you please comment on the CamelCase question?)
Hi Igor,
Quoted 28 lines · Igor Opaniuk
Quoted 20 lines · Simon Glass
Hi Igor,
Quoted 10 lines · Igor Opaniuk
Hi Simon,
I've dug into DriverModel documentation and even created a PoC for existing avb commands. The problem is that (maybe I missed out some key concepts) I'm still
not sure if it makes sense to follow it driver mode in the context of AVB 2.0 feature and
what kind of extra devices can be used within the same uclass in this case? Could you please explain in detail.
Thanks
avb_ops_alloc()is allocating a struct and then assigning operations to its members.This is what driver model is designed to do. It handles the allocations and the operations become part of the uclass interface.
Quoted 6 lines
At present it looks like you only have one driver. I'm not sure if it would make sense to have a second one.
As a counter example see
cros_ecuclass, which does things differently. It models the EC interface (I2C, SPI, LPC) using DM, with just a single impl on top.Quoted 7 lines
Right, I do understand what DriverModel is and why it should be used in the case of real-device drivers. But regarding Android Verified Boot 2.0 feature, which introduces verification capabilities and leverages only device-independent APIs,
I see no reason why it should be used here.
Could you please check [1] and confirm that this set of commands should really follow this model.If there is no need for operations and indirection through function pointers, why not just call the functions directly?
I do think (as the code is currently structured) that DM makes sense, even though I understand that you are not creating a device. Perhaps Tom might have thoughts on this though?
Quoted 9 lines
Quoted 3 lines
Also can you please drop the CamelCase in the patches? We don't use that in U-Boot.
Frankly, I don't like it also, bit all CamelCase instances in the code relate to libavb/libavb_ab library ([2]), which is planned to be deviated from AOSP upstream in the future.
That's why a decision was made to not introduce any changes to simplify this process, as Google intensively introduces new changes to it.Tom, what do you think? It's not how things usually work, but perhaps there is precedent for this?
Quoted 4 lines
(I've left a notice in the cover letter that checkpatch
will fail on the commit, which introduces libavb; also, there is the ongoing discussion there regarding why libavb/libavb_ab should be
kept as it's. Please join us, if you don't mind).I do see the cover letter thread but could not find the camel case discussion. Can you please point me to it?
Quoted 9 lines
Thanks!
Best regards,
Igor[1] https://android.googlesource.com/platform/external/avb/+/master/README.md
[2] https://android.googlesource.com/platform/external/avb/Quoted 1 line
Quoted 1 line
[..]
Regards,
Simon
Signature · 2 lines
Regards, Igor Opaniuk
PATCH 4/8 cmd: avb2.0: avb command for performing verification
Hi Igor,
Quoted 29 lines · Igor Opaniuk
Hi Simon,
Quoted 2 lines
If there is no need for operations and indirection through function pointers, why not just call the functions directly?
This is the way how libavb is integrated into bootloader. libavb interfaces with the bootloader through the supplied AvbOps struct. This includes operations to read and write data from partitions, read and write rollback indexes, check if the public key used to make a signature should be accepted, and so on. This is what Google AVB 2.0 specification says.
For additional details please check [1].In this particular patch, all avb commands, except the main "avb verify", are used
to debug these particular callback implementations
(can be used when enabling this feature on new platform etc.). The reason I use indirection through function pointers is that they are not supposed
to be public, and are not intended to be used somehow directly, only by libavb (check [2] how libavb is using it)Quoted 7 lines
Quoted 4 lines
(I've left a notice in the cover letter that checkpatch
will fail on the commit, which introduces libavb; also, there is the ongoing discussion there regarding why libavb/libavb_ab should be
kept as it's. Please join us, if you don't mind).I do see the cover letter thread but could not find the camel case discussion. Can you please point me to it?
Quoted 7 lines
There is no any particular discussion about CamelCase, but a few general statements why I should avoid introducing any changes in libavb/libavb_ab libraries.
Regarding our particular case, AvbSlotVerifyResult and AvbSlotVerifyData types (I guess you're talking about these CamelCase instances) are defined inside libavb library, so obviously I can't simply replace it with something, that conforms to the Linux kernel coding style
Maybe I've lost track of the patches, but I thought you were implementing this library in U-Boot and thus can call things whatever you like?
We have had a similar thing with EFI, but in that case there was no reference code to use, so it was easier to just rename things to kernel style.
In this case it seems that you want to be able to easily merge changes back and forth between U-Boot's copy of the library and the upstream one.
I think we have to balance that desire against the impact of having non-conforming code in the U-Boot code base. So far we have tended to adjust the code to fit kernel style in these situations.
Anyway I think this is Tom's call and I'm happy with whatever he decides.
[..]
Regards,
Simon
PATCH 5/8 avb2.0: add boot states and dm-verity support
In reply to Igor Opaniuk1. Add initial support of boot states mode (red, green, yellow)
2. Add functions for enforcing dm-verity configurations
--- cmd/avb.c | 17 ++++++- common/avb_verify.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++-- include/avb_verify.h | 19 ++++++- 3 files changed, 171 insertions(+), 5 deletions(-)
cmd/avb.c +16 -1
@@ -218,6 +218,8 @@ int do_avb_verify_part(cmd_tbl_t *cmdtp, int flag, {AvbSlotVerifyResult slot_result;AvbSlotVerifyData *out_data; +char *cmdline; +char *extra_args;bool unlocked = false;int res =CMD_RET_FAILURE ;
@@ -243,10 +245,23 @@ int do_avb_verify_part(cmd_tbl_t *cmdtp, int flag, "", unlocked, &out_data);switch (slot_result) {case AVB_SLOT_VERIFY_RESULT_OK : +/* Until we don't have support of changing unlock states, we +* assume that we are by default in locked state. +* So in this case we can boot only when verification is +* successful; we also supply in cmdline GREEN boot state +*/ printf ("Verification passed successfully\n" );/* export additional bootargs to AVB_BOOTARGS env var */ -env_set (AVB_BOOTARGS , out_data->cmdline); + + extra_args =avb_set_state (avb_ops,AVB_GREEN ); +if (extra_args) + cmdline =append_cmd_line (out_data->cmdline, + extra_args); +else + cmdline = out_data->cmdline; + +env_set (AVB_BOOTARGS , cmdline); res =CMD_RET_SUCCESS ;break ;
common/avb_verify.c +137 -3
164 lines not on this page · raw message
include/avb_verify.h +18 -1
@@ -11,12 +11,23 @@#include <avb/libavb_ab.h> #include <mmc.h> -#define ALLOWED_BUF_ALIGN 8 +#define AVB_MAX_ARGS 1024 +#define VERITY_TABLE_OPT_RESTART "restart_on_corruption" +#define VERITY_TABLE_OPT_LOGGING "ignore_corruption" +#define ALLOWED_BUF_ALIGN 8 + +enum avb_boot_state { +AVB_GREEN , +AVB_YELLOW , +AVB_ORANGE , +AVB_RED , +};struct AvbOpsData {struct AvbOps ops;struct AvbABOps ab_ops;int mmc_dev; +enum avb_boot_state boot_state; };struct mmc_part {
@@ -34,6 +45,12 @@ enum mmc_io_type {AvbOps *avb_ops_alloc (int boot_device);void avb_ops_free (AvbOps *ops); +char *avb_set_state (AvbOps *ops,enum avb_boot_state boot_state); +char *avb_set_enforce_verity (const char *cmdline); +char *avb_set_ignore_corruption (const char *cmdline); + +char *append_cmd_line (char *cmdline_orig,char *cmdline_new); +/** * ============================================================================ * I/O helper inline functions
Signature · 1 line
2.7.4
PATCH 5/8 avb2.0: add boot states and dm-verity support
Quoted 104 lines · Igor Opaniuk
1. Add initial support of boot states mode (red, green, yellow)
2. Add functions for enforcing dm-verity configurationsSigned-off-by Igor Opaniuk <[email protected]>--- cmd/avb.c | 17 ++++++- common/avb_verify.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++++-- include/avb_verify.h | 19 ++++++- 3 files changed, 171 insertions(+), 5 deletions(-)cmd/avb.c +16
-1@@ -218,6 +218,8 @@ int do_avb_verify_part(cmd_tbl_t *cmdtp, int flag, {AvbSlotVerifyResult slot_result;AvbSlotVerifyData *out_data; +char *cmdline; +char *extra_args;bool unlocked = false;int res =CMD_RET_FAILURE ;@@ -243,10 +245,23 @@ int do_avb_verify_part(cmd_tbl_t *cmdtp, int flag, "", unlocked, &out_data);switch (slot_result) {case AVB_SLOT_VERIFY_RESULT_OK : +/* Until we don't have support of changing unlock states, we +* assume that we are by default in locked state. +* So in this case we can boot only when verification is +* successful; we also supply in cmdline GREEN boot state +*/ printf ("Verification passed successfully\n" );/* export additional bootargs to AVB_BOOTARGS env var */ -env_set (AVB_BOOTARGS , out_data->cmdline); + + extra_args =avb_set_state (avb_ops,AVB_GREEN ); +if (extra_args) + cmdline =append_cmd_line (out_data->cmdline, + extra_args); +else + cmdline = out_data->cmdline; + +env_set (AVB_BOOTARGS , cmdline); res =CMD_RET_SUCCESS ;break ;common/avb_verify.c +48
-0@@ -119,6 +119,140 @@ const unsigned char avb_root_pub[1032] = {/** * ============================================================================ +* Boot states support (GREEN, YELLOW, ORANGE, RED) and dm_verity +* ============================================================================ +*/ +char *avb_set_state (AvbOps *ops,enum avb_boot_state boot_state) +{ +struct AvbOpsData *data; +char *cmdline =NULL ; + +if (!ops) +return NULL ; + + data = (struct AvbOpsData *)ops->user_data; +if (!data) +return NULL ; + + data->boot_state = boot_state; +switch (boot_state) { +case AVB_GREEN : + cmdline ="androidboot.verifiedbootstate=green" ; +break ; +case AVB_YELLOW : + cmdline ="androidboot.verifiedbootstate=yellow" ; +break ; +case AVB_ORANGE : + cmdline ="androidboot.verifiedbootstate=orange" ; +case AVB_RED : +break ; + } + +return cmdline; +} + +char *append_cmd_line (char *cmdline_orig,char *cmdline_new) +{ +char *cmd_line; + +if (!cmdline_new) +return cmdline_orig; + +if (cmdline_orig) + cmd_line = cmdline_orig; +else + cmd_line =" " ; + + cmd_line =avb_strdupv (cmd_line," " , cmdline_new,NULL ); + +return cmd_line; +}
common/avb_verify.c const unsigned char avb_root_pub[1032] = { · line 179
Quoted 10 lines
common/avb_verify.c +10
-0+ +static int avb_find_dm_args (char **args,char *str) +{ +int i =0 ; + +if (!str) +return -1 ; + + do { + if ((!args[i]) || (i >= AVB_MAX_ARGS))
Conditions probably should be swapped, to avoid "index out of bounds" error.
common/avb_verify.c const unsigned char avb_root_pub[1032] = { · line 187
Quoted 8 lines
common/avb_verify.c +8
-0+return -1 ; + +if (strstr (args[i], str)) +return i; + + i++; + }while (1 ); +}
Just a suggestion: wouldn't it be better to use "for" instead of "do/while" here? Like this:
for (i = 0; i < AVB_MAX_ARGS, args[i]; ++i) {
if (strstr(args[i], str))
return i;
}
return -1;Quoted 143 lines
common/avb_verify.c +71
-3+ +static char *avb_set_enforce_option (const char *cmdline,const char *option) +{ +char *cmdarg[AVB_MAX_ARGS ]; +char *newargs =NULL ; +int i =0 ; +int total_args; + +memset (cmdarg,0 ,sizeof (cmdarg)); + cmdarg[i++] =strtok ((char *)cmdline," " ); + +do { + cmdarg[i] =strtok (NULL ," " ); +if (!cmdarg[i]) +break ; + +if (++i >=AVB_MAX_ARGS ) { +printf ("%s: Can't handle more then %d args\n" , + __func__, i); +return NULL ; + } + }while (true); + + total_args = i; + i =avb_find_dm_args (&cmdarg[0 ],VERITY_TABLE_OPT_LOGGING ); +if (i >=0 ) { + cmdarg[i] = (char *)option; + }else { + i =avb_find_dm_args (&cmdarg[0 ],VERITY_TABLE_OPT_RESTART ); +if (i <0 ) { +printf ("%s: No verity options found\n" , __func__); +return NULL ; + } + + cmdarg[i] = (char *)option; + } + +for (i =0 ; i <= total_args; i++) + newargs =append_cmd_line (newargs, cmdarg[i]); + +return newargs; +} + +char *avb_set_ignore_corruption (const char *cmdline) +{ +char *newargs =NULL ; + + newargs =avb_set_enforce_option (cmdline,VERITY_TABLE_OPT_LOGGING ); +if (newargs) + newargs =append_cmd_line (newargs, +"androidboot.veritymode=eio" ); + +return newargs; +} + +char *avb_set_enforce_verity (const char *cmdline) +{ +char *newargs; + + newargs =avb_set_enforce_option (cmdline,VERITY_TABLE_OPT_RESTART ); +if (newargs) + newargs =append_cmd_line (newargs, +"androidboot.veritymode=enforcing" ); +return newargs; +} + +/** +* ============================================================================ * IO(mmc) auxiliary functions * ============================================================================ */ @@ -478,7 +612,7 @@ static AvbIOResult read_rollback_index(AvbOps *ops, u64 *out_rollback_index) {/* For now we always return 0 as the stored rollback index. */ -printf ("TODO: implement %s.\n" , __func__); +printf ("%s not supported yet\n" , __func__);if (out_rollback_index) *out_rollback_index =0 ;@@ -502,7 +636,7 @@ static AvbIOResult write_rollback_index(AvbOps *ops, u64 rollback_index) {/* For now this is a no-op. */ -printf ("TODO: implement %s.\n" , __func__); +printf ("%s not supported yet\n" , __func__);return AVB_IO_RESULT_OK ; }@@ -522,7 +656,7 @@ static AvbIOResult read_is_device_unlocked(AvbOps *ops, bool *out_is_unlocked) {/* For now we always return that the device is unlocked. */ -printf ("TODO: implement %s.\n" , __func__); +printf ("%s not supported yet\n" , __func__); *out_is_unlocked = true;include/avb_verify.h +18
-2@@ -11,12 +11,23 @@#include <avb/libavb_ab.h> #include <mmc.h> -#define ALLOWED_BUF_ALIGN 8 +#define AVB_MAX_ARGS 1024 +#define VERITY_TABLE_OPT_RESTART "restart_on_corruption" +#define VERITY_TABLE_OPT_LOGGING "ignore_corruption" +#define ALLOWED_BUF_ALIGN 8 + +enum avb_boot_state { +AVB_GREEN , +AVB_YELLOW , +AVB_ORANGE , +AVB_RED , +};struct AvbOpsData {struct AvbOps ops;struct AvbABOps ab_ops;int mmc_dev; +enum avb_boot_state boot_state; };struct mmc_part {@@ -34,6 +45,12 @@ enum mmc_io_type {AvbOps *avb_ops_alloc (int boot_device);void avb_ops_free (AvbOps *ops); +char *avb_set_state (AvbOps *ops,enum avb_boot_state boot_state); +char *avb_set_enforce_verity (const char *cmdline); +char *avb_set_ignore_corruption (const char *cmdline); + +char *append_cmd_line (char *cmdline_orig,char *cmdline_new); +/** * ============================================================================ * I/O helper inline functions -- 2.7.4
PATCH 6/8 am57xx_hs: avb2.0: add support of AVB 2.0
In reply to Igor Opaniuk1. Add vbmeta partition info to android partition layout for am57xx SoC
2. Add support of AVB 2.0 (including avb subset of commands) for am57xx HS
--- configs/am57xx_hs_evm_defconfig | 3 +++ include/configs/am57xx_evm.h | 11 +++++++++++ include/environment/ti/boot.h | 15 +++++++++++++++ 3 files changed, 29 insertions(+)
configs/am57xx_hs_evm_defconfig +3 -0
@@ -81,3 +81,6 @@ CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="Texas Instruments" CONFIG_USB_GADGET_VENDOR_NUM=0x0451 CONFIG_USB_GADGET_PRODUCT_NUM=0xd022 +# CONFIG_LIBAVB is not set +# CONFIG_LIBAVB_AB is not set +# CONFIG_CMD_AVB is not set
include/configs/am57xx_evm.h +11 -0
@@ -38,6 +38,16 @@#define CONFIG_SYS_OMAP_ABE_SYSCK +#define str (a) #a +#define VBMETA_PART_SIZE (64 * 1024) + +#if defined(CONFIG_LIBAVB ) +#define VBMETA_PART \ + "name=vbmeta,size=" str(VBMETA_PART_SIZE) ",uuid=${uuid_gpt_vbmeta};" +#else +#define VBMETA_PART "" +#endif +/* Define the default GPT table for eMMC */ #define PARTS_DEFAULT \/* Linux partitions */ \
@@ -61,6 +71,7 @@"name=cache,size=256M,uuid=${uuid_gpt_cache};" \"name=ipu1,size=1M,uuid=${uuid_gpt_ipu1};" \"name=ipu2,size=1M,uuid=${uuid_gpt_ipu2};" \ +VBMETA_PART \"name=userdata,size=-,uuid=${uuid_gpt_userdata}" #define DFUARGS \
include/environment/ti/boot.h +15 -0
@@ -18,6 +18,19 @@#define PARTS_DEFAULT #endif +#if defined(CONFIG_CMD_AVB ) +#define AVB_VERIFY_CHECK "if run avb_verify; then " \ + "echo AVB verification OK.;" \ + "set bootargs $bootargs $avb_bootargs;" \ + "else " \ + "echo AVB verification failed.;" \ + "exit; fi;" +#define AVB_VERIFY_CMD "avb_verify=avb init 1; avb verify;\0" +#else +#define AVB_VERIFY_CHECK "" +#define AVB_VERIFY_CMD "" +#endif +#define DEFAULT_COMMON_BOOT_TI_ARGS \ "console=" CONSOLEDEV ",115200n8\0" \ "fdtfile=undefined\0" \
@@ -26,6 +39,7 @@"bootfile=zImage\0" \"usbtty=cdc_acm\0" \"vram=16M\0" \ +AVB_VERIFY_CMD \"partitions=" PARTS_DEFAULT "\0" \"optargs=\0" \"dofastboot=0\0" \
@@ -43,6 +57,7 @@"setenv machid fe6; " \"mmc dev $mmcdev; " \"mmc rescan; " \ +AVB_VERIFY_CHECK \"part start mmc ${mmcdev} environment fdt_start; " \"part size mmc ${mmcdev} environment fdt_size; " \"part start mmc ${mmcdev} boot boot_start; " \
Signature · 1 line
2.7.4
PATCH 6/8 am57xx_hs: avb2.0: add support of AVB 2.0
Quoted 15 lines · Igor Opaniuk
1. Add vbmeta partition info to android partition layout for am57xx SoC
2. Add support of AVB 2.0 (including avb subset of commands) for am57xx HSSigned-off-by Igor Opaniuk <[email protected]>--- configs/am57xx_hs_evm_defconfig | 3 +++ include/configs/am57xx_evm.h | 11 +++++++++++ include/environment/ti/boot.h | 15 +++++++++++++++ 3 files changed, 29 insertions(+)configs/am57xx_hs_evm_defconfig +0
-0
configs/am57xx_hs_evm_defconfig CONFIG_USB_GADGET=y · line 86
Quoted 6 lines
configs/am57xx_hs_evm_defconfig +3
-0@@ -81,3 +81,6 @@ CONFIG_USB_GADGET=y CONFIG_USB_GADGET_MANUFACTURER="Texas Instruments" CONFIG_USB_GADGET_VENDOR_NUM=0x0451 CONFIG_USB_GADGET_PRODUCT_NUM=0xd022 +# CONFIG_LIBAVB is not set +# CONFIG_LIBAVB_AB is not set +# CONFIG_CMD_AVB is not set
Maybe it would be better to put "default n" to corresponding options in Kconfig? So that we only need to enable those when needed, instead of disabling in all not related configs. Because otherwise we risk to have not needed feature enabled in all boards. But "buildman" should show you that, if you run it for all "arm" boards.
include/configs/am57xx_evm.h line 41
Quoted 9 lines
include/configs/am57xx_evm.h +1
-0@@ -38,6 +38,16 @@#define CONFIG_SYS_OMAP_ABE_SYSCK +#define str (a) #a
Consider using __stringify_1() or just __stringify() for this.
Quoted 63 lines
include/configs/am57xx_evm.h +10
-0+#define VBMETA_PART_SIZE (64 * 1024) + +#if defined(CONFIG_LIBAVB ) +#define VBMETA_PART \ + "name=vbmeta,size=" str(VBMETA_PART_SIZE) ",uuid=${uuid_gpt_vbmeta};" +#else +#define VBMETA_PART "" +#endif +/* Define the default GPT table for eMMC */ #define PARTS_DEFAULT \/* Linux partitions */ \@@ -61,6 +71,7 @@"name=cache,size=256M,uuid=${uuid_gpt_cache};" \"name=ipu1,size=1M,uuid=${uuid_gpt_ipu1};" \"name=ipu2,size=1M,uuid=${uuid_gpt_ipu2};" \ +VBMETA_PART \"name=userdata,size=-,uuid=${uuid_gpt_userdata}" #define DFUARGS \include/environment/ti/boot.h +15
-1@@ -18,6 +18,19 @@#define PARTS_DEFAULT #endif +#if defined(CONFIG_CMD_AVB ) +#define AVB_VERIFY_CHECK "if run avb_verify; then " \ + "echo AVB verification OK.;" \ + "set bootargs $bootargs $avb_bootargs;" \ + "else " \ + "echo AVB verification failed.;" \ + "exit; fi;" +#define AVB_VERIFY_CMD "avb_verify=avb init 1; avb verify;\0" +#else +#define AVB_VERIFY_CHECK "" +#define AVB_VERIFY_CMD "" +#endif +#define DEFAULT_COMMON_BOOT_TI_ARGS \ "console=" CONSOLEDEV ",115200n8\0" \ "fdtfile=undefined\0" \@@ -26,6 +39,7 @@"bootfile=zImage\0" \"usbtty=cdc_acm\0" \"vram=16M\0" \ +AVB_VERIFY_CMD \"partitions=" PARTS_DEFAULT "\0" \"optargs=\0" \"dofastboot=0\0" \@@ -43,6 +57,7 @@"setenv machid fe6; " \"mmc dev $mmcdev; " \"mmc rescan; " \ +AVB_VERIFY_CHECK \"part start mmc ${mmcdev} environment fdt_start; " \"part size mmc ${mmcdev} environment fdt_size; " \"part start mmc ${mmcdev} boot boot_start; " \ --2.7.4
PATCH 7/8 test/py: avb2.0: add tests for avb commands
In reply to Igor Opaniuk1. Run AVB 2.0 full verification chain, avb verify
2. Check if 'avb get_uuid' works, compare results with 'part list mmc 1' output
3. Test avb read commands, which reads N bytes from a partition identified by a name
--- test/py/tests/test_avb.py | 111 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 test/py/tests/test_avb.py
test/py/tests/test_avb.py new file +111 -0
@@ -0,0 +1,111 @@ +# Copyright (c) 2018, Linaro Limited +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Android Verified Boot 2.0 Test + +""" +This tests Android Verified Boot 2.0 support in U-boot: + +For additional details about how to build proper vbmeta partition +check doc/README.avb2 + +For configuration verification: +- Corrupt boot partition and check for failure +- Corrupt vbmeta partition and check for failure +""" + +import pytest +import u_boot_utils as util + +# defauld mmc id +mmc_dev = 1 +temp_addr = 0x90000000 +temp_addr2 = 0x90002000 + +def test_avb_verify(u_boot_console): + """Run AVB 2.0 boot verification chain with avb subset of commands + """ + + success_str = "Verification passed successfully" + + response = u_boot_console.run_command('avb init %s' %str(mmc_dev)) + assert response == '' + response = u_boot_console.run_command('avb verify') + assert response.find(success_str) + + +def test_avb_mmc_uuid(u_boot_console): + """Check if 'avb get_uuid' works, compare results with + 'part list mmc 1' output + """ + + response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) + assert response == '' + + response = u_boot_console.run_command('mmc rescan; mmc dev %s' % + str(mmc_dev)) + assert response.find('is current device') + + part_lines = u_boot_console.run_command('mmc part').splitlines() + part_list = {} + cur_partname = "" + + for line in part_lines: + if "\"" in line: + start_pt = line.find("\"") + end_pt = line.find("\"", start_pt + 1) + cur_partname = line[start_pt + 1: end_pt] + + if "guid:" in line: + guid_to_check = line.split("guid:\t") + part_list[cur_partname] = guid_to_check[1] + + # lets check all guids with avb get_guid + for part, guid in part_list.iteritems(): + avb_guid_resp = u_boot_console.run_command('avb get_uuid %s' % part) + assert guid == avb_guid_resp.split("UUID: ")[1] + + +def test_avb_read_rb(u_boot_console): + """Test reading rollback indexes + """ + + response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) + assert response == '' + + response = u_boot_console.run_command('avb read_rb 1') + + +def test_avb_is_unlocked(u_boot_console): + """Test if device is in the unlocked state + """ + + response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) + assert response == '' + + response = u_boot_console.run_command('avb is_unlocked') + + +def test_avb_mmc_read(u_boot_console): + """Test mmc read operation + """ + + response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' % + str(mmc_dev)) + assert response.find('is current device') + + response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr) + assert response.find('read: OK') + + response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) + assert response == '' + + response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' % + temp_addr2) + assert response.find('Read 512 bytes') + + # Now lets compare two buffers + response = u_boot_console.run_command('cmp 0x%x 0x%x 40' % + (temp_addr, temp_addr2)) + assert response.find('64 word')
Signature · 1 line
2.7.4
PATCH 8/8 doc: avb2.0: add README about AVB2.0 integration
In reply to Igor OpaniukContains:
1. Overview of Android Verified Boot 2.0
2. Description of avb subset of commands
3. Examples of errors when boot/vendor/system/vbmeta partitions are tampered
4. Examples of enabling AVB2.0 on your setup
--- doc/README.avb2 | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 doc/README.avb2
doc/README.avb2 new file +100 -0
@@ -0,0 +1,100 @@ +Android Verified Boot 2.0 + +This file contains information about the current support of Android Verified +Boot 2.0 in U-boot + +1. OVERVIEW +--------------------------------- +Verified Boot establishes a chain of trust from the bootloader to system images +* Provides integrity checking for: + - Android Boot image: Linux kernel + ramdisk. RAW hashing of the whole + partition is done and the hash is compared with the one stored in + the VBMeta image + - system/vendor partitions: verifying root hash of dm-verity hashtrees. +* Provides capabilities for rollback protection. + +Integrity of the bootloader (U-boot BLOB and environment) is out of scope. + +For additional details check: +https://android.googlesource.com/platform/external/avb/+/master/README.md + + +2. AVB 2.0 U-BOOT SHELL COMMANDS +----------------------------------- +Provides CLI interface to invoke AVB 2.0 verification + misc. commands for +different testing purposes: + +avb init <dev> - initialize avb 2.0 for <dev> +avb verify - run verification process using hash data from vbmeta structure +avb read_rb <num> - read rollback index at location <num> +avb write_rb <num> <rb> - write rollback index <rb> to <num> +avb is_unlocked - returns unlock status of the device +avb get_uuid <partname> - read and print uuid of partition <partname> +avb read_part <partname> <offset> <num> <addr> - read <num> bytes from +partition <partname> to buffer <addr> +avb write_part <partname> <offset> <num> <addr> - write <num> bytes to +<partname> by <offset> using data from <addr> + + +3. PARTITIONS TAMPERING (EXAMPLE) +----------------------------------- +Boot or system/vendor (dm-verity metadata section) is tampered: +=> avb init 1 +=> avb verify +avb_slot_verify.c:175: ERROR: boot: Hash of data does not match digest in +descriptor. +Slot verification result: ERROR_IO + +Vbmeta partition is tampered: +=> avb init 1 +=> avb verify +avb_vbmeta_image.c:206: ERROR: Hash does not match! +avb_slot_verify.c:388: ERROR: vbmeta: Error verifying vbmeta image: +HASH_MISMATCH +Slot verification result: ERROR_IO + + +4. ENABLE ON YOUR BOARD +----------------------------------- +The following options must be enabled: +CONFIG_LIBAVB=y +CONFIG_LIBAVB_AB=y +CONFIG_CMD_AVB=y + + +Then add `avb verify` invocation to your android boot sequence of commands, +e.g.: + +=> avb_verify=avb init $mmcdev; avb verify; +=> if run avb_verify; then \ + echo AVB verification OK. Continue boot; \ + set bootargs $bootargs $avb_bootargs; \ + else \ + echo AVB verification failed; \ + exit; \ + fi; \ + +=> emmc_android_boot= \ + echo Trying to boot Android from eMMC ...; \ + ... \ + run avb_verify; \ + mmc read ${fdtaddr} ${fdt_start} ${fdt_size}; \ + mmc read ${loadaddr} ${boot_start} ${boot_size}; \ + bootm $loadaddr $loadaddr $fdtaddr; \ + + +To switch on automatic generation of vbmeta partition in AOSP build, add these +lines to device configuration mk file: + +BOARD_AVB_ENABLE := true +BOARD_AVB_ALGORITHM := SHA512_RSA4096 +BOARD_BOOTIMAGE_PARTITION_SIZE := <boot partition size> + +After flashing U-boot don't forget to update environment and write new +partition table: +=> env default -f -a +=> setenv partitions $partitions_android +=> env save +=> fas 1 + +$ fastboot oem format
Signature · 1 line
2.7.4
PATCH 8/8 doc: avb2.0: add README about AVB2.0 integration
Quoted 109 lines · Igor Opaniuk
Contains:
1. Overview of Android Verified Boot 2.0
2. Description of avb subset of commands
3. Examples of errors when boot/vendor/system/vbmeta partitions are tampered
4. Examples of enabling AVB2.0 on your setupSigned-off-by Igor Opaniuk <[email protected]>--- doc/README.avb2 | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 doc/README.avb2doc/README.avb2 new file +90
-0@@ -0,0 +1,100 @@ +Android Verified Boot 2.0 + +This file contains information about the current support of Android Verified +Boot 2.0 in U-boot + +1. OVERVIEW +--------------------------------- +Verified Boot establishes a chain of trust from the bootloader to system images +* Provides integrity checking for: + - Android Boot image: Linux kernel + ramdisk. RAW hashing of the whole + partition is done and the hash is compared with the one stored in + the VBMeta image + - system/vendor partitions: verifying root hash of dm-verity hashtrees. +* Provides capabilities for rollback protection. + +Integrity of the bootloader (U-boot BLOB and environment) is out of scope. + +For additional details check: +https://android.googlesource.com/platform/external/avb/+/master/README.md + + +2. AVB 2.0 U-BOOT SHELL COMMANDS +----------------------------------- +Provides CLI interface to invoke AVB 2.0 verification + misc. commands for +different testing purposes: + +avb init <dev> - initialize avb 2.0 for <dev> +avb verify - run verification process using hash data from vbmeta structure +avb read_rb <num> - read rollback index at location <num> +avb write_rb <num> <rb> - write rollback index <rb> to <num> +avb is_unlocked - returns unlock status of the device +avb get_uuid <partname> - read and print uuid of partition <partname> +avb read_part <partname> <offset> <num> <addr> - read <num> bytes from +partition <partname> to buffer <addr> +avb write_part <partname> <offset> <num> <addr> - write <num> bytes to +<partname> by <offset> using data from <addr> + + +3. PARTITIONS TAMPERING (EXAMPLE) +----------------------------------- +Boot or system/vendor (dm-verity metadata section) is tampered: +=> avb init 1 +=> avb verify +avb_slot_verify.c:175: ERROR: boot: Hash of data does not match digest in +descriptor. +Slot verification result: ERROR_IO + +Vbmeta partition is tampered: +=> avb init 1 +=> avb verify +avb_vbmeta_image.c:206: ERROR: Hash does not match! +avb_slot_verify.c:388: ERROR: vbmeta: Error verifying vbmeta image: +HASH_MISMATCH +Slot verification result: ERROR_IO + + +4. ENABLE ON YOUR BOARD +----------------------------------- +The following options must be enabled: +CONFIG_LIBAVB=y +CONFIG_LIBAVB_AB=y +CONFIG_CMD_AVB=y + + +Then add `avb verify` invocation to your android boot sequence of commands, +e.g.: + +=> avb_verify=avb init $mmcdev; avb verify; +=> if run avb_verify; then \ + echo AVB verification OK. Continue boot; \ + set bootargs $bootargs $avb_bootargs; \ + else \ + echo AVB verification failed; \ + exit; \ + fi; \ + +=> emmc_android_boot= \ + echo Trying to boot Android from eMMC ...; \ + ... \ + run avb_verify; \ + mmc read ${fdtaddr} ${fdt_start} ${fdt_size}; \ + mmc read ${loadaddr} ${boot_start} ${boot_size}; \ + bootm $loadaddr $loadaddr $fdtaddr; \ + + +To switch on automatic generation of vbmeta partition in AOSP build, add these +lines to device configuration mk file: + +BOARD_AVB_ENABLE := true +BOARD_AVB_ALGORITHM := SHA512_RSA4096
doc/README.avb2 line 100
Quoted 10 lines
doc/README.avb2 new file +10
-0+BOARD_BOOTIMAGE_PARTITION_SIZE := <boot partition size> + +After flashing U-boot don't forget to update environment and write new +partition table: +=> env default -f -a +=> setenv partitions $partitions_android +=> env save +=> fas 1 + +$ fastboot oem format
FYI, those commands can be shrank down to a single command:
=> gpt write mmc 1 $partitions_android
because that's exactly what "fastboot oem format" is doing. This way you can avoid using fastboot, and thus having it as a dependency. But your way is better w.r.t. user experience (i.e. if environment is already set, user can just run host command, and avoid tinkering with U-Boot shell at all). Please choose which one is better depending on targeting use-case.
Quoted 3 lines
--
2.7.4
PATCH 8/8 doc: avb2.0: add README about AVB2.0 integration
Hi Sam,
Thanks, will include this notice in the v2 patchset
Regards,
Igor
Quoted 135 lines · Sam Protsenko
Quoted 109 lines · Igor Opaniuk
Contains:
1. Overview of Android Verified Boot 2.0
2. Description of avb subset of commands
3. Examples of errors when boot/vendor/system/vbmeta partitions are tampered
4. Examples of enabling AVB2.0 on your setupSigned-off-by Igor Opaniuk <[email protected]>--- doc/README.avb2 | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 doc/README.avb2doc/README.avb2 new file +90
-0@@ -0,0 +1,100 @@ +Android Verified Boot 2.0 + +This file contains information about the current support of Android Verified +Boot 2.0 in U-boot + +1. OVERVIEW +--------------------------------- +Verified Boot establishes a chain of trust from the bootloader to system images +* Provides integrity checking for: + - Android Boot image: Linux kernel + ramdisk. RAW hashing of the whole + partition is done and the hash is compared with the one stored in + the VBMeta image + - system/vendor partitions: verifying root hash of dm-verity hashtrees. +* Provides capabilities for rollback protection. + +Integrity of the bootloader (U-boot BLOB and environment) is out of scope. + +For additional details check: +https://android.googlesource.com/platform/external/avb/+/master/README.md + + +2. AVB 2.0 U-BOOT SHELL COMMANDS +----------------------------------- +Provides CLI interface to invoke AVB 2.0 verification + misc. commands for +different testing purposes: + +avb init <dev> - initialize avb 2.0 for <dev> +avb verify - run verification process using hash data from vbmeta structure +avb read_rb <num> - read rollback index at location <num> +avb write_rb <num> <rb> - write rollback index <rb> to <num> +avb is_unlocked - returns unlock status of the device +avb get_uuid <partname> - read and print uuid of partition <partname> +avb read_part <partname> <offset> <num> <addr> - read <num> bytes from +partition <partname> to buffer <addr> +avb write_part <partname> <offset> <num> <addr> - write <num> bytes to +<partname> by <offset> using data from <addr> + + +3. PARTITIONS TAMPERING (EXAMPLE) +----------------------------------- +Boot or system/vendor (dm-verity metadata section) is tampered: +=> avb init 1 +=> avb verify +avb_slot_verify.c:175: ERROR: boot: Hash of data does not match digest in +descriptor. +Slot verification result: ERROR_IO + +Vbmeta partition is tampered: +=> avb init 1 +=> avb verify +avb_vbmeta_image.c:206: ERROR: Hash does not match! +avb_slot_verify.c:388: ERROR: vbmeta: Error verifying vbmeta image: +HASH_MISMATCH +Slot verification result: ERROR_IO + + +4. ENABLE ON YOUR BOARD +----------------------------------- +The following options must be enabled: +CONFIG_LIBAVB=y +CONFIG_LIBAVB_AB=y +CONFIG_CMD_AVB=y + + +Then add `avb verify` invocation to your android boot sequence of commands, +e.g.: + +=> avb_verify=avb init $mmcdev; avb verify; +=> if run avb_verify; then \ + echo AVB verification OK. Continue boot; \ + set bootargs $bootargs $avb_bootargs; \ + else \ + echo AVB verification failed; \ + exit; \ + fi; \ + +=> emmc_android_boot= \ + echo Trying to boot Android from eMMC ...; \ + ... \ + run avb_verify; \ + mmc read ${fdtaddr} ${fdt_start} ${fdt_size}; \ + mmc read ${loadaddr} ${boot_start} ${boot_size}; \ + bootm $loadaddr $loadaddr $fdtaddr; \ + + +To switch on automatic generation of vbmeta partition in AOSP build, add these +lines to device configuration mk file: + +BOARD_AVB_ENABLE := true +BOARD_AVB_ALGORITHM := SHA512_RSA4096doc/README.avb2 line 100
Quoted 10 lines
doc/README.avb2 new file +10
-0+BOARD_BOOTIMAGE_PARTITION_SIZE := <boot partition size> + +After flashing U-boot don't forget to update environment and write new +partition table: +=> env default -f -a +=> setenv partitions $partitions_android +=> env save +=> fas 1 + +$ fastboot oem formatFYI, those commands can be shrank down to a single command:
=> gpt write mmc 1 $partitions_android
because that's exactly what "fastboot oem format" is doing. This way you can avoid using fastboot, and thus having it as a dependency. But your way is better w.r.t. user experience (i.e. if environment is already set, user can just run host command, and avoid tinkering with U-Boot shell at all). Please choose which one is better depending on targeting use-case.
Quoted 3 lines
--
2.7.4
Signature · 2 lines
Regards, Igor Opaniuk
cover Initial integration of AVB2.0
In reply to Igor OpaniukHi Igor,
It's great to see the patch set to support AVB2.0, the upstream libavb(from aosp) combine the AVB with A/B which I think should be two separate feature, are you going to split them?
BTW, do you have plan to update boot_android cmd to support avb? the command is too weak for use now.
And any plan to add opptee_client/smcc to talk to OPTEE/ATF?
Thanks,
- Kever
Quoted 128 lines · Igor Opaniuk
This series of patches introduces support of Android Verified Boot 2.0, which provides integrity checking of Android partitions on MMC.
It integrates libavb/libavb_ab into the U-boot, provides implementation of AvbOps, subset of
avbcommands to run verification chain (and for debugging purposes), and it enables AVB2.0 verification on AM57xx HS SoC by default.Currently, there is still no support for verification of A/B boot slots and no rollback protection (for storing rollback indexes there are plans to use eMMC RPMB)
Libavb/libavb_ab will be deviated from AOSP upstream in the future, that's why minimal amount of changes were introduced into the lib sources, so checkpatch may fail.
For additional details check [1] AVB 2.0 README and doc/README.avb2, which is a part of this patchset.
[1] https://android.googlesource.com/platform/external/avb/+/master/README.md
Igor Opaniuk (8):
avb2.0: add Android Verified Boot 2.0 libraries avb2.0: integrate avb 2.0 into the build system avb2.0: implement AVB ops
cmd: avb2.0: avb command for performing verification avb2.0: add boot states and dm-verity support
am57xx_hs: avb2.0: add support of AVB 2.0 test/py: avb2.0: add tests for avb commands
doc: avb2.0: add README about AVB2.0 integrationcmd/Kconfig | 15 + cmd/Makefile | 3 + cmd/avb.c | 366 ++++++++ common/Makefile | 2 + common/avb_verify.c | 748 ++++++++++++++++ configs/am57xx_hs_evm_defconfig | 3 + doc/README.avb2 | 100 +++ include/avb/avb_ab_flow.h | 235 ++++++ include/avb/avb_ab_ops.h | 61 ++ include/avb/avb_chain_partition_descriptor.h | 54 ++ include/avb/avb_crypto.h | 147 ++++ include/avb/avb_descriptor.h | 113 +++ include/avb/avb_footer.h | 68 ++ include/avb/avb_hash_descriptor.h | 55 ++ include/avb/avb_hashtree_descriptor.h | 65 ++ include/avb/avb_kernel_cmdline_descriptor.h | 63 ++ include/avb/avb_ops.h | 196 +++++ include/avb/avb_property_descriptor.h | 89 ++ include/avb/avb_rsa.h | 55 ++ include/avb/avb_sha.h | 72 ++ include/avb/avb_slot_verify.h | 239 ++++++ include/avb/avb_sysdeps.h | 97 +++ include/avb/avb_util.h | 259 ++++++ include/avb/avb_vbmeta_image.h | 272 ++++++ include/avb/avb_version.h | 45 + include/avb/libavb.h | 32 + include/avb/libavb_ab.h | 22 + include/avb_verify.h | 97 +++ include/configs/am57xx_evm.h | 11 + include/environment/ti/boot.h | 15 + lib/Kconfig | 20 + lib/Makefile | 2 + lib/libavb/Makefile | 15 + lib/libavb/avb_chain_partition_descriptor.c | 46 + lib/libavb/avb_crypto.c | 355 ++++++++ lib/libavb/avb_descriptor.c | 142 ++++ lib/libavb/avb_footer.c | 36 + lib/libavb/avb_hash_descriptor.c | 43 + lib/libavb/avb_hashtree_descriptor.c | 51 ++ lib/libavb/avb_kernel_cmdline_descriptor.c | 40 + lib/libavb/avb_property_descriptor.c | 167 ++++ lib/libavb/avb_rsa.c | 277 ++++++ lib/libavb/avb_sha256.c | 364 ++++++++ lib/libavb/avb_sha512.c | 362 ++++++++ lib/libavb/avb_slot_verify.c | 1169 ++++++++++++++++++++++++++ lib/libavb/avb_sysdeps_posix.c | 57 ++ lib/libavb/avb_util.c | 385 +++++++++ lib/libavb/avb_vbmeta_image.c | 290 +++++++ lib/libavb/avb_version.c | 16 + lib/libavb_ab/Makefile | 9 + lib/libavb_ab/avb_ab_flow.c | 502 +++++++++++ test/py/tests/test_avb.py | 111 +++ 52 files changed, 8058 insertions(+) create mode 100644 cmd/avb.c create mode 100644 common/avb_verify.c create mode 100644 doc/README.avb2 create mode 100644 include/avb/avb_ab_flow.h create mode 100644 include/avb/avb_ab_ops.h create mode 100644 include/avb/avb_chain_partition_descriptor.h create mode 100644 include/avb/avb_crypto.h create mode 100644 include/avb/avb_descriptor.h create mode 100644 include/avb/avb_footer.h create mode 100644 include/avb/avb_hash_descriptor.h create mode 100644 include/avb/avb_hashtree_descriptor.h create mode 100644 include/avb/avb_kernel_cmdline_descriptor.h create mode 100644 include/avb/avb_ops.h create mode 100644 include/avb/avb_property_descriptor.h create mode 100644 include/avb/avb_rsa.h create mode 100644 include/avb/avb_sha.h create mode 100644 include/avb/avb_slot_verify.h create mode 100644 include/avb/avb_sysdeps.h create mode 100644 include/avb/avb_util.h create mode 100644 include/avb/avb_vbmeta_image.h create mode 100644 include/avb/avb_version.h create mode 100644 include/avb/libavb.h create mode 100644 include/avb/libavb_ab.h create mode 100644 include/avb_verify.h create mode 100644 lib/libavb/Makefile create mode 100644 lib/libavb/avb_chain_partition_descriptor.c create mode 100644 lib/libavb/avb_crypto.c create mode 100644 lib/libavb/avb_descriptor.c create mode 100644 lib/libavb/avb_footer.c create mode 100644 lib/libavb/avb_hash_descriptor.c create mode 100644 lib/libavb/avb_hashtree_descriptor.c create mode 100644 lib/libavb/avb_kernel_cmdline_descriptor.c create mode 100644 lib/libavb/avb_property_descriptor.c create mode 100644 lib/libavb/avb_rsa.c create mode 100644 lib/libavb/avb_sha256.c create mode 100644 lib/libavb/avb_sha512.c create mode 100644 lib/libavb/avb_slot_verify.c create mode 100644 lib/libavb/avb_sysdeps_posix.c create mode 100644 lib/libavb/avb_util.c create mode 100644 lib/libavb/avb_vbmeta_image.c create mode 100644 lib/libavb/avb_version.c create mode 100644 lib/libavb_ab/Makefile create mode 100644 lib/libavb_ab/avb_ab_flow.c create mode 100644 test/py/tests/test_avb.py
cover Initial integration of AVB2.0
Quoted 5 lines · Kever Yang
Hi Igor,
It's great to see the patch set to support AVB2.0, the upstream
libavb(from aosp) combine the AVB with A/B which I think should be two separate feature, are you going to split them?
Hi Kever,
Right, support of verification of A/B slots is going to be in a separate patch-set.
Quoted 3 lines
BTW, do you have plan to update
boot_androidcmd to support avb?
the command is too weak for use now.
And any plan to add opptee_client/smcc to talk to OPTEE/ATF?
Did you mean boot_android cmd from this patch
https://lists.denx.de/pipermail/u-boot/2017-April/285867.html,
that was never up-streamed? I guess the main suggestion was to extend existing bootm (by adding detection and parsing of Android boot images) instead of introducing brand new command for booting Android.
As currently major amount of boards use sequence of mmc/bootm commands for this purposes and bootm obviously is supposed to boot something from RAM, I assumed that it would be wrong to invoke avb verification from bootm itself. Because of this reason I've introduced avb set of commands for explicitly triggering the verification process. You can check the example how AVB2.0 is enabled on AM57xx HS (check "am57xx_hs: avb2.0: add support of AVB 2.0" patch).
The only one prerequisite is that U-boot env itself should be also a part of chain of trust (so it can't be tampered and "avb verify" removed)
Best regards,
Igor
Quoted 134 lines
Thanks,
- KeverQuoted 128 lines · Igor Opaniuk
This series of patches introduces support of Android Verified Boot 2.0, which provides integrity checking of Android partitions on MMC.
It integrates libavb/libavb_ab into the U-boot, provides implementation of AvbOps, subset of
avbcommands to run verification chain (and for debugging purposes), and it enables AVB2.0 verification on AM57xx HS SoC by default.Currently, there is still no support for verification of A/B boot slots and no rollback protection (for storing rollback indexes there are plans to use eMMC RPMB)
Libavb/libavb_ab will be deviated from AOSP upstream in the future, that's why minimal amount of changes were introduced into the lib sources, so checkpatch may fail.
For additional details check [1] AVB 2.0 README and doc/README.avb2, which is a part of this patchset.
[1] https://android.googlesource.com/platform/external/avb/+/master/README.md
Igor Opaniuk (8):
avb2.0: add Android Verified Boot 2.0 libraries avb2.0: integrate avb 2.0 into the build system avb2.0: implement AVB ops
cmd: avb2.0: avb command for performing verification avb2.0: add boot states and dm-verity support
am57xx_hs: avb2.0: add support of AVB 2.0 test/py: avb2.0: add tests for avb commands
doc: avb2.0: add README about AVB2.0 integrationcmd/Kconfig | 15 + cmd/Makefile | 3 + cmd/avb.c | 366 ++++++++ common/Makefile | 2 + common/avb_verify.c | 748 ++++++++++++++++ configs/am57xx_hs_evm_defconfig | 3 + doc/README.avb2 | 100 +++ include/avb/avb_ab_flow.h | 235 ++++++ include/avb/avb_ab_ops.h | 61 ++ include/avb/avb_chain_partition_descriptor.h | 54 ++ include/avb/avb_crypto.h | 147 ++++ include/avb/avb_descriptor.h | 113 +++ include/avb/avb_footer.h | 68 ++ include/avb/avb_hash_descriptor.h | 55 ++ include/avb/avb_hashtree_descriptor.h | 65 ++ include/avb/avb_kernel_cmdline_descriptor.h | 63 ++ include/avb/avb_ops.h | 196 +++++ include/avb/avb_property_descriptor.h | 89 ++ include/avb/avb_rsa.h | 55 ++ include/avb/avb_sha.h | 72 ++ include/avb/avb_slot_verify.h | 239 ++++++ include/avb/avb_sysdeps.h | 97 +++ include/avb/avb_util.h | 259 ++++++ include/avb/avb_vbmeta_image.h | 272 ++++++ include/avb/avb_version.h | 45 + include/avb/libavb.h | 32 + include/avb/libavb_ab.h | 22 + include/avb_verify.h | 97 +++ include/configs/am57xx_evm.h | 11 + include/environment/ti/boot.h | 15 + lib/Kconfig | 20 + lib/Makefile | 2 + lib/libavb/Makefile | 15 + lib/libavb/avb_chain_partition_descriptor.c | 46 + lib/libavb/avb_crypto.c | 355 ++++++++ lib/libavb/avb_descriptor.c | 142 ++++ lib/libavb/avb_footer.c | 36 + lib/libavb/avb_hash_descriptor.c | 43 + lib/libavb/avb_hashtree_descriptor.c | 51 ++ lib/libavb/avb_kernel_cmdline_descriptor.c | 40 + lib/libavb/avb_property_descriptor.c | 167 ++++ lib/libavb/avb_rsa.c | 277 ++++++ lib/libavb/avb_sha256.c | 364 ++++++++ lib/libavb/avb_sha512.c | 362 ++++++++ lib/libavb/avb_slot_verify.c | 1169 ++++++++++++++++++++++++++ lib/libavb/avb_sysdeps_posix.c | 57 ++ lib/libavb/avb_util.c | 385 +++++++++ lib/libavb/avb_vbmeta_image.c | 290 +++++++ lib/libavb/avb_version.c | 16 + lib/libavb_ab/Makefile | 9 + lib/libavb_ab/avb_ab_flow.c | 502 +++++++++++ test/py/tests/test_avb.py | 111 +++ 52 files changed, 8058 insertions(+) create mode 100644 cmd/avb.c create mode 100644 common/avb_verify.c create mode 100644 doc/README.avb2 create mode 100644 include/avb/avb_ab_flow.h create mode 100644 include/avb/avb_ab_ops.h create mode 100644 include/avb/avb_chain_partition_descriptor.h create mode 100644 include/avb/avb_crypto.h create mode 100644 include/avb/avb_descriptor.h create mode 100644 include/avb/avb_footer.h create mode 100644 include/avb/avb_hash_descriptor.h create mode 100644 include/avb/avb_hashtree_descriptor.h create mode 100644 include/avb/avb_kernel_cmdline_descriptor.h create mode 100644 include/avb/avb_ops.h create mode 100644 include/avb/avb_property_descriptor.h create mode 100644 include/avb/avb_rsa.h create mode 100644 include/avb/avb_sha.h create mode 100644 include/avb/avb_slot_verify.h create mode 100644 include/avb/avb_sysdeps.h create mode 100644 include/avb/avb_util.h create mode 100644 include/avb/avb_vbmeta_image.h create mode 100644 include/avb/avb_version.h create mode 100644 include/avb/libavb.h create mode 100644 include/avb/libavb_ab.h create mode 100644 include/avb_verify.h create mode 100644 lib/libavb/Makefile create mode 100644 lib/libavb/avb_chain_partition_descriptor.c create mode 100644 lib/libavb/avb_crypto.c create mode 100644 lib/libavb/avb_descriptor.c create mode 100644 lib/libavb/avb_footer.c create mode 100644 lib/libavb/avb_hash_descriptor.c create mode 100644 lib/libavb/avb_hashtree_descriptor.c create mode 100644 lib/libavb/avb_kernel_cmdline_descriptor.c create mode 100644 lib/libavb/avb_property_descriptor.c create mode 100644 lib/libavb/avb_rsa.c create mode 100644 lib/libavb/avb_sha256.c create mode 100644 lib/libavb/avb_sha512.c create mode 100644 lib/libavb/avb_slot_verify.c create mode 100644 lib/libavb/avb_sysdeps_posix.c create mode 100644 lib/libavb/avb_util.c create mode 100644 lib/libavb/avb_vbmeta_image.c create mode 100644 lib/libavb/avb_version.c create mode 100644 lib/libavb_ab/Makefile create mode 100644 lib/libavb_ab/avb_ab_flow.c create mode 100644 test/py/tests/test_avb.py
cover Initial integration of AVB2.0
In reply to Kever YangHi Kever,
libavb and libavb_ab are different things, and we split them for a
reason. Adding libavb is great, but you don't need to add libavb_ab as an A/B implementation. The boot_android command referenced by Igor doesn't use that as an A/B implementation, but uses the structs already defined in the Boot Control Block (BCB) and the android bootloader flow. I would recommend to include the libavb only.
Igor,
What changes did you need to do to libavb to import it to U-Boot? The idea with libavb is that it should be easy to integrate into your bootloader without changes; and therefore easy to update and integrate new patches when we release new versions of libavb. We would like to avoid diverting from it to reduce the maintenance cost.
Best regards,
Alex
Le jeu. 26 avr. 2018 à 05:05, Kever Yang <[email protected]> a écrit :
Quoted 155 lines
Hi Igor,
It's great to see the patch set to support AVB2.0, the upstream
libavb(from aosp) combine the AVB with A/B which I think should be two separate feature, are you going to split them?BTW, do you have plan to update
boot_androidcmd to support avb?
the command is too weak for use now.
And any plan to add opptee_client/smcc to talk to OPTEE/ATF?Thanks,
- KeverQuoted 4 lines · Igor Opaniuk
This series of patches introduces support of Android Verified Boot 2.0, which provides integrity checking of Android partitions on MMC.
It integrates libavb/libavb_ab into the U-boot, provides implementation
of
Quoted 1 line
AvbOps, subset of
avbcommands to run verification chain (and fordebugging
Quoted 1 line
purposes), and it enables AVB2.0 verification on AM57xx HS SoC by
default.
Quoted 7 lines
Currently, there is still no support for verification of A/B boot slots and no rollback protection (for storing rollback indexes there are plans to use eMMC RPMB)
Libavb/libavb_ab will be deviated from AOSP upstream in the future, that's why minimal amount of changes were introduced into the lib
sources,
Quoted 3 lines
so checkpatch may fail.
For additional details check [1] AVB 2.0 README and doc/README.avb2,
which
Quoted 3 lines
is a part of this patchset.
[1]
https://android.googlesource.com/platform/external/avb/+/master/README.md
Quoted 48 lines
Igor Opaniuk (8):
avb2.0: add Android Verified Boot 2.0 libraries avb2.0: integrate avb 2.0 into the build system avb2.0: implement AVB ops
cmd: avb2.0: avb command for performing verification avb2.0: add boot states and dm-verity support
am57xx_hs: avb2.0: add support of AVB 2.0 test/py: avb2.0: add tests for avb commands
doc: avb2.0: add README about AVB2.0 integrationcmd/Kconfig | 15 + cmd/Makefile | 3 + cmd/avb.c | 366 ++++++++ common/Makefile | 2 + common/avb_verify.c | 748 ++++++++++++++++ configs/am57xx_hs_evm_defconfig | 3 + doc/README.avb2 | 100 +++ include/avb/avb_ab_flow.h | 235 ++++++ include/avb/avb_ab_ops.h | 61 ++ include/avb/avb_chain_partition_descriptor.h | 54 ++ include/avb/avb_crypto.h | 147 ++++ include/avb/avb_descriptor.h | 113 +++ include/avb/avb_footer.h | 68 ++ include/avb/avb_hash_descriptor.h | 55 ++ include/avb/avb_hashtree_descriptor.h | 65 ++ include/avb/avb_kernel_cmdline_descriptor.h | 63 ++ include/avb/avb_ops.h | 196 +++++ include/avb/avb_property_descriptor.h | 89 ++ include/avb/avb_rsa.h | 55 ++ include/avb/avb_sha.h | 72 ++ include/avb/avb_slot_verify.h | 239 ++++++ include/avb/avb_sysdeps.h | 97 +++ include/avb/avb_util.h | 259 ++++++ include/avb/avb_vbmeta_image.h | 272 ++++++ include/avb/avb_version.h | 45 + include/avb/libavb.h | 32 + include/avb/libavb_ab.h | 22 + include/avb_verify.h | 97 +++ include/configs/am57xx_evm.h | 11 + include/environment/ti/boot.h | 15 + lib/Kconfig | 20 + lib/Makefile | 2 + lib/libavb/Makefile | 15 + lib/libavb/avb_chain_partition_descriptor.c | 46 + lib/libavb/avb_crypto.c | 355 ++++++++ lib/libavb/avb_descriptor.c | 142 ++++ lib/libavb/avb_footer.c | 36 +Quoted 8 lines
lib/libavb/avb_hash_descriptor.c | 43 + lib/libavb/avb_hashtree_descriptor.c | 51 ++ lib/libavb/avb_kernel_cmdline_descriptor.c | 40 + lib/libavb/avb_property_descriptor.c | 167 ++++ lib/libavb/avb_rsa.c | 277 ++++++ lib/libavb/avb_sha256.c | 364 ++++++++ lib/libavb/avb_sha512.c | 362 ++++++++ lib/libavb/avb_slot_verify.c | 1169++++++++++++++++++++++++++
Quoted 44 lines
lib/libavb/avb_sysdeps_posix.c | 57 ++ lib/libavb/avb_util.c | 385 +++++++++ lib/libavb/avb_vbmeta_image.c | 290 +++++++ lib/libavb/avb_version.c | 16 + lib/libavb_ab/Makefile | 9 + lib/libavb_ab/avb_ab_flow.c | 502 +++++++++++ test/py/tests/test_avb.py | 111 +++ 52 files changed, 8058 insertions(+) create mode 100644 cmd/avb.c create mode 100644 common/avb_verify.c create mode 100644 doc/README.avb2 create mode 100644 include/avb/avb_ab_flow.h create mode 100644 include/avb/avb_ab_ops.h create mode 100644 include/avb/avb_chain_partition_descriptor.h create mode 100644 include/avb/avb_crypto.h create mode 100644 include/avb/avb_descriptor.h create mode 100644 include/avb/avb_footer.h create mode 100644 include/avb/avb_hash_descriptor.h create mode 100644 include/avb/avb_hashtree_descriptor.h create mode 100644 include/avb/avb_kernel_cmdline_descriptor.h create mode 100644 include/avb/avb_ops.h create mode 100644 include/avb/avb_property_descriptor.h create mode 100644 include/avb/avb_rsa.h create mode 100644 include/avb/avb_sha.h create mode 100644 include/avb/avb_slot_verify.h create mode 100644 include/avb/avb_sysdeps.h create mode 100644 include/avb/avb_util.h create mode 100644 include/avb/avb_vbmeta_image.h create mode 100644 include/avb/avb_version.h create mode 100644 include/avb/libavb.h create mode 100644 include/avb/libavb_ab.h create mode 100644 include/avb_verify.h create mode 100644 lib/libavb/Makefile create mode 100644 lib/libavb/avb_chain_partition_descriptor.c create mode 100644 lib/libavb/avb_crypto.c create mode 100644 lib/libavb/avb_descriptor.c create mode 100644 lib/libavb/avb_footer.c create mode 100644 lib/libavb/avb_hash_descriptor.c create mode 100644 lib/libavb/avb_hashtree_descriptor.c create mode 100644 lib/libavb/avb_kernel_cmdline_descriptor.c create mode 100644 lib/libavb/avb_property_descriptor.c create mode 100644 lib/libavb/avb_rsa.c create mode 100644 lib/libavb/avb_sha256.c create mode 100644 lib/libavb/avb_sha512.cQuoted 9 lines
create mode 100644 lib/libavb/avb_slot_verify.c create mode 100644 lib/libavb/avb_sysdeps_posix.c create mode 100644 lib/libavb/avb_util.c create mode 100644 lib/libavb/avb_vbmeta_image.c create mode 100644 lib/libavb/avb_version.c create mode 100644 lib/libavb_ab/Makefile create mode 100644 lib/libavb_ab/avb_ab_flow.c create mode 100644 test/py/tests/test_avb.py_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot
cover Initial integration of AVB2.0
Hi Alex,
I've replaced licence texts in source file headers to SPDX short identifiers (suggestion from Tom Rini).
As far as I know that was the only one major change I introduced to libavb/libavb_ab.
I also did remove crc32() implementation and used existing in U-boot because of licence ambiguity,
frankly I wasn't sure if it was GPL-2.0 compatible (
https://android.googlesource.com/platform/external/avb/+/master/libavb/avb_crc32.c).
Regarding libavb_ab, I guess I can exclude it for now, as there is no any functionality implemented for A/B
slots support in this patch-set. And, btw, I've noticed the note in the latest README.md for AVB2.0
on googlesource "This code is DEPRECATED and you must define AVB_AB_I_UNDERSTAND_LIBAVB_AB_IS_DEPRECATED to use it. The code will be removed Jun 1 2018.".
Does it mean that a/b stuff will be included in libavb instead of seperate libavb_av lib?
Thanks!
Regards,
Igor
Quoted 176 lines · Alex Deymo
Hi Kever,
libavb andlibavb_abare different things, and we split them for a reason.
Adding libavb is great, but you don't need to addlibavb_abas an A/B implementation. Theboot_androidcommand referenced by Igor doesn't use that as an A/B implementation, but uses the structs already defined in the Boot Control Block (BCB) and the android bootloader flow. I would recommend to include the libavb only.Igor,
What changes did you need to do to libavb to import it to U-Boot? The idea with libavb is that it should be easy to integrate into your bootloader without changes; and therefore easy to update and integrate new patches when we release new versions of libavb. We would like to avoid diverting from it to reduce the maintenance cost.Best regards,
AlexLe jeu. 26 avr. 2018 à 05:05, Kever Yang <[email protected]> a écrit :
Quoted 155 lines
Hi Igor,
It's great to see the patch set to support AVB2.0, the upstream
libavb(from aosp) combine the AVB with A/B which I think should be two separate feature, are you going to split them?BTW, do you have plan to update
boot_androidcmd to support avb?
the command is too weak for use now.
And any plan to add opptee_client/smcc to talk to OPTEE/ATF?Thanks,
- KeverQuoted 126 lines · Igor Opaniuk
This series of patches introduces support of Android Verified Boot 2.0, which provides integrity checking of Android partitions on MMC.
It integrates libavb/libavb_ab into the U-boot, provides implementation of
AvbOps, subset ofavbcommands to run verification chain (and for debugging
purposes), and it enables AVB2.0 verification on AM57xx HS SoC by default.Currently, there is still no support for verification of A/B boot slots and no rollback protection (for storing rollback indexes there are plans to use eMMC RPMB)
Libavb/libavb_ab will be deviated from AOSP upstream in the future, that's why minimal amount of changes were introduced into the lib sources,
so checkpatch may fail.For additional details check [1] AVB 2.0 README and doc/README.avb2, which
is a part of this patchset.[1]
https://android.googlesource.com/platform/external/avb/+/master/README.mdIgor Opaniuk (8):
avb2.0: add Android Verified Boot 2.0 libraries avb2.0: integrate avb 2.0 into the build system avb2.0: implement AVB ops
cmd: avb2.0: avb command for performing verification avb2.0: add boot states and dm-verity support
am57xx_hs: avb2.0: add support of AVB 2.0 test/py: avb2.0: add tests for avb commands
doc: avb2.0: add README about AVB2.0 integrationcmd/Kconfig | 15 + cmd/Makefile | 3 + cmd/avb.c | 366 ++++++++ common/Makefile | 2 + common/avb_verify.c | 748 ++++++++++++++++ configs/am57xx_hs_evm_defconfig | 3 + doc/README.avb2 | 100 +++ include/avb/avb_ab_flow.h | 235 ++++++ include/avb/avb_ab_ops.h | 61 ++ include/avb/avb_chain_partition_descriptor.h | 54 ++ include/avb/avb_crypto.h | 147 ++++ include/avb/avb_descriptor.h | 113 +++ include/avb/avb_footer.h | 68 ++ include/avb/avb_hash_descriptor.h | 55 ++ include/avb/avb_hashtree_descriptor.h | 65 ++ include/avb/avb_kernel_cmdline_descriptor.h | 63 ++ include/avb/avb_ops.h | 196 +++++ include/avb/avb_property_descriptor.h | 89 ++ include/avb/avb_rsa.h | 55 ++ include/avb/avb_sha.h | 72 ++ include/avb/avb_slot_verify.h | 239 ++++++ include/avb/avb_sysdeps.h | 97 +++ include/avb/avb_util.h | 259 ++++++ include/avb/avb_vbmeta_image.h | 272 ++++++ include/avb/avb_version.h | 45 + include/avb/libavb.h | 32 + include/avb/libavb_ab.h | 22 + include/avb_verify.h | 97 +++ include/configs/am57xx_evm.h | 11 + include/environment/ti/boot.h | 15 + lib/Kconfig | 20 + lib/Makefile | 2 + lib/libavb/Makefile | 15 + lib/libavb/avb_chain_partition_descriptor.c | 46 + lib/libavb/avb_crypto.c | 355 ++++++++ lib/libavb/avb_descriptor.c | 142 ++++ lib/libavb/avb_footer.c | 36 + lib/libavb/avb_hash_descriptor.c | 43 + lib/libavb/avb_hashtree_descriptor.c | 51 ++ lib/libavb/avb_kernel_cmdline_descriptor.c | 40 + lib/libavb/avb_property_descriptor.c | 167 ++++ lib/libavb/avb_rsa.c | 277 ++++++ lib/libavb/avb_sha256.c | 364 ++++++++ lib/libavb/avb_sha512.c | 362 ++++++++ lib/libavb/avb_slot_verify.c | 1169 ++++++++++++++++++++++++++ lib/libavb/avb_sysdeps_posix.c | 57 ++ lib/libavb/avb_util.c | 385 +++++++++ lib/libavb/avb_vbmeta_image.c | 290 +++++++ lib/libavb/avb_version.c | 16 + lib/libavb_ab/Makefile | 9 + lib/libavb_ab/avb_ab_flow.c | 502 +++++++++++ test/py/tests/test_avb.py | 111 +++ 52 files changed, 8058 insertions(+) create mode 100644 cmd/avb.c create mode 100644 common/avb_verify.c create mode 100644 doc/README.avb2 create mode 100644 include/avb/avb_ab_flow.h create mode 100644 include/avb/avb_ab_ops.h create mode 100644 include/avb/avb_chain_partition_descriptor.h create mode 100644 include/avb/avb_crypto.h create mode 100644 include/avb/avb_descriptor.h create mode 100644 include/avb/avb_footer.h create mode 100644 include/avb/avb_hash_descriptor.h create mode 100644 include/avb/avb_hashtree_descriptor.h create mode 100644 include/avb/avb_kernel_cmdline_descriptor.h create mode 100644 include/avb/avb_ops.h create mode 100644 include/avb/avb_property_descriptor.h create mode 100644 include/avb/avb_rsa.h create mode 100644 include/avb/avb_sha.h create mode 100644 include/avb/avb_slot_verify.h create mode 100644 include/avb/avb_sysdeps.h create mode 100644 include/avb/avb_util.h create mode 100644 include/avb/avb_vbmeta_image.h create mode 100644 include/avb/avb_version.h create mode 100644 include/avb/libavb.h create mode 100644 include/avb/libavb_ab.h create mode 100644 include/avb_verify.h create mode 100644 lib/libavb/Makefile create mode 100644 lib/libavb/avb_chain_partition_descriptor.c create mode 100644 lib/libavb/avb_crypto.c create mode 100644 lib/libavb/avb_descriptor.c create mode 100644 lib/libavb/avb_footer.c create mode 100644 lib/libavb/avb_hash_descriptor.c create mode 100644 lib/libavb/avb_hashtree_descriptor.c create mode 100644 lib/libavb/avb_kernel_cmdline_descriptor.c create mode 100644 lib/libavb/avb_property_descriptor.c create mode 100644 lib/libavb/avb_rsa.c create mode 100644 lib/libavb/avb_sha256.c create mode 100644 lib/libavb/avb_sha512.cQuoted 9 lines
create mode 100644 lib/libavb/avb_slot_verify.c create mode 100644 lib/libavb/avb_sysdeps_posix.c create mode 100644 lib/libavb/avb_util.c create mode 100644 lib/libavb/avb_vbmeta_image.c create mode 100644 lib/libavb/avb_version.c create mode 100644 lib/libavb_ab/Makefile create mode 100644 lib/libavb_ab/avb_ab_flow.c create mode 100644 test/py/tests/test_avb.py_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot
Signature · 2 lines
Regards, Igor Opaniuk
cover Initial integration of AVB2.0
Hi Igor,
The "libavb_ab" is an implementation of A/B flow, which you could use, but you are not required to use in your A/B bootloader to make an Android device. This ended up not being used in general, for different reasons. The integration of the A/B error modes into an existing device depended on other factors about your device, and it is closer to the rest of the bootloader than it is to libavb. You can read more details about the reasons here: https://android.googlesource.com/platform/external/avb/+/37f5946d0e1159273eff61dd8041377fedbf55a9
Anyway, once you have selected a slot to boot from (using your own A/B logic) or if your device has only one slot, the verification process is done by libavb. There's the feedback loop from libavb to your A/B logic to tell you that the slot is certainly broken, but it isn't the only feedback your A/B logic is supposed to get. If the slot boots past libavb but the kernel crashes and reboots later on after a broken update, the counters in the bootloader's A/B logic shold also figure out that the slot is broken; but there's no A/B flow logic in libavb itself. libavb is just about verifying your boot end-to-end handling all the different ways you can sign these images.
There's an extension to libavb, which is used in Android Things (libavb_atx). That one is useful to include if you expect to boot Android Things images (in Android Things you have multiple different products using the exact same hardware SoM, which are not interchangeable).
Anyway, thanks for doing this. I think maybe a quick shell script to update libavb (automate the changes/renames you did) would be good, but I don't think is needed now.
Regards,
Alex.
2018-04-27 11:53 GMT+02:00 Igor Opaniuk <[email protected]>:
Quoted 26 lines
Hi Alex,
I've replaced licence texts in source file headers to SPDX short identifiers (suggestion from Tom Rini).
As far as I know that was the only one major change I introduced to libavb/libavb_ab.
I also did removecrc32()implementation and used existing in U-boot because of licence ambiguity,
frankly I wasn't sure if it was GPL-2.0 compatible (
https://android.googlesource.com/platform/external/avb/+/master/libavb/avb_crc32.c).Regarding
libavb_ab, I guess I can exclude it for now, as there is no any functionality implemented for A/B
slots support in this patch-set. And, btw, I've noticed the note in the latest README.md for AVB2.0
on googlesource "This code is DEPRECATED and you must defineAVB_AB_I_UNDERSTAND_LIBAVB_AB_IS_DEPRECATEDto use it. The code will be removed Jun 1 2018.".
Does it mean that a/b stuff will be included in libavb instead of seperatelibavb_avlib?Thanks!
Regards,
Igor
cover Initial integration of AVB2.0
In reply to Igor OpaniukHello Igor, Alex, Kever,
Having these patches in mainline would be great, as this would reduce the delta between our own and community U-boot trees. After having a quick look at this series, I have some questions/review findings.
These patches appear to be slightly older than what is available in [1].
More precisely, ignoring:
- change of license
- drop of avb_crc32.c
- updates in avb_sysdeps_posix.c
- 's^#include "^#include "avb/^'
The version of libavb imported in this patch series seems to match commit b60834f7a4a8 ("uefi: Set both androidboot.slot and androidboot.slot_suffix.") from [1].
FYI, there are 12 more non-merge commits in the avb repository [2]. Is there a strong reason not to include them?
I am not an expert in AVB, but IMHO, as suggested by Alex, we shouldn't assume that the in-tree libavb will diverge from the vanilla one. IMHO a cleaner workflow would be to contribute any bugfixes to the original repository and update the U-boot libavb from time to time, similar to how it's done, as example, for dtc in kernel [3]. Or maybe you see some obstacles to achieve this in practice?
Assuming that:
1) libavb will undergo regular updates from its original repository.
2) most of libavb headers are not designed to be included from non-libavb code, throwing below:
#error "Never include this file directly, include libavb.h instead."
I wonder if it would be possible to keep the internal libavb headers in lib/libavb (similar to how it's done by NXP in [4]), since this would allow not rewriting the original include paths for such headers in every *.c file and hence minimize the delta between in-tree vs out-of-tree code, as well as potentially speed up the update process (and/or simplify any update script which will take care of it, as also mentioned by Alex).
My final question is what's your opinion about the NXP-specific libavb wrapper implementation found at lib/avb/fsl/ in [5]/[6] which seems to rely on libavb and libavb_ab. Do you see it as a good model to be followed by other platforms (both from point of view of contents and placement in the tree)? I am asking because we are in the middle of some decision-making for similar/alternative implementation on a different SoC, so your feedback will be extremely helpful and greatly appreciated.
Thank you!
Best regards,
Eugeniu.
[1] https://android.googlesource.com/platform/external/avb/+/master
[2] Postt-b60834f7a4a8 libavb commits in [1]
$> git log --oneline --no-merges b60834f7a4a8..avb_upstream/master -- libavb 30dd8e5a1757 libavb: Add new routine to calculate a digest of all vbmeta images. fd0ba0d49101 Implement support for on-device persistent digests. 97740e537ad1 Split kernel cmdline code in separate file. fcadbf1d1a71 Support (boot) partition preloading.061e33b39e27 Add avb_div_by_10() sysdep operation.36e5c43f58d2 Fix incorrect variable names in avb_replace fc2531374e30 Fix AvbAlgorithmType type-limits error047ecf7d2361 libavb: Avoid conflict with system-provided crc32 symbol. 0922bf8970fd Make it possible to disable verification.01ca9962bd0d libavb: Only load and verify hash partition if requested. 8221811c5da1 libavb: Allow specifying dm-verity error handling. 27a291fcc194 libavb: Load entire partition if |allow_verification_error| is true.
[3] The way in-tree kernel DTC is aligned to upsteam:
$> git log --oneline --no-merges -i --grep "update.*upstream" -- scripts/dtc 9130ba884640 scripts/dtc: Update to upstream version v1.4.6-9-gaadd0b65c987 e45fe7f788dd scripts/dtc: Update to upstream version v1.4.5-6-gc1e55a5513e9 4201d057ea91 scripts/dtc: Update to upstream version v1.4.5-3-gb1a60033c110 89d123106a97 scripts/dtc: Update to upstream version v1.4.4-8-g756ffc4f52f6
[4] http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/commit/?h=60e14a6a07c5
[5] http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/tree/lib/avb/fsl?h=imx_v2015.04_brillo
[6] http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/tree/lib/avb/fsl?h=imx_v2017.03_4.9.11_1.0.0_ga
cover Initial integration of AVB2.0
Quoted 11 lines · Eugeniu Rosca
Hello Igor, Alex, Kever,
I wonder if it would be possible to keep the internal libavb headers in lib/libavb (similar to how it's done by NXP in [4]), since this would allow not rewriting the original include paths for such headers in every *.c file and hence minimize the delta between in-tree vs out-of-tree code, as well as potentially speed up the update process (and/or simplify any update script which will take care of it, as also mentioned by Alex).
[4] http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/commit/?h=60e14a6a07c5
Here is what I mean.
Three lzma headers are exposed to internal users/consumers:
$ git grep '"../../lib/' ---<-snip->--- include/lzma/LzmaDec.h:#include "../../lib/lzma/LzmaDec.h" include/lzma/LzmaTools.h:#include "../../lib/lzma/LzmaTools.h" include/lzma/LzmaTypes.h:#include "../../lib/lzma/Types.h" ---<-snip->---
A few places where lzma headers are used:
$ git grep 'include <lzma/Lzma' cmd/lzmadec.c:#include <lzma/LzmaTools.h> common/bootm.c:#include <lzma/LzmaTypes.h> common/bootm.c:#include <lzma/LzmaDec.h> common/bootm.c:#include <lzma/LzmaTools.h> lib/lzma/LzmaTools.h:#include <lzma/LzmaTypes.h> test/compression.c:#include <lzma/LzmaTypes.h> test/compression.c:#include <lzma/LzmaDec.h> test/compression.c:#include <lzma/LzmaTools.h>
For libavb this would translate to:
$ cat include/avb/libavb.h ---<-snip->--- #include "../../lib/libavb/avb_chain_partition_descriptor.h" #include "../../lib/libavb/avb_crypto.h" #include "../../lib/libavb/avb_descriptor.h" #include "../../lib/libavb/avb_footer.h" #include "../../lib/libavb/avb_hash_descriptor.h" ---<-snip->---
And with that, various consumers (mainly libavb_avb?) would do:
#include <avb/libavb.h>
As said, this would make integration of new libavb versions much easier. Would appreciate your thoughts.
Best regards,
Eugeniu.
cover Initial integration of AVB2.0
Hi Eugeniu,
You're totally right regarding avb internal headers, they all should remain in lib/libavb.
v2 patchset (planning to send it by the end of this week) will include these changes you're talking about (+ will include libavb updates from [1]).
Quoted 8 lines
My final question is what's your opinion about the NXP-specific libavb wrapper implementation found at
lib/avb/fsl/in [5]/[6] which seems to rely on libavb andlibavb_ab. Do you see it as a good model to be followed by other platforms (both from point of view of contents and placement in the tree)? I am asking because we are in the middle of some decision-making for similar/alternative implementation on a different SoC, so your feedback will be extremely helpful and greatly appreciated.
I've taken a quick look at patches from [2], and noticed a few issues (IMHO):
1) It includes custom implementation of RPMB operations, although generic RPMB functionality already exists in the U-boot mainline (check drivers/mmc/rpmb.c)
2) It introduces a brand-new "boota" command for booting Android, although existing bootm does already support Android boot image parsing and booting.
3) It doesn't have any dm-verify enforcement policies in case
if the bootloader is in the "locked" state (at least, I didn't manage to grep it)
4) There are a bunch of platform-specific code introduced to fastboot driver, and it's used as a base for working with GPT
in avb ops (sounds strange, but this is what I see here), although mainline U-boot does have API for this purposes.
Obviously, the root cause of all these issues is a big divergence from the U-boot mainline codebase.
Thanks!
Regards,
Igor
[1] https://android.googlesource.com/platform/external/avb/+/master
[2] http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/tree/lib/avb/fsl?h=imx_v2017.03_4.9.11_1.0.0_ga
Quoted 54 lines · Eugeniu Rosca
Quoted 11 lines · Eugeniu Rosca
Hello Igor, Alex, Kever,
I wonder if it would be possible to keep the internal libavb headers in lib/libavb (similar to how it's done by NXP in [4]), since this would allow not rewriting the original include paths for such headers in every *.c file and hence minimize the delta between in-tree vs out-of-tree code, as well as potentially speed up the update process (and/or simplify any update script which will take care of it, as also mentioned by Alex).
[4] http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/commit/?h=60e14a6a07c5
Here is what I mean.
Three lzma headers are exposed to internal users/consumers:$ git grep '"../../lib/' ---<-snip->--- include/lzma/LzmaDec.h:#include "../../lib/lzma/LzmaDec.h" include/lzma/LzmaTools.h:#include "../../lib/lzma/LzmaTools.h" include/lzma/LzmaTypes.h:#include "../../lib/lzma/Types.h" ---<-snip->---A few places where lzma headers are used:
$ git grep 'include <lzma/Lzma' cmd/lzmadec.c:#include <lzma/LzmaTools.h> common/bootm.c:#include <lzma/LzmaTypes.h> common/bootm.c:#include <lzma/LzmaDec.h> common/bootm.c:#include <lzma/LzmaTools.h> lib/lzma/LzmaTools.h:#include <lzma/LzmaTypes.h> test/compression.c:#include <lzma/LzmaTypes.h> test/compression.c:#include <lzma/LzmaDec.h> test/compression.c:#include <lzma/LzmaTools.h>For libavb this would translate to:
$ cat include/avb/libavb.h ---<-snip->--- #include "../../lib/libavb/avb_chain_partition_descriptor.h" #include "../../lib/libavb/avb_crypto.h" #include "../../lib/libavb/avb_descriptor.h" #include "../../lib/libavb/avb_footer.h" #include "../../lib/libavb/avb_hash_descriptor.h" ---<-snip->---And with that, various consumers (mainly
libavb_avb?) would do:
#include <avb/libavb.h>As said, this would make integration of new libavb versions much easier. Would appreciate your thoughts.
Best regards,
Eugeniu.
Signature · 2 lines
Regards, Igor Opaniuk
cover Initial integration of AVB2.0
Hi Igor,
Quoted 7 lines · Igor Opaniuk
Hi Eugeniu,
You're totally right regarding avb internal headers, they all should remain in lib/libavb.
v2 patchset (planning to send it by the end of this week) will include these changes you're talking about (+ will include libavb updates from [1]).
Good to hear that!
Quoted 15 lines
I've taken a quick look at patches from [2], and noticed a few issues (IMHO):
1) It includes custom implementation of RPMB operations, although generic RPMB functionality already exists in the U-boot mainline (checkdrivers/mmc/rpmb.c)
2) It introduces a brand-new "boota" command for booting Android, although existing bootm does already support Android boot image parsing and booting.
3) It doesn't have any dm-verify enforcement policies in case
if the bootloader is in the "locked" state (at least, I didn't manage to grep it)
4) There are a bunch of platform-specific code introduced to fastboot driver, and it's used as a base for working with GPT
in avb ops (sounds strange, but this is what I see here), although mainline U-boot does have API for this purposes.
Thanks for the detailed reply. I am looking forward for a cleaner and better partitioned porting of libavb/libavb_ab to the main tree. Your effort is very appreciated!
Quoted 5 lines
Regards,
Igor[1] https://android.googlesource.com/platform/external/avb/+/master
[2] http://git.freescale.com/git/cgit.cgi/imx/uboot-imx.git/tree/lib/avb/fsl?h=imx_v2017.03_4.9.11_1.0.0_ga
Best regards,
Eugeniu.