Project import generated by Copybara.
NOKEYCHECK=True
GitOrigin-RevId: 2deba9aa23f252d02164a254dacf7363d52f19bc
diff --git a/stm32flash.patches/stm32flash-50.patch b/stm32flash.patches/stm32flash-50.patch
new file mode 100644
index 0000000..e0f95ba
--- /dev/null
+++ b/stm32flash.patches/stm32flash-50.patch
@@ -0,0 +1,86 @@
+diff -aruN stm32flash.orig/dev_table.c stm32flash/dev_table.c
+--- stm32flash.orig/dev_table.c 2014-10-03 14:35:08.000000000 -0700
++++ stm32flash/dev_table.c 2015-02-02 17:25:20.752854394 -0800
+@@ -57,9 +57,10 @@
+ /* L0 */
+ {0x417, "L05xxx/06xxx" , 0x20001000, 0x20002000, 0x08000000, 0x08010000, 32, 128, 0x1FF80000, 0x1FF8000F, 0x1FF00000, 0x1FF01000},
+ /* L1 */
+- {0x416, "L1xxx6(8/B)" , 0x20000800, 0x20004000, 0x08000000, 0x08020000, 16, 256, 0x1FF80000, 0x1FF8000F, 0x1FF00000, 0x1FF01000},
+- {0x429, "L1xxx6(8/B)A" , 0x20001000, 0x20008000, 0x08000000, 0x08020000, 16, 256, 0x1FF80000, 0x1FF8000F, 0x1FF00000, 0x1FF01000},
+- {0x427, "L1xxxC" , 0x20001000, 0x20008000, 0x08000000, 0x08020000, 16, 256, 0x1FF80000, 0x1FF8000F, 0x1FF00000, 0x1FF02000},
++ {0x416, "Medium-density ULP", 0x20000800, 0x20004000, 0x08000000, 0x08020000, 16, 256, 0x1FF80000, 0x1FF8000F, 0x1FF00000, 0x1FF01000},
++ {0x429, "Medium-density ULP Shrink", 0x20000800, 0x20004000, 0x08000000, 0x08020000, 16, 256, 0x1FF80000, 0x1FF8000F, 0x1FF00000, 0x1FF01000},
++ {0x427, "Medium+-density ULP", 0x20001000, 0x20008000, 0x08000000, 0x08040000, 16, 256, 0x1FF80000, 0x1FF8000F, 0x1FF00000, 0x1FF01000},
++
+ {0x436, "L1xxxD" , 0x20001000, 0x2000C000, 0x08000000, 0x08060000, 16, 256, 0x1ff80000, 0x1ff8000F, 0x1FF00000, 0x1FF02000},
+ {0x437, "L1xxxE" , 0x20001000, 0x20014000, 0x08000000, 0x08060000, 16, 256, 0x1ff80000, 0x1ff8000F, 0x1FF00000, 0x1FF02000},
+ /* These are not (yet) in AN2606: */
+diff -aruN stm32flash.orig/stm32.c stm32flash/stm32.c
+--- stm32flash.orig/stm32.c 2014-10-02 00:20:26.000000000 -0700
++++ stm32flash/stm32.c 2015-02-02 17:25:20.752854394 -0800
+@@ -96,6 +96,7 @@
+ static const uint32_t stm_reset_code_length = sizeof(stm_reset_code);
+
+ extern const stm32_dev_t devices[];
++extern char reset_flag;
+
+ static void stm32_warn_stretching(const char *f)
+ {
+@@ -698,7 +699,16 @@
+ return STM32_ERR_OK;
+ }
+
+-stm32_err_t stm32_erase_memory(const stm32_t *stm, uint8_t spage, uint8_t pages)
++int supports_mass_erase(uint16_t chip_id)
++{
++ int retval = 1;
++ if(chip_id == 0x416 || chip_id == 0x417 || chip_id == 0x427 || chip_id == 0x429) {
++ retval = 0;
++ }
++ return retval;
++}
++
++stm32_err_t stm32_erase_memory(const stm32_t *stm, uint16_t spage, uint16_t pages)
+ {
+ struct port_interface *port = stm->port;
+ stm32_err_t s_err;
+@@ -725,8 +735,11 @@
+ /* Currently known as not supporting mass erase is the Ultra Low Power STM32L15xx range */
+ /* So if someone has not overridden the default, but uses one of these chips, take it out of */
+ /* mass erase mode, so it will be done page by page. This maximum might not be correct either! */
+- if (stm->pid == 0x416 && pages == 0xFF)
++
++ if (!supports_mass_erase(stm->pid) && pages == 0xFF) {
+ pages = 0xF8; /* works for the STM32L152RB with 128Kb flash */
++ reset_flag = 1; /* To mimic earlier behavior*/
++ }
+
+ if (pages == 0xFF) {
+ uint8_t buf[3];
+@@ -756,6 +769,12 @@
+ uint8_t *buf;
+ int i = 0;
+
++ if (pages == 0xF8) {
++ /* Erase the whole flash */
++ pages = (stm->dev->fl_end - stm->dev->fl_start) / stm->dev->fl_ps;
++ fprintf(stderr, "Erase 0x%x pages\n", pages);
++ }
++
+ buf = malloc(2 + 2 * pages + 1);
+ if (!buf)
+ return STM32_ERR_UNKNOWN;
+diff -aruN stm32flash.orig/stm32.h stm32flash/stm32.h
+--- stm32flash.orig/stm32.h 2014-10-02 00:20:26.000000000 -0700
++++ stm32flash/stm32.h 2015-02-02 17:25:20.752854394 -0800
+@@ -68,8 +68,8 @@
+ const uint8_t data[], unsigned int len);
+ stm32_err_t stm32_wunprot_memory(const stm32_t *stm);
+ stm32_err_t stm32_wprot_memory(const stm32_t *stm);
+-stm32_err_t stm32_erase_memory(const stm32_t *stm, uint8_t spage,
+- uint8_t pages);
++stm32_err_t stm32_erase_memory(const stm32_t *stm, uint16_t spage,
++ uint16_t pages);
+ stm32_err_t stm32_go(const stm32_t *stm, uint32_t address);
+ stm32_err_t stm32_reset_device(const stm32_t *stm);
+ stm32_err_t stm32_readprot_memory(const stm32_t *stm);
diff --git a/stm32flash.patches/stm32flash-51.patch b/stm32flash.patches/stm32flash-51.patch
new file mode 100644
index 0000000..b09b2e2
--- /dev/null
+++ b/stm32flash.patches/stm32flash-51.patch
@@ -0,0 +1,24 @@
+diff -aruN stm32flash/dev_table.c stm32flash_l4/dev_table.c
+--- stm32flash/dev_table.c 2016-03-08 10:55:19.183518329 -0800
++++ stm32flash_l4/dev_table.c 2016-03-04 14:19:45.997712775 -0800
+@@ -67,5 +67,7 @@
+ {0x641, "Medium_Density PL" , 0x20000200, 0x00005000, 0x08000000, 0x08020000, 4, 1024, 0x1FFFF800, 0x1FFFF80F, 0x1FFFF000, 0x1FFFF800},
+ {0x9a8, "STM32W-128K" , 0x20000200, 0x20002000, 0x08000000, 0x08020000, 1, 1024, 0, 0, 0, 0},
+ {0x9b0, "STM32W-256K" , 0x20000200, 0x20004000, 0x08000000, 0x08040000, 1, 2048, 0, 0, 0, 0},
++ /* STML431/33 */
++ {0x435, "L43xxC" , 0x20003100, 0x20010000, 0x08000000, 0x08040000, 64, 2048, 0x1FFF7800, 0x1FFF7810, 0x1FFF0000, 0x1FFf7000},
+ {0x0}
+ };
+diff -aruN stm32flash/stm32.c stm32flash_l4/stm32.c
+--- stm32flash/stm32.c 2016-03-08 10:55:19.183518329 -0800
++++ stm32flash_l4/stm32.c 2016-03-08 10:59:00.776754091 -0800
+@@ -702,7 +702,8 @@
+ int supports_mass_erase(uint16_t chip_id)
+ {
+ int retval = 1;
+- if(chip_id == 0x416 || chip_id == 0x417 || chip_id == 0x427 || chip_id == 0x429) {
++ if(chip_id == 0x416 || chip_id == 0x417 || chip_id == 0x427 || chip_id == 0x429
++ || chip_id == 0x435) {
+ retval = 0;
+ }
+ return retval;
diff --git a/stm32flash.patches/stm32flash-52.patch b/stm32flash.patches/stm32flash-52.patch
new file mode 100644
index 0000000..52b3bc8
--- /dev/null
+++ b/stm32flash.patches/stm32flash-52.patch
@@ -0,0 +1,53 @@
+diff -aruN stm32flash/stm32.c stm32flash_new/stm32.c
+--- stm32flash/stm32.c 2016-06-01 14:08:24.915895726 -0700
++++ stm32flash_new/stm32.c 2016-06-01 14:17:48.097561748 -0700
+@@ -93,6 +93,26 @@
+ 0x04, 0x00, 0xfa, 0x05 // .word 0x05fa0004 <AIRCR_RESET_VALUE> = VECTKEY | SYSRESETREQ
+ };
+
++/* Workaround for L433VC part, check the PEMPTY bit(0x20000) in FLASH_SR register, if it is set
++ clear it via writing 0x20000 to FLASH_SR so target will boot from flash on next reset */
++static const uint8_t stml433vc_reset_code[] = {
++ 0x07, 0x4B, // ldr r3 0x20003128 0x20003108 load FLASH_SR_ADDRESS to r3
++ 0x18, 0x68, // ldr r0, [r3] 0x2000310a load FLASH_SR reg to r0
++ 0x80, 0x22, // movs r2, #128 0x2000310c load 0x20000 to r2
++ 0x92, 0x02, // lsls r2, r2, #10 0x2000310e
++ 0x10, 0x40, // ands r0 r2 0x20003110 check 0x20000 in FLASH_SR reg
++ 0x00, 0xd0, // beq 0x20003116 0x20003112 if 0x20000 is set, set it again
++ 0x1a, 0x60, // str r2, [r3, #0] 0x20003114
++ 0x02, 0x49, // ldr r1, 0x20003120 ; 0x20003116 perform system reset via AIRCR
++ 0x02, 0x4A, // ldr r2, 0x20003124 ; 0x20003118
++ 0x0A, 0x60, // str r2, [r1] 0x2000311a
++ 0xfe, 0xe7, // endless: b endless 0x2000311c
++ 0x00, 0xbf, // nop 0x2000311e
++ 0x0c, 0xed, 0x00, 0xe0, // .word 0xe000ed0c <AIRCR_OFFSET> = NVIC AIRCR register address 0x20003120
++ 0x04, 0x00, 0xfa, 0x05, // .word 0x05fa0004 <AIRCR_RESET_VALUE> = VECTKEY | SYSRESETREQ 0x20003124
++ 0x10, 0x20, 0x02, 0x40, // .word 0x40022010 FLASH_SR_ADDRESS 0x20003128
++};
++
+ static const uint32_t stm_reset_code_length = sizeof(stm_reset_code);
+
+ extern const stm32_dev_t devices[];
+@@ -863,7 +883,9 @@
+ const uint8_t *code, uint32_t code_size)
+ {
+ uint32_t stack_le = le_u32(0x20002000);
+- uint32_t code_address_le = le_u32(target_address + 8);
++ /* Need to add 1 to target address to indicate thumb mode
++ because GO cmd uses BLX instruction to perform jump*/
++ uint32_t code_address_le = le_u32(target_address + 8 + 1);
+ uint32_t length = code_size + 8;
+ uint8_t *mem, *pos;
+ uint32_t address, w;
+@@ -930,7 +952,10 @@
+ {
+ uint32_t target_address = stm->dev->ram_start;
+
+- return stm32_run_raw_code(stm, target_address, stm_reset_code, stm_reset_code_length);
++ if (stm->dev->id == 0x435)
++ return stm32_run_raw_code(stm, target_address, stml433vc_reset_code, sizeof(stml433vc_reset_code));
++ else
++ return stm32_run_raw_code(stm, target_address, stm_reset_code, stm_reset_code_length);
+ }
+
+ stm32_err_t stm32_crc_memory(const stm32_t *stm, uint32_t address,
diff --git a/stm32flash.patches/stm32flash-53.patch b/stm32flash.patches/stm32flash-53.patch
new file mode 100644
index 0000000..0e65cc4
--- /dev/null
+++ b/stm32flash.patches/stm32flash-53.patch
@@ -0,0 +1,11 @@
+--- stm32flash/dev_table.c 2017-08-15 12:43:44.727882771 -0700
++++ stm32flash_new/dev_table.c 2017-08-29 10:08:16.700715014 -0700
+@@ -69,5 +69,8 @@
+ {0x9b0, "STM32W-256K" , 0x20000200, 0x20004000, 0x08000000, 0x08040000, 1, 2048, 0, 0, 0, 0},
+ /* STML431/33 */
+ {0x435, "L43xxC" , 0x20003100, 0x20010000, 0x08000000, 0x08040000, 64, 2048, 0x1FFF7800, 0x1FFF7810, 0x1FFF0000, 0x1FFf7000},
++ /* L4 */
++ {0x415, "STM32L476xx/486xx" , 0x20003100, 0x20018000, 0x08000000, 0x08100000, 1, 2048, 0x1FFF7800, 0x1FFFF80F, 0x1FFF0000, 0x1FFF7000, 0},
++ {0x435, "STM32L43xxx/44xxx" , 0x20003100, 0x2000C000, 0x08000000, 0x08100000, 1, 2048, 0x1FFF7800, 0x1FFFF80F, 0x1FFF0000, 0x1FFF7000, 0},
+ {0x0}
+ };
diff --git a/stm32flash.tar.gz b/stm32flash.tar.gz
new file mode 100644
index 0000000..b7ff44f
--- /dev/null
+++ b/stm32flash.tar.gz
Binary files differ
diff --git a/stm32flash.url b/stm32flash.url
new file mode 100644
index 0000000..deed025
--- /dev/null
+++ b/stm32flash.url
@@ -0,0 +1 @@
+http://releases.stm32flash.googlecode.com/git/stm32flash-0.4.tar.gz
diff --git a/stm32flash.version b/stm32flash.version
new file mode 100644
index 0000000..bd73f47
--- /dev/null
+++ b/stm32flash.version
@@ -0,0 +1 @@
+0.4