]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/image-fit.c
Prepare v2013.07-rc2
[karo-tx-uboot.git] / common / image-fit.c
index 9f56b5d303c19a0924be85a3faa284725181bc2e..b75e119d930e5d70d6ac703f70bbef50687ee21d 100644 (file)
@@ -234,42 +234,45 @@ void fit_print_contents(const void *fit)
  * @fit: pointer to the FIT format image header
  * @noffset: offset of the hash node
  * @p: pointer to prefix string
+ * @type: Type of information to print ("hash" or "sign")
  *
  * fit_image_print_data() lists properies for the processed hash node
  *
+ * This function avoid using puts() since it prints a newline on the host
+ * but does not in U-Boot.
+ *
  * returns:
  *     no returned results
  */
-static void fit_image_print_data(const void *fit, int noffset, const char *p)
+static void fit_image_print_data(const void *fit, int noffset, const char *p,
+                                const char *type)
 {
-       char *algo;
+       const char *keyname;
        uint8_t *value;
        int value_len;
-       int i, ret;
-
-       /*
-        * Check subnode name, must be equal to "hash".
-        * Multiple hash nodes require unique unit node
-        * names, e.g. hash@1, hash@2, etc.
-        */
-       if (strncmp(fit_get_name(fit, noffset, NULL),
-                   FIT_HASH_NODENAME,
-                   strlen(FIT_HASH_NODENAME)) != 0)
-               return;
+       char *algo;
+       int required;
+       int ret, i;
 
-       debug("%s  Hash node:    '%s'\n", p,
+       debug("%s  %s node:    '%s'\n", p, type,
              fit_get_name(fit, noffset, NULL));
-
-       printf("%s  Hash algo:    ", p);
+       printf("%s  %s algo:    ", p, type);
        if (fit_image_hash_get_algo(fit, noffset, &algo)) {
                printf("invalid/unsupported\n");
                return;
        }
-       printf("%s\n", algo);
+       printf("%s", algo);
+       keyname = fdt_getprop(fit, noffset, "key-name-hint", NULL);
+       required = fdt_getprop(fit, noffset, "required", NULL) != NULL;
+       if (keyname)
+               printf(":%s", keyname);
+       if (required)
+               printf(" (required)");
+       printf("\n");
 
        ret = fit_image_hash_get_value(fit, noffset, &value,
                                        &value_len);
-       printf("%s  Hash value:   ", p);
+       printf("%s  %s value:   ", p, type);
        if (ret) {
                printf("unavailable\n");
        } else {
@@ -278,7 +281,18 @@ static void fit_image_print_data(const void *fit, int noffset, const char *p)
                printf("\n");
        }
 
-       debug("%s  Hash len:     %d\n", p, value_len);
+       debug("%s  %s len:     %d\n", p, type, value_len);
+
+       /* Signatures have a time stamp */
+       if (IMAGE_ENABLE_TIMESTAMP && keyname) {
+               time_t timestamp;
+
+               printf("%s  Timestamp:    ", p);
+               if (fit_get_timestamp(fit, noffset, &timestamp))
+                       printf("unavailable\n");
+               else
+                       genimg_print_time(timestamp);
+       }
 }
 
 /**
@@ -303,8 +317,12 @@ static void fit_image_print_verification_data(const void *fit, int noffset,
         * names, e.g. hash@1, hash@2, signature@1, signature@2, etc.
         */
        name = fit_get_name(fit, noffset, NULL);
-       if (!strncmp(name, FIT_HASH_NODENAME, strlen(FIT_HASH_NODENAME)))
-               fit_image_print_data(fit, noffset, p);
+       if (!strncmp(name, FIT_HASH_NODENAME, strlen(FIT_HASH_NODENAME))) {
+               fit_image_print_data(fit, noffset, p, "Hash");
+       } else if (!strncmp(name, FIT_SIG_NODENAME,
+                               strlen(FIT_SIG_NODENAME))) {
+               fit_image_print_data(fit, noffset, p, "Sign");
+       }
 }
 
 /**
@@ -351,10 +369,13 @@ void fit_image_print(const void *fit, int image_noffset, const char *p)
 
 #ifndef USE_HOSTCC
        printf("%s  Data Start:   ", p);
-       if (ret)
+       if (ret) {
                printf("unavailable\n");
-       else
-               printf("0x%08lx\n", (ulong)data);
+       } else {
+               void *vdata = (void *)data;
+
+               printf("0x%08lx\n", (ulong)map_to_sysmem(vdata));
+       }
 #endif
 
        printf("%s  Data Size:    ", p);
@@ -941,13 +962,23 @@ int fit_image_verify(const void *fit, int image_noffset)
 {
        const void      *data;
        size_t          size;
-       int             noffset;
+       int             noffset = 0;
        char            *err_msg = "";
+       int verify_all = 1;
+       int ret;
 
        /* Get image data and data length */
        if (fit_image_get_data(fit, image_noffset, &data, &size)) {
                err_msg = "Can't get image data/size";
-               return 0;
+               goto error;
+       }
+
+       /* Verify all required signatures */
+       if (IMAGE_ENABLE_VERIFY &&
+           fit_image_verify_required_sigs(fit, image_noffset, data, size,
+                                          gd_fdt_blob(), &verify_all)) {
+               err_msg = "Unable to verify required signature";
+               goto error;
        }
 
        /* Process all hash subnodes of the component image node */
@@ -967,6 +998,15 @@ int fit_image_verify(const void *fit, int image_noffset)
                                                 &err_msg))
                                goto error;
                        puts("+ ");
+               } else if (IMAGE_ENABLE_VERIFY && verify_all &&
+                               !strncmp(name, FIT_SIG_NODENAME,
+                                       strlen(FIT_SIG_NODENAME))) {
+                       ret = fit_image_check_sig(fit, noffset, data,
+                                                       size, -1, &err_msg);
+                       if (ret)
+                               puts("- ");
+                       else
+                               puts("+ ");
                }
        }
 
@@ -1351,63 +1391,6 @@ int fit_conf_get_prop_node(const void *fit, int noffset,
        return fit_image_get_node(fit, uname);
 }
 
-/**
- * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
- * a given configuration
- * @fit: pointer to the FIT format image header
- * @noffset: configuration node offset
- *
- * fit_conf_get_kernel_node() retrives kernel image node unit name from
- * configuration FIT_KERNEL_PROP property and translates it to the node
- * offset.
- *
- * returns:
- *     image node offset when found (>=0)
- *     negative number on failure (FDT_ERR_* code)
- */
-int fit_conf_get_kernel_node(const void *fit, int noffset)
-{
-       return fit_conf_get_prop_node(fit, noffset, FIT_KERNEL_PROP);
-}
-
-/**
- * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
- * a given configuration
- * @fit: pointer to the FIT format image header
- * @noffset: configuration node offset
- *
- * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
- * configuration FIT_KERNEL_PROP property and translates it to the node
- * offset.
- *
- * returns:
- *     image node offset when found (>=0)
- *     negative number on failure (FDT_ERR_* code)
- */
-int fit_conf_get_ramdisk_node(const void *fit, int noffset)
-{
-       return fit_conf_get_prop_node(fit, noffset, FIT_RAMDISK_PROP);
-}
-
-/**
- * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
- * a given configuration
- * @fit: pointer to the FIT format image header
- * @noffset: configuration node offset
- *
- * fit_conf_get_fdt_node() retrives fdt image node unit name from
- * configuration FIT_KERNEL_PROP property and translates it to the node
- * offset.
- *
- * returns:
- *     image node offset when found (>=0)
- *     negative number on failure (FDT_ERR_* code)
- */
-int fit_conf_get_fdt_node(const void *fit, int noffset)
-{
-       return fit_conf_get_prop_node(fit, noffset, FIT_FDT_PROP);
-}
-
 /**
  * fit_conf_print - prints out the FIT configuration details
  * @fit: pointer to the FIT format image header
@@ -1467,49 +1450,6 @@ int fit_image_select(const void *fit, int rd_noffset, int verify)
        return 0;
 }
 
-/**
- * fit_check_ramdisk - verify FIT format ramdisk subimage
- * @fit_hdr: pointer to the FIT ramdisk header
- * @rd_noffset: ramdisk subimage node offset within FIT image
- * @arch: requested ramdisk image architecture type
- * @verify: data CRC verification flag
- *
- * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
- * specified FIT image.
- *
- * returns:
- *     1, on success
- *     0, on failure
- */
-int fit_check_ramdisk(const void *fit, int rd_noffset, uint8_t arch,
-                       int verify)
-{
-       fit_image_print(fit, rd_noffset, "   ");
-
-       if (verify) {
-               puts("   Verifying Hash Integrity ... ");
-               if (!fit_image_verify(fit, rd_noffset)) {
-                       puts("Bad Data Hash\n");
-                       bootstage_error(BOOTSTAGE_ID_FIT_RD_HASH);
-                       return 0;
-               }
-               puts("OK\n");
-       }
-
-       bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK_ALL);
-       if (!fit_image_check_os(fit, rd_noffset, IH_OS_LINUX) ||
-           !fit_image_check_arch(fit, rd_noffset, arch) ||
-           !fit_image_check_type(fit, rd_noffset, IH_TYPE_RAMDISK)) {
-               printf("No Linux %s Ramdisk Image\n",
-                      genimg_get_arch_name(arch));
-               bootstage_error(BOOTSTAGE_ID_FIT_RD_CHECK_ALL);
-               return 0;
-       }
-
-       bootstage_mark(BOOTSTAGE_ID_FIT_RD_CHECK_ALL_OK);
-       return 1;
-}
-
 int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
                        ulong addr)
 {
@@ -1654,7 +1594,7 @@ int fit_image_load(bootm_headers_t *images, const char *prop_name, ulong addr,
        if (fit_image_get_data(fit, noffset, &buf, &size)) {
                printf("Could not find %s subimage data!\n", prop_name);
                bootstage_error(bootstage_id + BOOTSTAGE_SUB_GET_DATA);
-               return -ENOMEDIUM;
+               return -ENOENT;
        }
        len = (ulong)size;