cmd: usbdown: support the checking signature feature 57/93057/2
authorJaehoon Chung <jh80.chung@samsung.com>
Thu, 20 Oct 2016 06:55:11 +0000 (15:55 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Fri, 21 Oct 2016 01:05:51 +0000 (10:05 +0900)
Added the checking signature feature for preventing to flash wrong
image.
This funcionality does the same behavior with thor.

Change-Id: I2645cd8e506ea412be39186952a0860fe64bdaf3
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
cmd/usbdown.c

index 6a911747693e9725d9df96bec5ef631b9d99bed6..1b9f1fc25f7ba903756985ce983006a5a9628e2f 100644 (file)
@@ -15,6 +15,7 @@
 #include <asm/byteorder.h>
 #include <asm/unaligned.h>
 #include <linux/list.h>
+#include <samsung/sighdr.h>
 #include <part.h>
 #include <usb.h>
 #include <mmc.h>
@@ -370,6 +371,24 @@ int do_update(cmd_tbl_t *cmdtp, int flags, int argc, char * const argv[])
                        return -EINVAL;
                }
 
+#ifdef CONFIG_SIG
+               /* It needs to check the signature about only u-boot image */
+               if (!strncmp(usbdown->name, "u-boot", strlen(usbdown->name))) {
+                       if (fs_set_blk_dev(from, argv[1], FS_TYPE_ANY))
+                               return CMD_RET_FAILURE;
+
+                       ret = fs_read(filename, (phys_addr_t)addr, 0,
+                                       size, &len_read);
+                       if (ret)
+                               return CMD_RET_FAILURE;
+
+                       ret = check_board_signature("u-boot-mmc.bin",
+                                       (phys_addr_t)addr, (phys_addr_t)size);
+                       if (ret)
+                               return CMD_RET_FAILURE;
+               }
+#endif
+
                if (usbdown->layout == FS_FAT) {
                        /* loading File */
                        fsname = "fat";
@@ -510,7 +529,9 @@ int do_usb_down(cmd_tbl_t *cmdtp, int flags, int argc, char * const argv[])
                        sprintf(cmd_buf, "%s %s %s %s",
                                        cmd, part, interface, dir);
                        sprintf(cmd_buf + strlen(cmd_buf), "/%s", name[i]);
-                       run_command(cmd_buf, 0);
+                       ret = run_command(cmd_buf, 0);
+                       if (ret == CMD_RET_FAILURE)
+                               return ret;
                        printf("\n");
                }