Skip to content

Commit

Permalink
build with mingw
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterMute committed Apr 29, 2012
1 parent 414ca99 commit 7ed5be2
Show file tree
Hide file tree
Showing 6 changed files with 365 additions and 27 deletions.
6 changes: 3 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ bin_PROGRAMS = st-flash st-util
noinst_LIBRARIES = libstlink.a

st_flash_SOURCES = flash/main.c
st_util_SOURCES = gdbserver/gdb-remote.c gdbserver/gdb-remote.h gdbserver/gdb-server.c
st_util_SOURCES = gdbserver/gdb-remote.c gdbserver/gdb-remote.h gdbserver/gdb-server.c mingw/mingw.c mingw/mingw.h

CFILES = \
src/stlink-common.c \
Expand All @@ -28,10 +28,10 @@ libstlink_a_CPPFLAGS = -std=gnu99 -Wall -Wextra -O2
libstlink_a_LIBADD = $(LIBOBJS)

st_flash_LDADD = libstlink.a
st_flash_CPPFLAGS = -std=gnu99 -Wall -Wextra -O2 -I$(top_srcdir)/src
st_flash_CPPFLAGS = -std=gnu99 -Wall -Wextra -O2 -I$(top_srcdir)/src -I$(top_srcdir)/mingw

st_util_LDADD = libstlink.a
st_util_CPPFLAGS = -std=gnu99 -Wall -Wextra -O2 -I$(top_srcdir)/src
st_util_CPPFLAGS = -std=gnu99 -Wall -Wextra -O2 -I$(top_srcdir)/src -I$(top_srcdir)/mingw

EXTRA_DIST = autogen.sh

7 changes: 6 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ AC_PROG_INSTALL
AC_CANONICAL_HOST
AC_CANONICAL_BUILD
AC_PROG_RANLIB
#AC_PROG_LIBTOOL
AM_PROG_CC_C_O

AC_CHECK_HEADERS(sys/mman.h)
AC_CHECK_HEADERS(sys/poll.h)
AC_CHECK_FUNCS(mmap)
AC_REPLACE_FUNCS(mmap pread)

Expand All @@ -29,6 +29,11 @@ AC_CHECK_LIB([usbpath],[usb_path2devnum],,,-lusb)
LIBS="$LIBS $USB_LIBS"
CFLAGS="$CFLAGS $USB_CFLAGS"

case "${host}" in
*-mingw32*)
LIBS="$LIBS -lws2_32"
;;
esac
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

6 changes: 5 additions & 1 deletion gdbserver/gdb-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#ifdef __MINGW32__
#include "mingw.h"
#else
#include <sys/poll.h>
#endif

static const char hex[] = "0123456789abcdef";

Expand All @@ -24,7 +28,7 @@ int gdb_send_packet(int fd, char* data) {
packet[0] = '$';

uint8_t cksum = 0;
for(int i = 0; i < strlen(data); i++) {
for(unsigned int i = 0; i < strlen(data); i++) {
packet[i + 1] = data[i];
cksum += data[i];
}
Expand Down
49 changes: 27 additions & 22 deletions gdbserver/gdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#ifdef __MINGW32__
#include "mingw.h"
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <signal.h>
#endif

#include <stlink-common.h>

Expand Down Expand Up @@ -203,15 +207,15 @@ static const char* const memory_map_template =
"<!DOCTYPE memory-map PUBLIC \"+//IDN gnu.org//DTD GDB Memory Map V1.0//EN\""
" \"http://sourceware.org/gdb/gdb-memory-map.dtd\">"
"<memory-map>"
" <memory type=\"rom\" start=\"0x00000000\" length=\"0x%x\"/>" // code = sram, bootrom or flash; flash is bigger
" <memory type=\"ram\" start=\"0x20000000\" length=\"0x%x\"/>" // sram 8k
" <memory type=\"flash\" start=\"0x08000000\" length=\"0x%x\">"
" <property name=\"blocksize\">0x%x</property>"
" <memory type=\"rom\" start=\"0x00000000\" length=\"0x%zx\"/>" // code = sram, bootrom or flash; flash is bigger
" <memory type=\"ram\" start=\"0x20000000\" length=\"0x%zx\"/>" // sram 8k
" <memory type=\"flash\" start=\"0x08000000\" length=\"0x%zx\">"
" <property name=\"blocksize\">0x%zx</property>"
" </memory>"
" <memory type=\"ram\" start=\"0x40000000\" length=\"0x1fffffff\"/>" // peripheral regs
" <memory type=\"ram\" start=\"0xe0000000\" length=\"0x1fffffff\"/>" // cortex regs
" <memory type=\"rom\" start=\"0x%08x\" length=\"0x%x\"/>" // bootrom
" <memory type=\"rom\" start=\"0x1ffff800\" length=\"0x8\"/>" // option byte area
" <memory type=\"rom\" start=\"0x%08x\" length=\"0x%zx\"/>" // bootrom
" <memory type=\"rom\" start=\"0x1ffff800\" length=\"0x8x\"/>" // option byte area
"</memory-map>";

char* make_memory_map(stlink_t *sl) {
Expand Down Expand Up @@ -291,7 +295,7 @@ static int add_data_watchpoint(stlink_t *sl, enum watchfun wf, stm32_addr_t addr
mask++;
}

if((mask != -1) && (mask < 16)) {
if((mask != (uint32_t)-1) && (mask < 16)) {
for(i = 0; i < DATA_WATCH_NUM; i++) {
// is this an empty slot ?
if(data_watches[i].fun == WATCHDISABLED) {
Expand Down Expand Up @@ -461,7 +465,7 @@ static int flash_add_block(stm32_addr_t addr, unsigned length, stlink_t *sl) {
}

static int flash_populate(stm32_addr_t addr, uint8_t* data, unsigned length) {
int fit_blocks = 0, fit_length = 0;
unsigned int fit_blocks = 0, fit_length = 0;

for(struct flash_block* fb = flash_root; fb; fb = fb->next) {
/* Block: ------X------Y--------
Expand Down Expand Up @@ -553,7 +557,8 @@ int serve(stlink_t *sl, int port) {
unsigned int val = 1;
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));

struct sockaddr_in serv_addr = {0};
struct sockaddr_in serv_addr;
bzero(&serv_addr,sizeof(struct sockaddr_in));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
serv_addr.sin_port = htons(port);
Expand All @@ -576,7 +581,7 @@ int serve(stlink_t *sl, int port) {
printf("Listening at *:%d...\n", port);

int client = accept(sock, NULL, NULL);
signal (SIGINT, SIG_DFL);
//signal (SIGINT, SIG_DFL);
if(client < 0) {
perror("accept");
return 1;
Expand Down Expand Up @@ -633,17 +638,17 @@ int serve(stlink_t *sl, int port) {
if(!strcmp(queryName, "Supported")) {
reply = strdup("PacketSize=3fff;qXfer:memory-map:read+");
} else if(!strcmp(queryName, "Xfer")) {
char *type, *op, *s_addr, *s_length;
char *type, *op, *__s_addr, *s_length;
char *tok = params;
char *annex __attribute__((unused));

type = strsep(&tok, ":");
op = strsep(&tok, ":");
annex = strsep(&tok, ":");
s_addr = strsep(&tok, ",");
__s_addr = strsep(&tok, ",");
s_length = tok;

unsigned addr = strtoul(s_addr, NULL, 16),
unsigned addr = strtoul(__s_addr, NULL, 16),
length = strtoul(s_length, NULL, 16);

#ifdef DEBUG
Expand Down Expand Up @@ -729,13 +734,13 @@ int serve(stlink_t *sl, int port) {
cmdName++; // vCommand -> Command

if(!strcmp(cmdName, "FlashErase")) {
char *s_addr, *s_length;
char *__s_addr, *s_length;
char *tok = params;

s_addr = strsep(&tok, ",");
__s_addr = strsep(&tok, ",");
s_length = tok;

unsigned addr = strtoul(s_addr, NULL, 16),
unsigned addr = strtoul(__s_addr, NULL, 16),
length = strtoul(s_length, NULL, 16);

#ifdef DEBUG
Expand All @@ -749,21 +754,21 @@ int serve(stlink_t *sl, int port) {
reply = strdup("OK");
}
} else if(!strcmp(cmdName, "FlashWrite")) {
char *s_addr, *data;
char *__s_addr, *data;
char *tok = params;

s_addr = strsep(&tok, ":");
__s_addr = strsep(&tok, ":");
data = tok;

unsigned addr = strtoul(s_addr, NULL, 16);
unsigned addr = strtoul(__s_addr, NULL, 16);
unsigned data_length = status - (data - packet);

// Length of decoded data cannot be more than
// encoded, as escapes are removed.
// Additional byte is reserved for alignment fix.
uint8_t *decoded = calloc(data_length + 1, 1);
unsigned dec_index = 0;
for(int i = 0; i < data_length; i++) {
for(unsigned int i = 0; i < data_length; i++) {
if(data[i] == 0x7d) {
i++;
decoded[dec_index++] = data[i] ^ 0x20;
Expand Down Expand Up @@ -919,7 +924,7 @@ int serve(stlink_t *sl, int port) {
count : count + 4 - (count % 4));

reply = calloc(count * 2 + 1, 1);
for(int i = 0; i < count; i++) {
for(unsigned int i = 0; i < count; i++) {
reply[i * 2 + 0] = hex[sl->q_buf[i + adj_start] >> 4];
reply[i * 2 + 1] = hex[sl->q_buf[i + adj_start] & 0xf];
}
Expand All @@ -935,7 +940,7 @@ int serve(stlink_t *sl, int port) {
stm32_addr_t start = strtoul(s_start, NULL, 16);
unsigned count = strtoul(s_count, NULL, 16);

for(int i = 0; i < count; i ++) {
for(unsigned int i = 0; i < count; i ++) {
char hex[3] = { hexdata[i*2], hexdata[i*2+1], 0 };
uint8_t byte = strtoul(hex, NULL, 16);
sl->q_buf[i] = byte;
Expand Down
Loading

0 comments on commit 7ed5be2

Please sign in to comment.