summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2017-09-26 13:19:37 +0200
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2017-09-26 15:24:55 +0000
commit7a16e40adb108eaedb3a46619fcdf99cdd9a1b9d (patch)
tree7293d6e58f4b6b9ea20f386a98d6c021872586d0
parentbd9d8353e0345d04f6dc661fbf3513479c0d41f5 (diff)
downloadchrome-ec-7a16e40adb108eaedb3a46619fcdf99cdd9a1b9d.tar.gz
stm32: Add command to reboot in DFU mode
Setting in the 'USER' option byte, the BOOT_SEL bit to 0 and the nBOOT0 bit to 0 have the same effect as asserting physically the BOOT0 pin and the device will boot in the ROM code 'DFU' mode at the next cold boot. Add the 'dfu' console command to easily reboot in USB DFU mode to re-flash the firmware without having to re-plug the dongle differently. As mentioned in the STM32 Reference Manual, the BOOT_SEL and nBOOT0 bits are available on STM32F04x and STM32F09x devices only. So add some code in the early init to emulate this behavior on STM32F07x. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=twinkie BUG=none TEST=type 'dfu' in the console, see the USB device re-enumerating as 0483:df11, flash a new firmware then boot in normal mode by doing: sudo dfu-util -a 0 -s 0x08000000 -D build/twinkie/ec.bin sudo dfu-util -a 0 -s 0x08000000:force:unprotect -D build/twinkie/ec.bin Change-Id: I301002e015c7db28950797f33349ff3f99537373 Reviewed-on: https://chromium-review.googlesource.com/684300 Tested-by: Vincent Palatin <vpalatin@chromium.org> Trybot-Ready: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/twinkie/board.h1
-rw-r--r--chip/stm32/flash-f.c14
-rw-r--r--core/cortex-m0/init.S17
-rw-r--r--include/config.h1
4 files changed, 33 insertions, 0 deletions
diff --git a/board/twinkie/board.h b/board/twinkie/board.h
index cfb39ede1f..4f40499dfc 100644
--- a/board/twinkie/board.h
+++ b/board/twinkie/board.h
@@ -46,6 +46,7 @@
#define CONFIG_ADC
#define CONFIG_BOARD_PRE_INIT
+#define CONFIG_CMD_REBOOT_DFU
#define CONFIG_I2C
#define CONFIG_I2C_MASTER
#define CONFIG_INA231
diff --git a/chip/stm32/flash-f.c b/chip/stm32/flash-f.c
index f3c6b381b8..c238470865 100644
--- a/chip/stm32/flash-f.c
+++ b/chip/stm32/flash-f.c
@@ -653,3 +653,17 @@ int flash_pre_init(void)
return EC_SUCCESS;
}
+
+#ifdef CONFIG_CMD_REBOOT_DFU
+static int command_dfu(int argc, char **argv)
+{
+ /* Enable BOOT_SEL and nBOOT0 */
+ write_optb(STM32_OPTB_USER_OFF, read_optb(STM32_OPTB_USER_OFF) & ~0x88);
+ system_reset(SYSTEM_RESET_HARD);
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(dfu, command_dfu,
+ "",
+ "Reboot in DFU mode");
+#endif /* CONFIG_CMD_REBOOT_DFU */
diff --git a/core/cortex-m0/init.S b/core/cortex-m0/init.S
index 9b8a774415..b0c242942e 100644
--- a/core/cortex-m0/init.S
+++ b/core/cortex-m0/init.S
@@ -85,6 +85,23 @@ sram_vtable: .skip (48*4)
.global reset
.thumb_func
reset:
+#if defined(CONFIG_CMD_REBOOT_DFU) && defined(CHIP_VARIANT_STM32F07X)
+ /*
+ * Emulate on STM32F07x the ROM code jumping to the USB DFU bootloader
+ * if BOOT_SEL and nBOOT0 are set in the user option byte,
+ * as it is missing on those chips.
+ */
+ ldr r0, =0x1FFFF800 @ Option byte mapping
+ ldr r1, =0x1FFFC800 @ ROM entry point
+ ldrb r2, [r0, #2] @ Read the 'USER' option byte
+ movs r3, #0x88 @ BOOT_SEL and nBOOT0 bits
+ tst r2, r3 @ are BOOT_SEL and nBOOT0 set (ie equal 0) ?
+ bne normal_boot @ No, use the RO EC copy
+ ldr r3, [r1, #4] @ Read the reset vector address
+ bx r3 @ Go to DFU bootloader
+normal_boot:
+#endif /* defined(CONFIG_CMD_REBOOT_DFU) && defined(HIP_VARIANT_STM32F07X) */
+
/*
* Ensure we're in privileged mode with main stack. Necessary if
* we've jumped directly here from another image after task_start().
diff --git a/include/config.h b/include/config.h
index 0897f41cb2..22121ae6e2 100644
--- a/include/config.h
+++ b/include/config.h
@@ -701,6 +701,7 @@
#define CONFIG_CMD_POWERINDEBUG
#undef CONFIG_CMD_POWERLED
#define CONFIG_CMD_POWER_AP
+#undef CONFIG_CMD_REBOOT_DFU
#define CONFIG_CMD_REGULATOR
#undef CONFIG_CMD_RTC
#undef CONFIG_CMD_RTC_ALARM