cmd: usbdown: support the checking signature feature
authorJaehoon Chung <jh80.chung@samsung.com>
Thu, 20 Oct 2016 06:55:11 +0000 (15:55 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Tue, 11 Apr 2017 09:58:16 +0000 (18:58 +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 404625405077c6f96fdfbb629023ba8044d661c8..3d54034355919960b42e37346bd3aab299c8669e 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";
@@ -514,7 +533,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");
                }