MA-15181 use correct API in SPL to get mmc index
authorHaoran.Wang <elven.wang@nxp.com>
Mon, 22 Jul 2019 09:45:49 +0000 (17:45 +0800)
committerHaoran.Wang <elven.wang@nxp.com>
Mon, 22 Jul 2019 09:53:43 +0000 (17:53 +0800)
Due SPL doesn't have env, so cannot use mmc_get_env_dev() get
the mmc index.
Following spl_mmc.c get correct mmc index in SPL.

Change-Id: I0f07a9ea35d5b3ba0d638af436238d0cfe925981
Signed-off-by: Haoran.Wang <elven.wang@nxp.com>
lib/avb/fsl/fsl_avbkey.c

index 2624b06..8f7f3d0 100644 (file)
 #include "trusty/hwcrypto.h"
 #include "fsl_atx_attributes.h"
 
+#if defined(CONFIG_SPL_BUILD)
+#include <spl.h>
+#endif
+
 #define INITFLAG_FUSE_OFFSET 0
 #define INITFLAG_FUSE_MASK 0x00000001
 #define INITFLAG_FUSE 0x00000001
@@ -61,13 +65,36 @@ void fill_secure_keyslot_package(struct keyslot_package *kp) {
                                0x100));
 }
 
+#if defined(CONFIG_SPL_BUILD)
+static int spl_mmc_get_device_index(u32 boot_device)
+{
+       switch (boot_device) {
+       case BOOT_DEVICE_MMC1:
+               return 0;
+       case BOOT_DEVICE_MMC2:
+       case BOOT_DEVICE_MMC2_2:
+               return 1;
+       }
+
+#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
+       printf("spl: unsupported mmc boot device.\n");
+#endif
+
+       return -ENODEV;
+}
+#endif
+
 int read_keyslot_package(struct keyslot_package* kp) {
        char original_part;
        int blksz;
        unsigned char* fill = NULL;
        int ret = 0;
        /* load tee from boot1 of eMMC. */
+#if defined(CONFIG_SPL_BUILD)
+       int mmcc = spl_mmc_get_device_index(spl_boot_device());
+#else
        int mmcc = mmc_get_env_dev();
+#endif
        struct blk_desc *dev_desc = NULL;
 
        struct mmc *mmc;