Commit Graph

44 Commits

Author SHA1 Message Date
faqiang.zhu 0d6d880779 MA-14629 fix build warnings for varialbe initialization and type cast
initialize potential uninitialized variable with the type of"char*" to
be NULL in AVB. That "hashtree_error_mode" in code is manually specified
with a known value, the cases listed cover all potential value of
"hashtree_error_mode"

explicitly do a type cast for memcpy parameters.

Change-Id: Ie5d234422a273d6dab75585bd0d8eb81583707ca
Signed-off-by: faqiang.zhu <faqiang.zhu@nxp.com>
2019-04-18 18:49:33 +08:00
Luo Ji dfdf60c69c MA-14374 [coverity] Fix coverity issues in fsl_avbkey.c
Fix coverity issues as:
  CID 5899697: Dereference before null check (REVERSE_INULL)
  CID 3616594: Unchecked return value (CHECKED_RETURN)
  CID 3616598: Resource leak (RESOURCE_LEAK)
  CID 3616591: Resource leak (RESOURCE_LEAK)

Test: Coverity scan pass.

Change-Id: I70abb41c3cd825c6eec43dc7e5baec716ae46680
Signed-off-by: Luo Ji <ji.luo@nxp.com>
2019-03-14 17:24:19 +08:00
Ji Luo e0343ea466 MA-14318-1 Support dual bootloader for xen
Trusty is not supported for xen so we don't need to check
the keyslot package or rollback index in spl. Reassign the
dram address for spl and u-boot to avoid conflicts.

Support serial init functions to enable debug console
in spl when xen is running.

Test: Boot and A/B slot switch on imx8qm_mek.

Change-Id: If6829252f1ec2e32255f951715c8747181951fd0
Signed-off-by: Ji Luo <ji.luo@nxp.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
2019-03-12 17:33:39 +08:00
Luo Ji 40f95bfc01 MA-14280 [coverity] Fix resource leak in libavb
Fix resource leak in libavb, coverity issue:
  CID 5899691: Resource leak (RESOURCE_LEAK) leaked_storage: Variable
  hash_out going out of scope leaks the storage it points to.

  CID 5899689: Resource leak (RESOURCE_LEAK) leaked_storage: Variable
  hash_buf going out of scope leaks the storage it points to.

  CID 5899688: Uninitialized pointer read (UNINIT) uninit_use: Using
  uninitialized value digest.

  CID 5899692: Structurally dead code (UNREACHABLE) unreachable: This
  code cannot be reached: goto out;

Test: Coverity scan pass.

Change-Id: If8e26fdd383c32a9160775006621830b42c0f07e
Signed-off-by: Luo Ji <ji.luo@nxp.com>
2019-03-12 14:50:52 +08:00
Ji Luo 55dbdd9d56 MA-14121 Only free hash buffer for Android Auto
The hash buffer is allocated on stack if we don't use
CAAM to accelerate the hash calculation, don't free
the hash buffer in such case.

Test: Boot ok on imx8qm.

Change-Id: I3b3dcc0e8359848b4f9c58c802d51f0a76931e5e
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2019-02-22 10:14:31 +08:00
Ji Luo 3a62d022b9 MA-14118 Avoid slot switch if retry count exhaust in spl
The A/B slot is chosen at spl stage and should be kept up to
u-boot stage. Decrease slot retry count will cause slot switch
when the slot only has one chance left.
Set the 'bootloader_verified' flag when current slot is running the last
chance at spl, u-boot will treat the slot as bootable if the
'reserved' flag is set even the retry count exhausted.

Test: Slot not switch during 7 times reboot try.

Change-Id: I7ae84b2ce683300a1bb332606cd58e48483214ea
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2019-02-22 10:13:28 +08:00
Ji Luo 7eebccd173 MA-14043 Fix avb verify fail in adb reboot test
During AVB verify, CAAM will be invoked to calculate the hash
of boot.img and dtbo.img. ALLOC_CACHE_ALIGN_BUFFER() supports
allocate cache aligned buffer on *stack*, which may cause
'dirty' dcache data be flushed to dram after CAAM operations
complete.

Use memalign() to allocate cache aligned buffer on *heap* to
fix this issue.

Test: 1200 times reboot test on imx8qm and 2300 times reboot
      on imx8qxp.

Change-Id: I8f86248df318093d44a46dcab76306377898766e
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2019-02-22 10:13:16 +08:00
Ji Luo fd421f74db MA-14051 Enable trusty for imx8q xen
Open configs to add trusty os support for imx8q xen
build. The rpmb keyslot package must be checked and
copied to secure memory before trusty os boot.

Change-Id: I66201783fa8439f2685377c10f257f064057dcfa
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2019-01-31 12:41:00 +08:00
Ji Luo 71562aae3b MA-13938 [Android] imx8q: Support dual bootloader feature
Support dual bootloader feature for imx8q which uses the
container format. Move the A/B slot select and verify to
SPL stage, the bootloader rollback index will be stored
at the last 8K bytes of eMMC rpmb storage.

Test: Boot and rbindex verify pass on imx8q.

Change-Id: I0a48210f65984a083037a0cd3f9558951029ed7d
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2019-01-18 12:07:21 +08:00
Ji Luo e05d44f550 MA-13832 [Trusty] Support random rpmb key set
Sometimes we need to set random rpmb key which is invisible
except for the device.
Generate the random key with hwcrypto interface and support
fastboot command "fastboot oem set-rpmb-random-key" to set it.

Test: build and boot on imx8q.

Change-Id: I44e1b6b091366d8ffceb1159fc65c17610ce5243
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-12-24 09:13:38 +08:00
Ji Luo fc734f07d7 MA-13759-1 imx8mm: Enable trusty support
Open configs to enable trusty for imx8mm_evk and also
add new config imx8mm_evk_android_trusty_defconfig based
on imx8mm_evk_android_defconfig.

Test: Trusty starts ok.

Change-Id: Iaea90de21f886ed23082a5e8e8d2fa7fb139a9cb
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-12-12 21:02:10 +08:00
Ji Luo 57f07af56b MA-13682 Don't include hard-code public key for Auto
This will reduce some image size for Android Auto.

Test: build and boot on imx8qm_mek.

Change-Id: I023801a542f83398126d5af23c0a1eb2080c5063
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-12-05 10:24:10 +08:00
Ji Luo 2d831d95f7 MA-13629 [Trusty] Add commands to set vbmeta public key
Add commands to write/read vbmeta public key to/from secure
storage. The vbmeta public key can only be set once.
Comands to set the public key:
  fastboot stage <path-to-your-public-key>
  fastboot oem set-public-key

Test: build and boot on imx8qxp_mek.

Change-Id: Id3ad4aa5aacef4fc8443f6a2d6ccb931310970ca
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-12-04 09:53:12 +08:00
Ji Luo d7c768a690 MA-13628 [Auto] Read/Write rollback index from rpmb
Secure storage is ready in trusty so we should read/write the rollback
index from rpmb.
But for borads without rpmb key, read/write the rpmb will fail and will
block the following avb verify process. In this case, check if the rpmb
key has been set and always return AVB_IO_RESULT_OK for the boards without
rpmb key.

Test: build and boot pass on imx8qm_mek.

Change-Id: I10c438e56d049ae97ebedfc446c8202642630d8b
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-12-04 09:53:12 +08:00
Luo Ji f042c8f7ca MA-13487 Refine fsl avb functions
Too many macros are used in fsl_avbkey.c and
make it difficult to maintain.
This patch made some refine by:
  1. Move all avb/atx operations to fsl_avb.c.
  2. Refine the functions logic.
  3. Drop some unsupported conditions/functions.

Test: build and boot on
      imx8qm_mek/imx8mq_evk/imx6qp_sabresd/imx7d_pico/imx8m_aiy.

Change-Id: I5c99732acfc47d53cdf188d69223983777e577f4
Signed-off-by: Luo Ji <ji.luo@nxp.com>
2018-11-21 20:56:03 +08:00
Ji Luo e48ceaae24 [iot] Update rollback index when slot has been marked as successful
The rollback index should be updated when avb verify pass
and the slot has been marked as successful, update the
rollback index also for those enabled dual bootloader
feature.
This commit also fix some configs condition issue so
read/write rollback index with trusty will work.

Test: rollback index updated successfully on
      imx7d_pico and AIY.

Change-Id: I2344d6462249d8d88f0622d331cdeffc7e12f885
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-11-12 09:18:38 +08:00
Ji Luo b57739cac7 [iot] Support fastboot variable 'at-vboot-state'
Add support for fastboot variable 'at-vboot-state', it's composed
by 6 sub-variable: 'bootloader-locked', 'bootloader-min-versions',
'avb-perm-attr-set', 'avb-locked', 'avb-unlock-disabled' and
'avb-min-versions'.

Test: All 'at-vboot-state' variables are returned
      correctly on imx7d_pico and AIY.

Change-Id: Ibb855cbcc7c41657af62dafb98a96c4dfb96ef22
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-11-12 09:18:37 +08:00
Ji Luo aebefa8046 [iot] Support command 'oem at-disable-unlock-vboot'
Device will be locked permanently after disabling the unlcok vboot, store
the disable unlock vboot status into fuse. Since the fuse write operation
is irreversible so config 'CONFIG_AVB_FUSE' is disabled by default, user
need to add this config manually and run this command again.

Test: Disable unlock vboot bit is set after enabling "CONFIG_AVB_FUSE",
      device was locked permanently after running this command. This is
      verified on both imx7d_pico and AIY.

Change-Id: Iad8991a238763b1d662e33cba65f0b9eb44e97ef
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-11-12 09:18:37 +08:00
Ji Luo c14e9d4e27 [iot] Support lock vboot for Android Things
Supoort "fastboot oem at-lock-vboot" command for Android
Things, this command can only be called after perm-attr
have been fused.

Test: build and boot ok on imx7d_pico and AIY.

Change-Id: Ifcfeb2a38d88c5d12b46a1d9ea61b182ae2e7bcb
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-11-12 09:18:37 +08:00
Ji Luo d4a0dbd9a4 [iot] Support authenticated unlock
Add fastboot commands "fastboot oem at-get-vboot-unlock-challenge"
and "fastboot oem at-unlock-vboot" to support the authenticated
unlock feature for Android Things devices. Use software random
numbers generator to generate the 16 bytes random challenge, it
should be replaced with hardware encrypted random generator when
the TEE part is ready.

Test: Generate unlock challenge by:
        ./avbtool make_atx_unlock_credential
        --output=atx_unlock_credential.bin
        --intermediate_key_certificate=atx_pik_certificate.bin
        --unlock_key_certificate=atx_puk_certificate.bin
        --challenge=my_generated_challenge.bin
        --unlock_key=testkey_atx_puk.pem
      validated the unlock credential successfully on imx7d_pico
      and AIY.

Change-Id: I4b8cee87c9e96924169479b65020a081136681f6
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-11-12 09:18:37 +08:00
Haoran.Wang 9d5a4e04e2 [iot] Support ARM64 for Trusty OS
Align the callback to ARM64 environment for
Trusty OS.

TEST: AIY-3G & AIY-1G board's TIPC and AVB handler
      works.

Change-Id: I65806f56267a4a9278db04a462e351da181618cc
Signed-off-by: Haoran.Wang <elven.wang@nxp.com>
2018-11-12 09:18:36 +08:00
Luo Ji a37a72c84f MA-13357 [Trusty] Init hwcrypto service even rpmb key not set
RPMB storage proxy service will return fail if the rpmb key is not
correct, we should not return early here if the rpmb key has not
been set because we still need to initialize the hwcrypto service
to generate the rpmb key blob.
This commit also adds more hint when set the rpmb key.

Change-Id: I8ee59e4e277b545283d63b1070e671d508dbe0c2
Signed-off-by: Luo Ji <ji.luo@nxp.com>
2018-11-09 16:26:24 +08:00
Ji Luo 8cd43400c1 MA-13276 [Auto] Generate key blob when set the rpmb key
Generate the key blob and store it to the last block of boot1 partition
after setting the rpmb key. The key blob should be checked in spl and be
passed to Trusty OS if it's valid. If the key blob are damaged, RPMB
storage proxy service will return fail and should make the device hang.

Test: Build and boot ok on imx8qm/qxp.

Change-Id: Ia274cd72109ab6ae15920e91b2a2008e1f1e667c
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-11-02 20:50:09 -05:00
Ji Luo 86b33989f4 MA-13234 [Auto] Calculate SHA256 hash with CAAM
Use CAAM to accelerate SHA256 hash calculation in AVB,
this will reduce u-boot boot time, about 570ms can be
saved for imx8qxp.

Test: Build and boot ok for imx8qxp.

Change-Id: Idbbd781e5ad8e7d6cd8865190d7547c165d02190
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-11-02 20:50:09 -05:00
Ji Luo 557981f3ac MA-13048 [AUTO] Support program rpmb key with fastboot command
Add fastboot command "fastboot oem set-rpmb-key" to program the rpmb
key which should be staged first.
Usage:
      1. fastboot stage my-rpmb-key.bin
      2. fastboot oem set-rpmb-key

Test: rpmb key programed successfully on imx8qxp.

Change-Id: I95474a6367eb8ef0db16bb38680975b8c45b84f1
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-10-12 09:02:28 +08:00
Haoran.Wang cf2a6c19c8 MA-12699 Refine libavb for security features
Assign security features to specific config.
Now, use AVB_RPMB to enable RPMB stored rollback
index.

After this refine,
for imx6/7/8 Android release, use no AVB_RPMB,
for imx6/7 AndroidThings, use AVB_RPMB.

This patch also fix below build error for imx6/7:
vendor/nxp-opensource/uboot-imx/lib/avb/fsl/fsl_avbkey.c:711:2: error:
implicit declaration of function 'fsl_fuse_read'
[-Werror=implicit-function-declaration]
  if (fsl_fuse_read((uint32_t *)blob, RPMBKEY_FUSE_LENW,
RPMBKEY_FUSE_OFFSET)){

Change-Id: I734479f0627901f372f4b211b2e710bd103eb244
Signed-off-by: Haoran.Wang <elven.wang@nxp.com>
2018-09-13 14:51:00 +08:00
Haoran.Wang 502522c089 [iot] Support ARM64 for Trusty OS
Align the callback to ARM64 environment for
Trusty OS.

TEST: AIY-3G & AIY-1G board's TIPC and AVB handler
      works.

Change-Id: I65806f56267a4a9278db04a462e351da181618cb
Signed-off-by: Haoran.Wang <elven.wang@nxp.com>
2018-09-12 18:12:13 +08:00
Ji Luo b0e849fb2d MA-12421 Fix CAAM not work on Android Things
Blob buffer size is 48 bytes larger than the plain text buffer,
set correct range when flush the dcache. Also use cache aligned
buffer for the blob/plain_text to avoid failure in CAAM.

Change-Id: I3b377cfeb8f5bd9c76233827b2c9c7bd0d788c9b
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-08-22 17:36:43 +08:00
Ji Luo c2763113af MA-12358 Only dump partition table when it's needed
Sometimes we don't need to dump the whole partition table when
some partition can't be found, only dump the partition table
when it's needed.

Test: Build and boot ok.

Change-Id: I52407f0117b73f4b3656fe2435b08dfc7a349939
Signed-off-by: Ji Luo <ji.luo@nxp.com>
2018-08-21 09:44:34 +08:00
Luo Ji 80834f323b [iot] Set power-on write protection for boot1 partition
The RPMB keyslot is stored in last block of boot1 partition which
is easily erased or tampered, set power-on write protection for this
partition to prevent corruption.

Test: Power-on write protection works as expected on imx8m.

Change-Id: I7aadaed81ff81de680da9b20049f163a982e3d57
Signed-off-by: Luo Ji <ji.luo@nxp.com>
2018-08-21 09:44:33 +08:00
Luo Ji a3f5218d38 [iot] Support rollback index protection at SPL stage
Bootloader image take fit format and the rollback index for bootloader
is stored at the "rbindex" node, SPL will read the rollback index for
bootloader and compare it with the one stored in RPMB. The stored
rollback index will be updated only when current slot pass the verify
and has been marked as successful.

Bug:109947126
Test: Rollback index protection feature works fine for imx8m.

Change-Id: Ic12db4571287fbcb99e5eba0127e0b09378fa5d6
Signed-off-by: Luo Ji <ji.luo@nxp.com>
2018-08-21 09:44:32 +08:00
Luo Ji 0bfb34cbcc [iot] Verify single slot in boota for dual bootloader
A/B switch logic will be moved to SPL stage if dual bootloader
feature is enable, in such case, we just need to verify single
slot which is selected in SPL stage.

Test: verify and boot ok for imx8m.

Change-Id: Iafe0d2d4aea1c178551940808416eec4a3547259
Signed-off-by: Luo Ji <ji.luo@nxp.com>
2018-08-20 21:31:57 +08:00
Luo Ji dbcf1e3cc0 [iot] Support dual bootloader in SPL
Move the A/B slot check to SPL, the A/B slot switch
workflow is just like what we have in libavb_ab.

Test: A/B select works fine on imx8m.

Change-Id: Ie3d827a9be0298b491bf2bc8d48833597fd70e90
Signed-off-by: Luo Ji <ji.luo@nxp.com>
2018-08-20 21:31:28 +08:00
Luo Ji 484e0dca8b [iot] [coverity] Fix null dereferenced issues
Fix the null dereferenced issues from converity scan results.
issue id:
  3618300:Dereference after null check
  3618364:Dereference after null check
  3618463:Dereference after null check
  3618470:Explicit null dereferenced
  3618520:Dereference after null check

Test: issue fixed by converity scan.

Change-Id: I577ed094a1f9b493de61b84827c0e1157a4fbd2f
Signed-off-by: Luo Ji <ji.luo@nxp.com>
2018-08-20 21:25:48 +08:00
Luo Ji a251106623 [iot] Fix 'calc_sha256' not defined error
'calc_sha256' should only be valid when CONFIG_IMX_TRUSTY_OS
is defined. Error message is like below:
  error: label 'calc_sha256' defined but not used
	[-Werror=unused-label]

Test: build pass with or without CONFIG_IMX_TRUSTY_OS enabled.

Change-Id: I0938e641596cb9faccd0c64f7c03d526dab3b7d4
Signed-off-by: Luo Ji <ji.luo@nxp.com>
Reviewed-on: http://androidsource.ap.freescale.net/project/4932
Reviewed-by: Wang Haoran <elven.wang@nxp.com>
2018-08-20 21:25:47 +08:00
Haoran.Wang a84bd6bf7b [iot] Use hard code key if no perm attr fused
For the device under development, the perm attr
not fused will break unlock ATX/AVB process and
make dm-verity parameters not output for kernel.

Use hard code one if Trusty OS didn't get the
perm attr.

Bug:93961668
Test: Verify kernel command line contains avb information.

Change-Id: Idd55dde79eed793dccdd7319600fbd04e11ca12d
Signed-off-by: Haoran.Wang <elven.wang@nxp.com>
2018-08-20 21:25:47 +08:00
Yu Shan a1f5c4f9fb [iot] Minor format fix.
Test: None
Bug: None
Change-Id: I2c899e42d8b2911ed96df535c4864d1316d66383
2018-08-20 21:25:46 +08:00
Yu Shan fd2b83defa [iot] No touch RPMB when use Trusty
Since Trusty OS will hand RPMB so no touch
the RPMB partition.

Change-Id: I07ed0e4a024171f6b353b038723ccd6e66a00d54
Signed-off-by: Haoran.Wang <elven.wang@nxp.com>
2018-08-20 21:25:46 +08:00
Yu Shan fd9eec336e [iot] Support fastboot oem fuse at-perm-attr command
Support "fastboot oem fuse at-perm-attr" command for
ATX. The perm_attr will be stored into RPMB which
managed by Trusty OS.
Modified permanent_attributes related AVB ops that
support Trusty OS backed RPMB storage.

Change-Id: Id6248570b4294fed3c45270064196bd6b9cf9208
Signed-off-by: Haoran.Wang <elven.wang@nxp.com>
2018-08-20 21:25:45 +08:00
Yu Shan b92b0e1d49 [iot] Use Trusty OS handle RollbackIndex and lock status
Use Trusty OS AVB manager handle RollbackIndex and
lock status into RPMB partition.

Change-Id: Idfe7234cfa31b2169af59b64e00f028542c49240
Signed-off-by: Haoran.Wang <elven.wang@nxp.com>
2018-08-20 21:25:45 +08:00
Luo Ji d2275a5926 [iot] Return full zero hash if fuse not initialized
Part of permanent attributes hash was stored in
fuse for security reason, however, the write
operation of fuse was disabled by default because
it was an irreversible operation. Returning
AVB_IO_RESULT_ERROR_IO will stop following
AVB process and won't pass dm-verity related
commandlines to kernel, in such case, board
will fail to boot even in unlock state.

Returning AVB_IO_RESULT_OK and full zero
permanent attributes hash when the fuse
haven't been initialized, let the lock/unlock
policy in libavb to handle the mismatch errors.

Test: imx7d_pico boot successfully with dm-verity feature.

Change-Id: I6bcf58ff8ce71859fa2d85c86572ea6de1c3a0df
Signed-off-by: Luo Ji <ji.luo@nxp.com>
2018-08-20 21:25:44 +08:00
Luo Ji 449f9048e6 [iot] Update libavb in u-boot
This commit did:
1. Sync AVB lib with external/avb, head of commit is:
    commit 6d5326a945c2d17d5d0e7718d5cb97663c3b33a2
    Author: Neal Ostrem <nealo@google.com>
    Date:   Tue Apr 24 13:09:45 2018 -0700

        Merge fix/changes required after merge from AOSP ToT.

        Change library name to one used by AT.
        Test: Built successfully and unit tests pass.
        Change-Id: I5e5fc9a6010d96cfecfc6faf0858ba930cba65a0
2. Change product id in ATX to be full zeros to sync with
   external/avb.
3. Fix build errors and implement ops fsl_set_key_version.
4. Move most nxp modified code to lib/avb/fsl/.

Test: build and boot successfully for imx7d_pico and imx8m_phanbell.

Change-Id: I199a035fe8267b10955299a4b745458d40a2e754
Signed-off-by: Luo Ji <ji.luo@nxp.com>
2018-08-20 21:25:44 +08:00
Luo Ji 4397a056bf MA-12216 [Android] Fix u-boot build errors
Type mismatch will cause some build warnings and they will be treated
as errors when '-Werror' is specified. Fix the error logs loke below:
  error: cast from pointer to integer of different size
  [-Werror=pointer-to-int-cast]

Test: build pass for evk_imx8mm

Change-Id: I48489815c8310c659a5c7c860433c4a93cb0dc66
Signed-off-by: Luo Ji <ji.luo@nxp.com>
2018-07-19 18:15:34 +08:00
Ye Li 2105662ada MLK-18591-1 android: Add the AVB library
Porting the android AVB lib from imx u-boot v2017.03

Signed-off-by: Ye Li <ye.li@nxp.com>
2018-06-13 02:41:08 -07:00