From 1f62fa4909940639faf8cb24e839a49668f1707d Mon Sep 17 00:00:00 2001 From: Clement Burin des Roziers Date: Fri, 31 Oct 2014 14:50:22 +0100 Subject: [PATCH 1/5] CRC32: improved computation time Reading one byte at a time was so slow that it caused the gdb client to timeout. --- src/crc32.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/crc32.c b/src/crc32.c index 6f1c0e3..16cc565 100644 --- a/src/crc32.c +++ b/src/crc32.c @@ -97,13 +97,19 @@ uint32_t crc32_calc(uint32_t crc, uint8_t data) uint32_t generic_crc32(target *t, uint32_t base, int len) { uint32_t crc = -1; - uint8_t byte; + static uint8_t bytes[128]; - while (len--) { - byte = target_mem_read8(t, base); + while (len) { + uint32_t i; + uint32_t read_len = len >= 128 ? 128 : len; - crc = crc32_calc(crc, byte); - base++; + target_mem_read(t, bytes, base, read_len); + + for (i=0; i Date: Tue, 1 Dec 2015 11:45:37 +0100 Subject: [PATCH 2/5] flashstub: factor Makefile rules Use target-specific variables --- flashstub/Makefile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/flashstub/Makefile b/flashstub/Makefile index f6c6738..031bf41 100644 --- a/flashstub/Makefile +++ b/flashstub/Makefile @@ -13,15 +13,10 @@ ASFLAGS=-mcpu=cortex-m3 -mthumb all: lmi.stub stm32f4.stub stm32l4.stub nrf51.stub stm32f1.stub -stm32f1.o: stm32f1.c - $(Q)echo " CC $<" - $(Q)$(CC) $(CFLAGS) -DSTM32F1 -o $@ -c $< +stm32f1.o: CFLAGS += -DSTM32F1 +stm32f4.o: CFLAGS += -DSTM32F4 -stm32f4.o: stm32f4.c - $(Q)echo " CC $<" - $(Q)$(CC) $(CFLAGS) -DSTM32F4 -o $@ -c $< - -stm32l4.o: stm32l4.c +%.o: %.c $(Q)echo " CC $<" $(Q)$(CC) $(CFLAGS) -o $@ -c $< From 1e5c053f4feaeb87cc5920e1cedf262a3aac1795 Mon Sep 17 00:00:00 2001 From: Laurent Bonnans Date: Tue, 1 Dec 2015 11:48:34 +0100 Subject: [PATCH 3/5] flashstub: build efm32.stub with makefile --- flashstub/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flashstub/Makefile b/flashstub/Makefile index 031bf41..a18cd23 100644 --- a/flashstub/Makefile +++ b/flashstub/Makefile @@ -11,7 +11,7 @@ endif CFLAGS=-Os -std=gnu99 -mcpu=cortex-m0 -mthumb -I../libopencm3/include ASFLAGS=-mcpu=cortex-m3 -mthumb -all: lmi.stub stm32f4.stub stm32l4.stub nrf51.stub stm32f1.stub +all: lmi.stub stm32f4.stub stm32l4.stub nrf51.stub stm32f1.stub efm32.stub stm32f1.o: CFLAGS += -DSTM32F1 stm32f4.o: CFLAGS += -DSTM32F4 From 2d7b24c566ae7285c4311a6e24c35008ff942fce Mon Sep 17 00:00:00 2001 From: Laurent Bonnans Date: Wed, 9 Dec 2015 14:12:24 +0100 Subject: [PATCH 4/5] efm32: inhibit srst EFM32s don't seem to like to be completely resetted while being debugged (load and break were broken) --- src/efm32.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/efm32.c b/src/efm32.c index 9fb499d..25bb3f2 100644 --- a/src/efm32.c +++ b/src/efm32.c @@ -334,6 +334,7 @@ bool efm32_probe(target *t) uint32_t ram_size = efm32_read_ram_size(t) * 0x400; /* Setup Target */ + t->target_options |= CORTEXM_TOPT_INHIBIT_SRST; t->driver = variant_string; gdb_outf("flash size %d page size %d\n", flash_size, flash_page_size); target_add_ram (t, SRAM_BASE, ram_size); From c9d3cf71ddb2ad520b44520b178a0304d747e102 Mon Sep 17 00:00:00 2001 From: Laurent Bonnans Date: Mon, 14 Dec 2015 11:02:48 +0100 Subject: [PATCH 5/5] gdb_main.c: fix buffer overflow on large reads When gdb issues a `m xx,200` command, the probe should respond with a packet of size 2*0x200=1024 which is the size of the packet buffer. However, the `hexify()` procedures writes 1025 bytes in the buffer. During my tests, it caused the probe to hang when issuing a `dump` command. Presumably by overwritting the `cur_target` variable. --- src/gdb_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gdb_main.c b/src/gdb_main.c index 6b2059f..cec5822 100644 --- a/src/gdb_main.c +++ b/src/gdb_main.c @@ -41,7 +41,7 @@ #define ERROR_IF_NO_TARGET() \ if(!cur_target) { gdb_putpacketz("EFF"); break; } -static char pbuf[BUF_SIZE]; +static char pbuf[BUF_SIZE+1]; static target *cur_target; static target *last_target;