[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>
This commit is contained in:
Luo Ji 2018-06-20 18:35:01 +08:00 committed by Ji Luo
parent 06e6b708df
commit 80834f323b
2 changed files with 11 additions and 0 deletions

View File

@ -217,6 +217,7 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)
#define EXT_CSD_WR_REL_PARAM 166 /* R */
#define EXT_CSD_WR_REL_SET 167 /* R/W */
#define EXT_CSD_RPMB_MULT 168 /* RO */
#define EXT_CSD_BOOT_WP 173 /* R/W & R/W/C_P */
#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
#define EXT_CSD_BOOT_BUS_WIDTH 177
#define EXT_CSD_PART_CONF 179 /* R/W */
@ -328,6 +329,8 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)
#define MMC_QUIRK_RETRY_SEND_CID BIT(0)
#define MMC_QUIRK_RETRY_SET_BLOCKLEN BIT(1)
#define BOOT1_PWR_WP (0x83)
enum mmc_voltage {
MMC_SIGNAL_VOLTAGE_000 = 0,
MMC_SIGNAL_VOLTAGE_120 = 1,
@ -339,6 +342,7 @@ enum mmc_voltage {
MMC_SIGNAL_VOLTAGE_180 |\
MMC_SIGNAL_VOLTAGE_330)
/* Maximum block size for MMC */
#define MMC_MAX_BLOCK_LEN 512

View File

@ -62,6 +62,8 @@ bool fsl_slot_is_bootable(AvbABSlotData* slot) {
#define PARTITION_MISC "misc"
#define PARTITION_BOOTLOADER "bootloader"
extern int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value);
/* Pre-declaration of h_spl_load_read(), see detail implementation in
* common/spl/spl_mmc.c.
*/
@ -281,6 +283,11 @@ int mmc_load_image_raw_sector_dual_uboot(
return -1;
}
}
/* Set power-on write protection to boot1 partition. */
if (mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BOOT_WP, BOOT1_PWR_WP)) {
printf("Unable to set power-on write protection to boot1!\n");
return -1;
}
/* Load AB metadata from misc partition */
if (fsl_load_metadata_dual_uboot(dev_desc, &ab_data,