diff --git a/bsl.c b/bsl.c index 8dd5f5a..e8a0279 100644 --- a/bsl.c +++ b/bsl.c @@ -26,6 +26,7 @@ #include #include "device.h" +#include "util.h" static const struct fet_transport *trans; @@ -293,7 +294,26 @@ const struct device *fet_open_bl(const struct fet_transport *tr) return NULL; } + if (memcmp(buf, "\x06\x00\x24\x00\x00\x00\x61\x01", 8)) { + fprintf(stderr, "bsl: bootloader start returned error %d\n", + buf[5]); + return NULL; + } + usleep(500000); + /* Show chip info */ + if (bsl_xfer(CMD_TX_DATA, 0xff0, NULL, 0x10) < 0) { + fprintf(stderr, "bsl: failed to read chip info\n"); + return NULL; + } + + if (reply_len < 0x16) { + fprintf(stderr, "bsl: missing chip info\n"); + return NULL; + } + + print_devid((reply_buf[4] << 8) | reply_buf[5]); + printf("BSL version is %d.%02d\n", reply_buf[16], reply_buf[17]); return &bsl_device; } diff --git a/fet.c b/fet.c index fe3cd0c..5a8bac8 100644 --- a/fet.c +++ b/fet.c @@ -505,55 +505,8 @@ static int xfer(int command_code, const u_int8_t *data, int datalen, static int fet_version; -/* Reply data taken from uif430 */ -#define ID_REPLY_LEN 18 - -static const struct { - const u_int8_t reply[ID_REPLY_LEN]; - const char *idtext; -} id_table[] = { - { - .reply = {0xF2, 0x49, 0x02, 0x60, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x02, 0x02, 0x01, 0x00, 0xF3, 0x2B, - 0x80, 0x00}, - .idtext = "MSP430F249" - }, - { - .reply = {0xF1, 0x49, 0x00, 0x43, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x10, 0x00, 0x00, 0xF0, 0x1A, - 0x10, 0x00}, - .idtext = "MSP430F149" - }, - { - .reply = {0xF1, 0x6C, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, 0x61, 0x01, 0x00, 0xD1, 0x4D, - 0x80, 0x00}, - .idtext = "MSP430F1611" - }, - { - .reply = {0xf2, 0x27, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x02, 0x01, 0x01, 0x04, 0xb1, 0x62, - 0x80, 0x00}, - .idtext = "MSP430F2274" - }, - { - .reply = {0xf2, 0x27, 0x41, 0x40, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x02, 0x01, 0x01, 0x04, 0xb1, 0x61, - 0x80, 0x00}, - .idtext = "MSP430F2274" - }, - { - .reply = {0xf2, 0x01, 0x10, 0x40, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, - 0x00, 0x00}, - .idtext = "MSP430F20x3" - } -}; - static int do_identify(void) { - int i; - if (fet_version < 20300000) { char idtext[64]; @@ -561,34 +514,25 @@ static int do_identify(void) return -1; if (!fet_reply.data) { - fprintf(stderr, "do_indentify: missing info\n"); + fprintf(stderr, "fet: missing info\n"); return -1; } memcpy(idtext, fet_reply.data + 4, 32); idtext[32] = 0; - printf("Device is %s\n", idtext); + printf("Device: %s\n", idtext); return 0; } if (xfer(0x28, NULL, 0, 2, 0, 0) < 0) return -1; - if (!fet_reply.data) { - fprintf(stderr, "do_indentify: missing info\n"); + if (fet_reply.datalen < 2) { + fprintf(stderr, "fet: missing info\n"); return -1; } - if (fet_reply.datalen >= ID_REPLY_LEN) - for (i = 0; i < ARRAY_LEN(id_table); i++) - if (!memcmp(id_table[i].reply, fet_reply.data, - ID_REPLY_LEN)) { - printf("Device is %s\n", id_table[i].idtext); - return 0; - } - - printf("warning: unknown device data:\n"); - hexdump(0, fet_reply.data, fet_reply.datalen); + print_devid((fet_reply.data[0] << 8) | fet_reply.data[1]); return 0; } diff --git a/uif.c b/uif.c index c93fdf4..1246331 100644 --- a/uif.c +++ b/uif.c @@ -81,12 +81,12 @@ static int serial_recv(u_int8_t *data, int max_len) r = read(serial_fd, data, max_len); if (r < 0 && errno != EINTR) { - perror("bls: read error"); + perror("uif: read error"); return -1; } if (!r) { - fprintf(stderr, "bls: read timeout\n"); + fprintf(stderr, "uif: read timeout\n"); return -1; } } while (r <= 0); diff --git a/util.c b/util.c index 78798bc..66b967b 100644 --- a/util.c +++ b/util.c @@ -49,3 +49,27 @@ void hexdump(int addr, const u_int8_t *data, int len) offset += i; } } + +static struct { + u_int16_t id; + const char *id_text; +} id_table[] = { + {0xF249, "MSP430F249"}, + {0xF149, "MSP430F149"}, + {0xF16C, "MSP430F1611"}, + {0xF227, "MSP430F2274"}, + {0xF201, "MSP430F20x3"} +}; + +void print_devid(u_int16_t id) +{ + int i = 0; + + while (i < ARRAY_LEN(id_table) && id_table[i].id != id) + i++; + + if (i < ARRAY_LEN(id_table)) + printf("Device: %s\n", id_table[i].id_text); + else + printf("Unknown device ID: 0x%04x\n", id); +} diff --git a/util.h b/util.h index 310f7a3..491dff5 100644 --- a/util.h +++ b/util.h @@ -25,4 +25,6 @@ void hexdump(int addr, const u_int8_t *data, int len); #define ARRAY_LEN(a) (sizeof(a) / sizeof((a)[0])) +void print_devid(const u_int16_t id); + #endif