From: Fabien Le Mentec Date: Sun, 16 Oct 2011 20:36:11 +0000 (-0500) Subject: [add] flash memory loader tool X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=c16a18e5b3e578589f7aa52c2119982e20eb0975;hp=3c37fb68f5a7e1f3be93cc48c7e04f356a0842a8;p=fw%2Fstlink [add] flash memory loader tool --- diff --git a/flash/Makefile b/flash/Makefile new file mode 100644 index 0000000..fe0dff7 --- /dev/null +++ b/flash/Makefile @@ -0,0 +1,28 @@ +CFLAGS+=-g +CFLAGS+=-DCONFIG_USE_LIBUSB +CFLAGS+=-DCONFIG_USE_LIBSG +CFLAGS+=-DDEBUG +CFLAGS+=-std=gnu99 +CFLAGS+=-Wall -Wextra +CFLAGS+=-I../src + +LDFLAGS=-L.. -lstlink -lusb-1.0 -lsgutils2 + +SRCS=main.c +OBJS=$(SRCS:.c=.o) + +NAME=flash + +all: $(NAME) + +$(NAME): $(OBJS) + $(CC) $(CFLAGS) -o $(NAME) $(OBJS) $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) -c $^ -o $@ + +clean: + rm -f $(OBJS) + rm -f $(NAME) + +.PHONY: clean all diff --git a/flash/main.c b/flash/main.c new file mode 100644 index 0000000..c8b15e0 --- /dev/null +++ b/flash/main.c @@ -0,0 +1,51 @@ +/* simple wrapper around the stlink_flash_write function */ + + +#include +#include +#include "stlink-common.h" + + +int main(int ac, char** av) +{ + /* stlinkv1 command line: ./flash /dev/sgX path addr */ + /* stlinkv2 command line: ./flash path addr */ + + stlink_t* sl = NULL; + stm32_addr_t addr; + const char* path; + int err; + + if (ac == 4) /* stlinkv1 */ + { + static const int scsi_verbose = 2; + sl = stlink_quirk_open(av[1], scsi_verbose); + path = av[2]; + addr = strtoul(av[3], NULL, 16); + } + else if (ac == 3) /* stlinkv2 */ + { + sl = stlink_open_usb(NULL, 10); + path = av[1]; + addr = strtoul(av[2], NULL, 16); + } + else /* invalid */ + { + printf("invalid command line\n"); + goto on_error; + } + + if (sl == NULL) goto on_error; + + err = stlink_fwrite_flash(sl, path, addr); + if (err == -1) + { + printf("stlink_fwrite_flash() == -1\n"); + goto on_error; + } + + on_error: + if (sl != NULL) stlink_close(sl); + + return err; +}