2010-01-08 05:39:07 +00:00
|
|
|
/* MSPDebug - debugging tool for the eZ430
|
2010-01-08 08:17:24 +00:00
|
|
|
* Copyright (C) 2009, 2010 Daniel Beer
|
2010-01-08 05:39:07 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2010-04-30 04:01:03 +00:00
|
|
|
#include <stdlib.h>
|
2010-01-08 05:39:07 +00:00
|
|
|
#include <string.h>
|
2010-05-13 00:57:21 +00:00
|
|
|
#include <stdint.h>
|
2010-01-08 05:39:07 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
#include "bsl.h"
|
2010-01-08 07:19:53 +00:00
|
|
|
#include "util.h"
|
2010-08-16 23:07:03 +00:00
|
|
|
#include "output.h"
|
2010-05-15 01:44:46 +00:00
|
|
|
#include "fet_error.h"
|
2011-07-26 23:26:02 +00:00
|
|
|
#include "sport.h"
|
2010-05-25 23:17:45 +00:00
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
struct bsl_device {
|
|
|
|
struct device base;
|
|
|
|
|
2011-07-26 23:26:02 +00:00
|
|
|
sport_t serial_fd;
|
2010-05-25 23:17:45 +00:00
|
|
|
uint8_t reply_buf[256];
|
2010-04-30 04:01:03 +00:00
|
|
|
int reply_len;
|
|
|
|
};
|
2010-01-08 05:39:07 +00:00
|
|
|
|
|
|
|
#define DATA_HDR 0x80
|
|
|
|
#define DATA_ACK 0x90
|
|
|
|
#define DATA_NAK 0xA0
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
static int bsl_ack(struct bsl_device *dev)
|
2010-01-08 05:39:07 +00:00
|
|
|
{
|
2010-05-13 00:57:21 +00:00
|
|
|
uint8_t reply;
|
2010-01-08 05:39:07 +00:00
|
|
|
|
2011-07-26 23:26:02 +00:00
|
|
|
if (sport_read(dev->serial_fd, &reply, 1) < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: failed to receive reply\n");
|
2010-01-08 05:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reply == DATA_NAK) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: received NAK\n");
|
2010-01-08 05:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reply != DATA_ACK) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: bad ack character: %x\n", reply);
|
2010-01-08 05:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
static int bsl_sync(struct bsl_device *dev)
|
2010-01-08 05:39:07 +00:00
|
|
|
{
|
2010-05-13 00:57:21 +00:00
|
|
|
static const uint8_t c = DATA_HDR;
|
2010-01-08 05:39:07 +00:00
|
|
|
int tries = 2;
|
|
|
|
|
2011-07-26 23:26:02 +00:00
|
|
|
if (sport_flush(dev->serial_fd) < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
pr_error("bsl: tcflush");
|
2010-01-11 03:54:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-01-08 05:39:07 +00:00
|
|
|
|
|
|
|
while (tries--)
|
2011-07-26 23:26:02 +00:00
|
|
|
if (!(sport_write_all(dev->serial_fd, &c, 1) || bsl_ack(dev)))
|
2010-01-08 05:39:07 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: sync failed\n");
|
2010-01-08 05:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
static int send_command(struct bsl_device *dev,
|
2010-05-13 00:57:21 +00:00
|
|
|
int code, uint16_t addr,
|
|
|
|
const uint8_t *data, int len)
|
2010-01-08 05:39:07 +00:00
|
|
|
{
|
2010-05-13 00:57:21 +00:00
|
|
|
uint8_t pktbuf[256];
|
|
|
|
uint8_t cklow = 0xff;
|
|
|
|
uint8_t ckhigh = 0xff;
|
2010-01-08 05:39:07 +00:00
|
|
|
int pktlen = data ? len + 4 : 4;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (pktlen + 6 > sizeof(pktbuf)) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: payload too large: %d\n", len);
|
2010-01-08 05:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pktbuf[0] = DATA_HDR;
|
|
|
|
pktbuf[1] = code;
|
|
|
|
pktbuf[2] = pktlen;
|
|
|
|
pktbuf[3] = pktlen;
|
|
|
|
pktbuf[4] = addr & 0xff;
|
|
|
|
pktbuf[5] = addr >> 8;
|
|
|
|
pktbuf[6] = len & 0xff;
|
|
|
|
pktbuf[7] = len >> 8;
|
|
|
|
|
|
|
|
if (data)
|
|
|
|
memcpy(pktbuf + 8, data, len);
|
|
|
|
|
|
|
|
for (i = 0; i < pktlen + 4; i += 2)
|
|
|
|
cklow ^= pktbuf[i];
|
|
|
|
for (i = 1; i < pktlen + 4; i += 2)
|
|
|
|
ckhigh ^= pktbuf[i];
|
|
|
|
|
|
|
|
pktbuf[pktlen + 4] = cklow;
|
|
|
|
pktbuf[pktlen + 5] = ckhigh;
|
|
|
|
|
2011-07-26 23:26:02 +00:00
|
|
|
return sport_write_all(dev->serial_fd, pktbuf, pktlen + 6);
|
2010-01-08 05:39:07 +00:00
|
|
|
}
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
static int verify_checksum(struct bsl_device *dev)
|
2010-01-08 05:39:07 +00:00
|
|
|
{
|
2010-05-13 00:57:21 +00:00
|
|
|
uint8_t cklow = 0xff;
|
|
|
|
uint8_t ckhigh = 0xff;
|
2010-01-08 05:39:07 +00:00
|
|
|
int i;
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
for (i = 0; i < dev->reply_len; i += 2)
|
|
|
|
cklow ^= dev->reply_buf[i];
|
|
|
|
for (i = 1; i < dev->reply_len; i += 2)
|
|
|
|
ckhigh ^= dev->reply_buf[i];
|
2010-01-08 05:39:07 +00:00
|
|
|
|
|
|
|
if (cklow || ckhigh) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: checksum invalid (%02x %02x)\n",
|
2010-01-08 05:39:07 +00:00
|
|
|
cklow, ckhigh);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
static int fetch_reply(struct bsl_device *dev)
|
2010-01-08 05:39:07 +00:00
|
|
|
{
|
2010-04-30 04:01:03 +00:00
|
|
|
dev->reply_len = 0;
|
2010-01-08 05:39:07 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2011-07-26 23:26:02 +00:00
|
|
|
int r = sport_read(dev->serial_fd,
|
|
|
|
dev->reply_buf + dev->reply_len,
|
|
|
|
sizeof(dev->reply_buf) -
|
|
|
|
dev->reply_len);
|
2010-01-08 05:39:07 +00:00
|
|
|
|
|
|
|
if (r < 0)
|
|
|
|
return -1;
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
dev->reply_len += r;
|
2010-01-08 05:39:07 +00:00
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
if (dev->reply_buf[0] == DATA_ACK) {
|
2010-01-08 05:39:07 +00:00
|
|
|
return 0;
|
2010-04-30 04:01:03 +00:00
|
|
|
} else if (dev->reply_buf[0] == DATA_HDR) {
|
|
|
|
if (dev->reply_len >= 6 &&
|
|
|
|
dev->reply_len == dev->reply_buf[2] + 6)
|
|
|
|
return verify_checksum(dev);
|
|
|
|
} else if (dev->reply_buf[0] == DATA_NAK) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: received NAK\n");
|
2010-01-08 05:39:07 +00:00
|
|
|
return -1;
|
|
|
|
} else {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: unknown reply type: %02x\n",
|
2010-04-30 04:01:03 +00:00
|
|
|
dev->reply_buf[0]);
|
2010-01-08 05:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
if (dev->reply_len >= sizeof(dev->reply_buf)) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: reply buffer overflow\n");
|
2010-01-08 05:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
static int bsl_xfer(struct bsl_device *dev,
|
2010-05-13 00:57:21 +00:00
|
|
|
int command_code, uint16_t addr, const uint8_t *txdata,
|
2010-01-08 05:39:07 +00:00
|
|
|
int len)
|
|
|
|
{
|
2010-04-30 04:01:03 +00:00
|
|
|
if (bsl_sync(dev) < 0 ||
|
|
|
|
send_command(dev, command_code, addr, txdata, len) < 0 ||
|
|
|
|
fetch_reply(dev) < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: failed on command 0x%02x "
|
2010-01-08 05:39:07 +00:00
|
|
|
"(addr = 0x%04x, len = 0x%04x)\n",
|
|
|
|
command_code, addr, len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CMD_TX_DATA 0x38
|
|
|
|
#define CMD_ERASE 0x39
|
|
|
|
#define CMD_RX_DATA 0x3a
|
|
|
|
#define CMD_RESET 0x3b
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
static void bsl_destroy(device_t dev_base)
|
2010-01-08 05:39:07 +00:00
|
|
|
{
|
2010-04-30 04:01:03 +00:00
|
|
|
struct bsl_device *dev = (struct bsl_device *)dev_base;
|
|
|
|
|
|
|
|
bsl_xfer(dev, CMD_RESET, 0, NULL, 0);
|
2011-07-26 23:26:02 +00:00
|
|
|
sport_close(dev->serial_fd);
|
2010-04-30 04:01:03 +00:00
|
|
|
free(dev);
|
2010-01-08 05:39:07 +00:00
|
|
|
}
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
static int bsl_ctl(device_t dev_base, device_ctl_t type)
|
2010-01-08 05:39:07 +00:00
|
|
|
{
|
2011-11-14 18:38:19 +00:00
|
|
|
(void)dev_base;
|
|
|
|
|
2010-08-15 23:11:14 +00:00
|
|
|
switch (type) {
|
|
|
|
case DEVICE_CTL_HALT:
|
|
|
|
/* Ignore halt requests */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case DEVICE_CTL_RESET:
|
|
|
|
/* Ignore reset requests */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: CPU control is not possible\n");
|
2010-08-15 23:11:14 +00:00
|
|
|
}
|
|
|
|
|
2010-01-08 05:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
static device_status_t bsl_poll(device_t dev_base)
|
2010-01-08 05:39:07 +00:00
|
|
|
{
|
2011-11-14 18:38:19 +00:00
|
|
|
(void)dev_base;
|
|
|
|
|
2010-03-23 01:37:53 +00:00
|
|
|
return DEVICE_STATUS_HALTED;
|
2010-01-08 05:39:07 +00:00
|
|
|
}
|
|
|
|
|
2010-08-05 02:43:07 +00:00
|
|
|
static int bsl_getregs(device_t dev_base, address_t *regs)
|
2010-01-08 05:39:07 +00:00
|
|
|
{
|
2011-11-14 18:38:19 +00:00
|
|
|
(void)dev_base;
|
|
|
|
(void)regs;
|
|
|
|
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: register fetch is not implemented\n");
|
2010-01-08 05:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-08-05 02:43:07 +00:00
|
|
|
static int bsl_setregs(device_t dev_base, const address_t *regs)
|
2010-01-08 05:39:07 +00:00
|
|
|
{
|
2011-11-14 18:38:19 +00:00
|
|
|
(void)dev_base;
|
|
|
|
(void)regs;
|
|
|
|
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: register store is not implemented\n");
|
2010-01-08 05:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
static int bsl_writemem(device_t dev_base,
|
2010-08-05 02:43:07 +00:00
|
|
|
address_t addr, const uint8_t *mem, address_t len)
|
2010-01-08 05:39:07 +00:00
|
|
|
{
|
2010-08-15 23:11:14 +00:00
|
|
|
struct bsl_device *dev = (struct bsl_device *)dev_base;
|
|
|
|
|
2010-09-25 08:29:38 +00:00
|
|
|
if (addr >= 0x10000 || len > 0x10000 || addr + len > 0x10000) {
|
|
|
|
printc_err("bsl: memory write out of range\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-08-15 23:11:14 +00:00
|
|
|
while (len) {
|
|
|
|
int wlen = len > 100 ? 100 : len;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r = bsl_xfer(dev, CMD_RX_DATA, addr, mem, wlen);
|
|
|
|
|
2010-09-09 23:40:59 +00:00
|
|
|
if (r < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: failed to write to 0x%04x\n",
|
2010-08-15 23:11:14 +00:00
|
|
|
addr);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mem += wlen;
|
|
|
|
len -= wlen;
|
|
|
|
addr += wlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2010-01-08 05:39:07 +00:00
|
|
|
}
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
static int bsl_readmem(device_t dev_base,
|
2010-08-05 02:43:07 +00:00
|
|
|
address_t addr, uint8_t *mem, address_t len)
|
2010-01-08 05:39:07 +00:00
|
|
|
{
|
2010-04-30 04:01:03 +00:00
|
|
|
struct bsl_device *dev = (struct bsl_device *)dev_base;
|
|
|
|
|
2010-09-25 08:29:38 +00:00
|
|
|
if (addr >= 0x10000 || len > 0x10000 || addr + len > 0x10000) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: memory read out of range\n");
|
2010-08-05 02:43:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-01-08 05:39:07 +00:00
|
|
|
while (len) {
|
2010-08-05 02:43:07 +00:00
|
|
|
address_t count = len;
|
2010-01-08 05:39:07 +00:00
|
|
|
|
|
|
|
if (count > 128)
|
|
|
|
count = 128;
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
if (bsl_xfer(dev, CMD_TX_DATA, addr, NULL, count) < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: failed to read memory\n");
|
2010-01-08 05:39:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
if (count > dev->reply_buf[2])
|
|
|
|
count = dev->reply_buf[2];
|
2010-01-08 05:39:07 +00:00
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
memcpy(mem, dev->reply_buf + 4, count);
|
2010-01-08 05:39:07 +00:00
|
|
|
mem += count;
|
|
|
|
len -= count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-23 03:45:06 +00:00
|
|
|
static int bsl_erase(device_t dev_base, device_erase_type_t type,
|
|
|
|
address_t addr)
|
|
|
|
{
|
|
|
|
struct bsl_device *dev = (struct bsl_device *)dev_base;
|
|
|
|
|
2011-11-14 18:38:19 +00:00
|
|
|
(void)addr;
|
|
|
|
|
2010-09-23 03:45:06 +00:00
|
|
|
if (type != DEVICE_ERASE_MAIN) {
|
|
|
|
printc_err("bsl: only main erase is supported\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Constants found from viewing gdbproxy's activities */
|
|
|
|
return bsl_xfer(dev, CMD_ERASE, 0x2500, NULL, 0x0069);
|
|
|
|
}
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
static int enter_via_fet(struct bsl_device *dev)
|
2010-01-08 05:39:07 +00:00
|
|
|
{
|
2010-05-13 00:57:21 +00:00
|
|
|
uint8_t buf[16];
|
2010-01-08 05:39:07 +00:00
|
|
|
|
|
|
|
/* Enter bootloader command */
|
2011-07-26 23:26:02 +00:00
|
|
|
if (sport_write_all(dev->serial_fd,
|
|
|
|
(uint8_t *)"\x7e\x24\x01\x9d\x5a\x7e", 6)) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: couldn't write bootloader transition "
|
2010-01-11 03:54:36 +00:00
|
|
|
"command\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for reply */
|
2011-07-26 23:26:02 +00:00
|
|
|
if (sport_read_all(dev->serial_fd, buf, 8) < 0) {
|
|
|
|
printc_err("bsl: couldn't read bootloader "
|
|
|
|
"transition acknowledgement\n");
|
|
|
|
return -1;
|
2010-01-08 05:39:07 +00:00
|
|
|
}
|
|
|
|
|
2010-01-11 03:54:36 +00:00
|
|
|
/* Check that it's what we expect */
|
2010-01-08 07:19:53 +00:00
|
|
|
if (memcmp(buf, "\x06\x00\x24\x00\x00\x00\x61\x01", 8)) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: bootloader start returned error "
|
2010-05-15 01:44:46 +00:00
|
|
|
"%d (%s)\n", buf[5], fet_error(buf[5]));
|
2010-01-11 03:54:36 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-03-15 01:56:07 +00:00
|
|
|
static device_t bsl_open(const struct device_args *args)
|
2010-01-11 03:54:36 +00:00
|
|
|
{
|
2011-03-15 01:20:06 +00:00
|
|
|
struct bsl_device *dev;
|
2010-04-10 02:35:36 +00:00
|
|
|
|
2011-03-15 01:20:06 +00:00
|
|
|
if (!(args->flags & DEVICE_FLAG_TTY)) {
|
|
|
|
printc_err("This driver does not support raw USB access.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev = malloc(sizeof(*dev));
|
2010-04-30 04:01:03 +00:00
|
|
|
if (!dev) {
|
2010-08-16 23:07:03 +00:00
|
|
|
pr_error("bsl: can't allocate memory");
|
2010-04-30 04:01:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-27 01:08:21 +00:00
|
|
|
memset(dev, 0, sizeof(*dev));
|
|
|
|
|
2011-03-15 01:56:07 +00:00
|
|
|
dev->base.type = &device_bsl;
|
2010-04-30 04:01:03 +00:00
|
|
|
|
2012-02-29 03:29:00 +00:00
|
|
|
dev->serial_fd = sport_open(args->path, 460800, 0);
|
2011-07-26 23:26:02 +00:00
|
|
|
if (SPORT_ISERR(dev->serial_fd)) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: can't open %s: %s\n",
|
2011-07-26 13:51:06 +00:00
|
|
|
args->path, last_error());
|
2010-04-30 04:01:03 +00:00
|
|
|
free(dev);
|
2010-01-08 07:19:53 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
if (enter_via_fet(dev) < 0)
|
2011-12-14 00:11:02 +00:00
|
|
|
printc_err("bsl: warning: FET firmware not responding\n");
|
2010-01-11 03:54:36 +00:00
|
|
|
|
2010-01-08 05:39:07 +00:00
|
|
|
usleep(500000);
|
|
|
|
|
2010-01-08 07:19:53 +00:00
|
|
|
/* Show chip info */
|
2010-04-30 04:01:03 +00:00
|
|
|
if (bsl_xfer(dev, CMD_TX_DATA, 0xff0, NULL, 0x10) < 0) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: failed to read chip info\n");
|
2010-04-30 04:01:03 +00:00
|
|
|
goto fail;
|
2010-01-08 07:19:53 +00:00
|
|
|
}
|
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
if (dev->reply_len < 0x16) {
|
2010-08-16 23:07:03 +00:00
|
|
|
printc_err("bsl: missing chip info\n");
|
2010-04-30 04:01:03 +00:00
|
|
|
goto fail;
|
2010-01-08 07:19:53 +00:00
|
|
|
}
|
|
|
|
|
2010-08-31 03:50:00 +00:00
|
|
|
printc_dbg("Device ID: 0x%02x%02x\n",
|
2010-05-18 23:33:06 +00:00
|
|
|
dev->reply_buf[4], dev->reply_buf[5]);
|
2010-08-31 03:50:00 +00:00
|
|
|
printc_dbg("BSL version is %x.%02x\n", dev->reply_buf[14],
|
2010-04-30 04:01:03 +00:00
|
|
|
dev->reply_buf[15]);
|
2010-05-18 23:33:06 +00:00
|
|
|
|
2010-04-30 04:01:03 +00:00
|
|
|
return (device_t)dev;
|
|
|
|
|
|
|
|
fail:
|
2011-07-26 23:26:02 +00:00
|
|
|
sport_close(dev->serial_fd);
|
2010-04-30 04:01:03 +00:00
|
|
|
free(dev);
|
|
|
|
return NULL;
|
2010-01-08 05:39:07 +00:00
|
|
|
}
|
2011-03-15 01:56:07 +00:00
|
|
|
|
|
|
|
const struct device_class device_bsl = {
|
|
|
|
.name = "uif-bsl",
|
|
|
|
.help = "TI FET430UIF bootloader.",
|
|
|
|
.open = bsl_open,
|
|
|
|
.destroy = bsl_destroy,
|
|
|
|
.readmem = bsl_readmem,
|
|
|
|
.writemem = bsl_writemem,
|
|
|
|
.erase = bsl_erase,
|
|
|
|
.getregs = bsl_getregs,
|
|
|
|
.setregs = bsl_setregs,
|
|
|
|
.ctl = bsl_ctl,
|
|
|
|
.poll = bsl_poll
|
|
|
|
};
|