ARM: renesas: Drop unused mmc.h
[pandora-u-boot.git] / common / avb_verify.c
index 48ba8db..cff9117 100644 (file)
@@ -1,7 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2018, Linaro Limited
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <avb_verify.h>
@@ -120,6 +119,55 @@ static const unsigned char avb_root_pub[1032] = {
        0xd8, 0x7e,
 };
 
+const char *str_avb_io_error(AvbIOResult res)
+{
+       switch (res) {
+       case AVB_IO_RESULT_OK:
+               return "Requested operation was successful";
+       case AVB_IO_RESULT_ERROR_IO:
+               return "Underlying hardware encountered an I/O error";
+       case AVB_IO_RESULT_ERROR_OOM:
+               return "Unable to allocate memory";
+       case AVB_IO_RESULT_ERROR_NO_SUCH_PARTITION:
+               return "Requested partition does not exist";
+       case AVB_IO_RESULT_ERROR_RANGE_OUTSIDE_PARTITION:
+               return "Bytes requested is outside the range of partition";
+       case AVB_IO_RESULT_ERROR_NO_SUCH_VALUE:
+               return "Named persistent value does not exist";
+       case AVB_IO_RESULT_ERROR_INVALID_VALUE_SIZE:
+               return "Named persistent value size is not supported";
+       case AVB_IO_RESULT_ERROR_INSUFFICIENT_SPACE:
+               return "Buffer is too small for the requested operation";
+       default:
+               return "Unknown AVB error";
+       }
+}
+
+const char *str_avb_slot_error(AvbSlotVerifyResult res)
+{
+       switch (res) {
+       case AVB_SLOT_VERIFY_RESULT_OK:
+               return "Verification passed successfully";
+       case AVB_SLOT_VERIFY_RESULT_ERROR_OOM:
+               return "Allocation of memory failed";
+       case AVB_SLOT_VERIFY_RESULT_ERROR_IO:
+               return "I/O error occurred while trying to load data";
+       case AVB_SLOT_VERIFY_RESULT_ERROR_VERIFICATION:
+               return "Digest didn't match or signature checks failed";
+       case AVB_SLOT_VERIFY_RESULT_ERROR_ROLLBACK_INDEX:
+               return "Rollback index is less than its stored value";
+       case AVB_SLOT_VERIFY_RESULT_ERROR_PUBLIC_KEY_REJECTED:
+               return "Public keys are not accepted";
+       case AVB_SLOT_VERIFY_RESULT_ERROR_INVALID_METADATA:
+               return "Metadata is invalid or inconsistent";
+       case AVB_SLOT_VERIFY_RESULT_ERROR_UNSUPPORTED_VERSION:
+               return "Metadata requires a newer version of libavb";
+       case AVB_SLOT_VERIFY_RESULT_ERROR_INVALID_ARGUMENT:
+               return "Invalid arguments are used";
+       default:
+               return "Unknown AVB slot verification error";
+       }
+}
 /**
  * ============================================================================
  * Boot states support (GREEN, YELLOW, ORANGE, RED) and dm_verity
@@ -280,9 +328,9 @@ static unsigned long mmc_read_and_flush(struct mmc_part *part,
         * Reading fails on unaligned buffers, so we have to
         * use aligned temporary buffer and then copy to destination
         */
-
        if (unaligned) {
-               printf("Handling unaligned read buffer..\n");
+               debug("%s: handling unaligned read buffer, addr = 0x%p\n",
+                     __func__, buffer);
                tmp_buf = get_sector_buf();
                buf_size = get_sector_buf_size();
                if (sectors > buf_size / part->info.blksz)
@@ -321,7 +369,8 @@ static unsigned long mmc_write(struct mmc_part *part, lbaint_t start,
        if (unaligned) {
                tmp_buf = get_sector_buf();
                buf_size = get_sector_buf_size();
-               printf("Handling unaligned wrire buffer..\n");
+               debug("%s: handling unaligned read buffer, addr = 0x%p\n",
+                     __func__, buffer);
                if (sectors > buf_size / part->info.blksz)
                        sectors = buf_size / part->info.blksz;
 
@@ -349,28 +398,35 @@ static struct mmc_part *get_partition(AvbOps *ops, const char *partition)
        dev_num = get_boot_device(ops);
        part->mmc = find_mmc_device(dev_num);
        if (!part->mmc) {
-               printf("No MMC device at slot %x\n", dev_num);
+               printf("%s: no MMC device at slot %x\n", __func__, dev_num);
                goto err;
        }
 
-       if (mmc_init(part->mmc)) {
-               printf("MMC initialization failed\n");
+       ret = mmc_init(part->mmc);
+       if (ret) {
+               printf("%s: MMC initialization failed, err = %d\n",
+                      __func__, ret);
                goto err;
        }
 
-       ret = mmc_switch_part(part->mmc, part_num);
-       if (ret)
-               goto err;
+       if (IS_MMC(part->mmc)) {
+               ret = mmc_switch_part(part->mmc, part_num);
+               if (ret) {
+                       printf("%s: MMC part switch failed, err = %d\n",
+                              __func__, ret);
+                       goto err;
+               }
+       }
 
        mmc_blk = mmc_get_blk_desc(part->mmc);
        if (!mmc_blk) {
-               printf("Error - failed to obtain block descriptor\n");
+               printf("%s: failed to obtain block descriptor\n", __func__);
                goto err;
        }
 
        ret = part_get_info_by_name(mmc_blk, partition, &part->info);
        if (ret < 0) {
-               printf("Can't find partition '%s'\n", partition);
+               printf("%s: can't find partition '%s'\n", __func__, partition);
                goto err;
        }
 
@@ -683,7 +739,7 @@ static AvbIOResult read_rollback_index(AvbOps *ops,
 {
 #ifndef CONFIG_OPTEE_TA_AVB
        /* For now we always return 0 as the stored rollback index. */
-       printf("%s not supported yet\n", __func__);
+       debug("%s: rollback protection is not implemented\n", __func__);
 
        if (out_rollback_index)
                *out_rollback_index = 0;
@@ -729,7 +785,7 @@ static AvbIOResult write_rollback_index(AvbOps *ops,
 {
 #ifndef CONFIG_OPTEE_TA_AVB
        /* For now this is a no-op. */
-       printf("%s not supported yet\n", __func__);
+       debug("%s: rollback protection is not implemented\n", __func__);
 
        return AVB_IO_RESULT_OK;
 #else
@@ -765,8 +821,7 @@ static AvbIOResult read_is_device_unlocked(AvbOps *ops, bool *out_is_unlocked)
 {
 #ifndef CONFIG_OPTEE_TA_AVB
        /* For now we always return that the device is unlocked. */
-
-       printf("%s not supported yet\n", __func__);
+       debug("%s: device locking is not implemented\n", __func__);
 
        *out_is_unlocked = true;