MA-15180 Refine dual bootloader flow for imx8m
authorJi Luo <ji.luo@nxp.com>
Mon, 22 Jul 2019 01:14:28 +0000 (09:14 +0800)
committerJi Luo <ji.luo@nxp.com>
Thu, 1 Aug 2019 11:23:20 +0000 (19:23 +0800)
We may need to enable the dual bootloader feature on non-trusty
platforms, skip the bootloader rollback index check in spl if
trusty is not enabled.

Don't generate rpmb key in spl, it should be generated in u-boot
proper with u-boot commands.

Test: dual bootloader on imx8mm.

Change-Id: Iac454e0140cd6f4472a66d267d9ba0d40df7102c
Signed-off-by: Ji Luo <ji.luo@nxp.com>
arch/arm/mach-imx/imx8/parser.c
common/spl/spl_fit.c
lib/avb/fsl/fsl_avb_ab_flow.c

index 386479c..ba6ce3b 100644 (file)
@@ -252,7 +252,8 @@ static int read_auth_container(struct spl_image_info *spl_image)
                }
        }
 
-#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_DUAL_BOOTLOADER)
+#if defined(CONFIG_SPL_BUILD) && \
+       defined(CONFIG_DUAL_BOOTLOADER) && defined(CONFIG_IMX_TRUSTY_OS)
        /* Everything checks out, get the sw_version now. */
        spl_image->rbindex = (uint64_t)container->sw_version;
 #endif
index d55d833..81a31fb 100644 (file)
@@ -429,14 +429,14 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
                return -1;
        }
 
-#ifdef CONFIG_DUAL_BOOTLOADER
-    int rbindex;
-    rbindex = spl_fit_get_rbindex(fit, images);
-    if (rbindex < 0) {
-        printf("Error! Can't get rollback index!\n");
-        return -1;
-    } else
-        spl_image->rbindex = rbindex;
+#if defined(CONFIG_DUAL_BOOTLOADER) && defined(CONFIG_IMX_TRUSTY_OS)
+       int rbindex;
+       rbindex = spl_fit_get_rbindex(fit, images);
+       if (rbindex < 0) {
+               printf("Error! Can't get rollback index!\n");
+               return -1;
+       } else
+               spl_image->rbindex = rbindex;
 #endif
 
 #ifdef CONFIG_SPL_FPGA_SUPPORT
index 446d650..2eea2d9 100644 (file)
@@ -214,7 +214,7 @@ int fsl_load_metadata_dual_uboot(struct blk_desc *dev_desc,
        }
 }
 
-#ifndef CONFIG_XEN
+#if !defined(CONFIG_XEN) && defined(CONFIG_IMX_TRUSTY_OS)
 static int spl_verify_rbidx(struct mmc *mmc, AvbABSlotData *slot,
                        struct spl_image_info *spl_image)
 {
@@ -286,7 +286,7 @@ int mmc_load_image_parse_container_dual_uboot(
        struct blk_desc *dev_desc;
        AvbABData ab_data, ab_data_orig;
        size_t slot_index_to_boot, target_slot;
-#ifndef CONFIG_XEN
+#if !defined(CONFIG_XEN) && defined(CONFIG_IMX_TRUSTY_OS)
        struct keyslot_package kp;
 #endif
 
@@ -302,7 +302,7 @@ int mmc_load_image_parse_container_dual_uboot(
                return -1;
        }
 
-#ifndef CONFIG_XEN
+#if !defined(CONFIG_XEN) && defined(CONFIG_IMX_TRUSTY_OS)
        /* Read RPMB keyslot package, xen won't check this. */
        read_keyslot_package(&kp);
        if (strcmp(kp.magic, KEYPACK_MAGIC)) {
@@ -350,7 +350,7 @@ int mmc_load_image_parse_container_dual_uboot(
                        ret = mmc_load_image_parse_container(spl_image, mmc, info.start);
 
                        /* Don't need to check rollback index for xen. */
-#ifndef CONFIG_XEN
+#if !defined(CONFIG_XEN) && defined(CONFIG_IMX_TRUSTY_OS)
                        /* Image loaded successfully, go to verify rollback index */
                        if (!ret && rpmbkey_is_set())
                                ret = spl_verify_rbidx(mmc, &ab_data.slots[target_slot], spl_image);
@@ -398,7 +398,7 @@ int mmc_load_image_parse_container_dual_uboot(
                        ret = mmc_load_image_parse_container(spl_image, mmc, info.start);
 
                        /* Don't need to check rollback index for xen. */
-#ifndef CONFIG_XEN
+#if !defined(CONFIG_XEN) && defined(CONFIG_IMX_TRUSTY_OS)
                        /* Image loaded successfully, go to verify rollback index */
                        if (!ret && rpmbkey_is_set())
                                ret = spl_verify_rbidx(mmc, &ab_data.slots[slot_index_to_boot], spl_image);
@@ -445,7 +445,9 @@ int mmc_load_image_raw_sector_dual_uboot(
        struct image_header *header;
        AvbABData ab_data, ab_data_orig;
        size_t slot_index_to_boot, target_slot;
+#ifdef CONFIG_IMX_TRUSTY_OS
        struct keyslot_package kp;
+#endif
 
        /* Check if gpt is valid */
        dev_desc = mmc_get_blk_desc(mmc);
@@ -459,20 +461,23 @@ int mmc_load_image_raw_sector_dual_uboot(
                return -1;
        }
 
-       /* Init RPMB keyslot package if not initialized before. */
+#ifdef CONFIG_IMX_TRUSTY_OS
+       /* Read RPMB keyslot package. */
        read_keyslot_package(&kp);
        if (strcmp(kp.magic, KEYPACK_MAGIC)) {
-               printf("keyslot package magic error. Will generate new one\n");
-               if (gen_rpmb_key(&kp)) {
-                       printf("Generate keyslot package fail!\n");
+               if (rpmbkey_is_set()) {
+                       printf("\nFATAL - RPMB key was destroyed!\n");
+                       hang();
+               } else
+                       printf("keyslot package magic error, do nothing here!\n");
+       } else {
+               /* 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;
                }
        }
-       /* 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;
-       }
+#endif
 
        /* Load AB metadata from misc partition */
        if (fsl_load_metadata_dual_uboot(dev_desc, &ab_data,
@@ -528,13 +533,15 @@ int mmc_load_image_raw_sector_dual_uboot(
                                ret = -1;
                        }
 
+#ifdef CONFIG_IMX_TRUSTY_OS
                        /* Fit image loaded successfully, go to verify rollback index */
-                       if (!ret)
+                       if (!ret && rpmbkey_is_set())
                                ret = spl_verify_rbidx(mmc, &ab_data.slots[target_slot], spl_image);
 
                        /* Copy rpmb keyslot to secure memory. */
                        if (!ret)
                                fill_secure_keyslot_package(&kp);
+#endif
                }
 
                /* Set current slot to unbootable if load/verify fail. */
@@ -598,13 +605,15 @@ int mmc_load_image_raw_sector_dual_uboot(
                                ret = -1;
                        }
 
+#ifdef CONFIG_IMX_TRUSTY_OS
                        /* Fit image loaded successfully, go to verify rollback index */
-                       if (!ret)
+                       if (!ret && rpmbkey_is_set())
                                ret = spl_verify_rbidx(mmc, &ab_data.slots[target_slot], spl_image);
 
                        /* Copy rpmb keyslot to secure memory. */
                        if (!ret)
                                fill_secure_keyslot_package(&kp);
+#endif
                }
 
                if (ret)