mini-jtag: include ../Makefile.common, fix some warnings

This commit is contained in:
Xiangfu 2012-09-24 14:31:17 +08:00
parent 5f5c4da087
commit b764969a2b
3 changed files with 22 additions and 70 deletions

View File

@ -5,42 +5,23 @@
# For details see the UNLICENSE file at the root of the source tree.
#
PREFIX ?= /usr/local
CFLAGS += -g
LDLIBS += `pkg-config libftdi --libs`
OBJS = mini-jtag.o load-bits.o jtag.o
OBJS := mini-jtag.o load-bits.o jtag.o
# ----- Verbosity control -----------------------------------------------------
CC_normal := $(CC)
BUILD_normal :=
DEPEND_normal := $(CPP) $(CFLAGS) -D__OPTIMIZE__ -MM -MG
CC_quiet = @echo " CC " $@ && $(CC_normal)
BUILD_quiet = @echo " BUILD " $@ && $(BUILD_normal)
DEPEND_quiet = @$(DEPEND_normal)
ifeq ($(V),1)
CC = $(CC_normal)
BUILD = $(BUILD_normal)
DEPEND = $(DEPEND_normal)
else
CC = $(CC_quiet)
BUILD = $(BUILD_quiet)
DEPEND = $(DEPEND_quiet)
endif
# ----- Rules -----------------------------------------------------------------
.PHONY: all clean
.PHONY: install uninstall
.PHONY: all clean
.PHONY: install uninstall
all: mini-jtag
include ../Makefile.common
mini-jtag: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LDLIBS)
%.o: %.c
$(CC) $(CFLAGS) -o $@ -c $<
$(MKDEP)
install: all
mkdir -p $(DESTDIR)/$(PREFIX)/bin/
install -m 755 mini-jtag $(DESTDIR)/$(PREFIX)/bin/
@ -53,26 +34,6 @@ clean:
rm -f $(OBJS:.o=.d)
rm -f mini-jtag
# ----- Dependencies ----------------------------------------------------------
MKDEP = \
$(DEPEND) $< | \
sed \
-e 's|^$(basename $(notdir $<)).o:|$@:|' \
-e '/^\(.*:\)\? */{p;s///;s/ *\\\?$$/ /;s/ */:\n/g;H;}' \
-e '$${g;p;}' \
-e d >$(basename $@).d; \
[ "$${PIPESTATUS[*]}" = "0 0" ] || \
{ rm -f $(basename $@).d; exit 1; }
%.o: %.c
$(CC) $(CFLAGS) -o $@ -c $<
@$(MKDEP)
-include $(OBJS:.o=.d)
# ----- Test -------------------------------------------------------------------
%.bit:
wget -O $@ http://downloads.qi-hardware.com/people/xiangfu/mini-slx9/firmware/$@ || { rm -f $@; exit 1; }

View File

@ -16,7 +16,7 @@
int tap_tms(struct ftdi_context *ftdi, int tms, uint8_t bit7)
{
char buf[3];
uint8_t buf[3];
buf[0] = MPSSE_WRITE_TMS|MPSSE_LSB|MPSSE_BITMODE|MPSSE_WRITE_NEG;
buf[1] = 0; /* value = lenght - 1 */
buf[2] = (tms ? 0x01 : 0x00) | ((bit7 & 0x01) << 7);
@ -102,12 +102,11 @@ int tap_shift_dr_bits(struct ftdi_context *ftdi,
uint8_t *out)
{
/* Have to be at RTI status before call this function */
uint8_t buf[3];
uint8_t *buf_bytes;
uint8_t buf_bytes[FTDI_MAX_RW_SIZE + 3];
uint32_t in_bytes = 0;
uint32_t last_bits = 0;
uint16_t last_bytes, len, len_pre;
uint16_t last_bytes, len;
int i, t;
/* Send 3 Clocks with TMS = 1 0 0 to reach SHIFTDR*/
@ -126,14 +125,6 @@ int tap_shift_dr_bits(struct ftdi_context *ftdi,
for (i = 0; i <= t; i++) {
len = (i == t) ? last_bytes : FTDI_MAX_RW_SIZE;
buf_bytes = malloc(len * sizeof(uint8_t) + 3);
if (!buf_bytes) {
fprintf(stderr,
"Can't malloc memory\n");
return -1;
}
memset(buf_bytes, 0, len + 3);
buf_bytes[0] = MPSSE_LSB|MPSSE_WRITE_NEG;
if (in)
@ -146,20 +137,16 @@ int tap_shift_dr_bits(struct ftdi_context *ftdi,
buf_bytes[2] = ((len - 1) >> 8) & 0xff;
if (in)
memcpy(&buf_bytes[3], (in + i * len_pre), len);
memcpy(&buf_bytes[3], (in + i * FTDI_MAX_RW_SIZE), len);
if (ftdi_write_data(ftdi, buf_bytes, len + 3) != len + 3) {
fprintf(stderr,
"Ftdi write failed\n");
free(buf_bytes);
return -1;
}
if (out)
ftdi_read_data(ftdi, (out + i * len), len);
len_pre = len;
free(buf_bytes);
ftdi_read_data(ftdi, (out + i * FTDI_MAX_RW_SIZE), len);
}
}
@ -178,7 +165,7 @@ int tap_shift_dr_bits(struct ftdi_context *ftdi,
int ft232_flush(struct ftdi_context *ftdi)
{
char buf[1] = { SEND_IMMEDIATE };
uint8_t buf[1] = { SEND_IMMEDIATE };
if (ftdi_write_data(ftdi, buf, 1) != 1) {
fprintf(stderr,
"Can't SEND_IMMEDIATE\n");

View File

@ -124,6 +124,7 @@ int main(int argc, char **argv)
tap_reset_rti(&ftdi);
}
/* TODO: Fix not working with m1 */
if (!strcmp (argv[1], "load")) {
if(argc < 3) {
usage(argv[0]);
@ -160,7 +161,12 @@ int main(int argc, char **argv)
printf("\tBitstream length: %d\n", bs->length);
/* copy data into shift register */
dr_data = malloc(bs->length * sizeof(char));
dr_data = malloc(bs->length * sizeof(uint8_t));
if (!dr_data) {
perror("memory allocation failed");
goto free_bs;
}
for (u = 0; u < bs->length; u++) {
/* flip bits */
dr_data[u] |= ((bs->data[u] & 0x80) ? 1 : 0) << 0;
@ -187,7 +193,6 @@ int main(int argc, char **argv)
tap_reset_rti(&ftdi);
free_dr:
free(dr_data);
free_bs:
bits_free(bs);
@ -258,7 +263,6 @@ int main(int argc, char **argv)
}
if (!strcmp(argv[1], "write") && argc == 4) {
int i;
uint8_t addr, checksum;
uint8_t in[5];
uint32_t value;