diff options
author | Ji Luo <ji.luo@nxp.com> | 2018-10-10 17:29:35 +0800 |
---|---|---|
committer | Ye Li <ye.li@nxp.com> | 2018-10-11 19:41:40 -0700 |
commit | 884ef77506e8255903ba9d9b8f6d54142f242e9f (patch) | |
tree | 3c7934787819d3aead5a2c8d0188e6588dd9764e /lib/avb/fsl/fsl_avbkey.c | |
parent | c66bb808116f24c9f8f95db974b62046d9a9e0ba (diff) |
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>
(cherry picked from commit 557981f3ace1f11f1483668dd97076e6c3f1d1cc)
Diffstat (limited to 'lib/avb/fsl/fsl_avbkey.c')
-rw-r--r-- | lib/avb/fsl/fsl_avbkey.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/avb/fsl/fsl_avbkey.c b/lib/avb/fsl/fsl_avbkey.c index 71a012906b..7c192f31ef 100644 --- a/lib/avb/fsl/fsl_avbkey.c +++ b/lib/avb/fsl/fsl_avbkey.c @@ -1368,3 +1368,63 @@ fail: } #endif /* AVB_RPMB && CONFIG_AVB_ATX */ + +#ifdef CONFIG_ANDROID_AUTO_SUPPORT +int fastboot_set_rpmb_key(uint8_t *staged_buf, uint32_t key_size) +{ + int ret = 0; + int mmcc; + struct mmc *mmc; + char original_part; + struct blk_desc *desc = NULL; + uint8_t rpmb_key[RPMBKEY_LENGTH]; + + if (memcmp(staged_buf, RPMB_KEY_MAGIC, strlen(RPMB_KEY_MAGIC))) { + printf("ERROR - rpmb magic doesn't match!\n"); + return -1; + } + + /* Get current mmc device. */ + mmcc = mmc_get_env_dev(); + mmc = find_mmc_device(mmcc); + if (!mmc) { + printf("error - cannot find '%d' mmc device\n", mmcc); + return -1; + } + desc = mmc_get_blk_desc(mmc); + original_part = desc->hwpart; + + /* Switch to the RPMB partition */ + if (desc->hwpart != MMC_PART_RPMB) { + if (mmc_switch_part(mmc, MMC_PART_RPMB) != 0) { + printf("ERROR - can't switch to rpmb partition \n"); + return -1; + } + desc->hwpart = MMC_PART_RPMB; + } + + /* Set rpmb key. */ + memset(rpmb_key, 0, RPMBKEY_LENGTH); + memcpy(rpmb_key, staged_buf + strlen(RPMB_KEY_MAGIC), RPMBKEY_LENGTH); + + if (mmc_rpmb_set_key(mmc, rpmb_key)) { + printf("ERROR - Key already programmed ?\n"); + ret = -1; + goto fail; + } else + printf("RPMB key programed successfully!"); + + /* TODO Generate keyblob with CAAM and store it to boot1, + * this requires CAAM is ready for Android Auto. + */ +fail: + /* Return to original partition */ + if (desc->hwpart != original_part) { + if (mmc_switch_part(mmc, original_part) != 0) + return -1; + desc->hwpart = original_part; + } + + return ret; +} +#endif |