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>
Thu, 10 Oct 2019 04:38:38 +0000 (13:38 +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 c4ba8019646cf3a5a100d22d728c5a4e150af74b..95fdccd75a686daf6d836ba6a21d21f425cfa58d 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>
@@ -374,6 +375,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";
@@ -528,7 +547,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");
                }