added optional common chip identification

This commit is contained in:
zcsahok 2015-10-21 08:20:15 +02:00
parent be92e35742
commit f5f881bc33
6 changed files with 79 additions and 22 deletions

View File

@ -16,8 +16,10 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <string.h>
#include "output.h"
#include "device.h"
#include "bytes.h"
device_t device_default;
@ -90,8 +92,41 @@ int device_setbrk(device_t dev, int which, int enabled, address_t addr,
return 0;
}
int device_probe_id(device_t dev)
static void show_device_type(device_t dev)
{
printc("Device: %s", dev->chip->name);
if (device_is_fram(dev))
printc(" [FRAM]");
printc("\n");
}
int device_probe_id(device_t dev, const char *force_id)
{
/* skip probe if driver already did it */
if (dev->chip) {
show_device_type(dev);
return 0;
}
/* use forced id if present */
if (force_id) {
dev->chip = chipinfo_find_by_name(force_id);
if (!dev->chip) {
printc_err("unknown chip: %s\n", force_id);
return -1;
}
printc("Device: %s (forced)\n", dev->chip->name);
return 0;
}
/* no probing if not requested */
if (!dev->need_probe)
return 0;
/* else proceed with identification */
uint8_t data[16];
if (dev->type->readmem(dev, 0xff0, data, sizeof(data)) < 0) {
@ -99,6 +134,9 @@ int device_probe_id(device_t dev)
return -1;
}
struct chipinfo_id id;
memset(&id, 0, sizeof(id));
if (data[0] == 0x80) {
if (dev->type->readmem(dev, 0x1a00, data, sizeof(data)) < 0) {
printc_err("device_probe_id: read failed\n");
@ -108,20 +146,42 @@ int device_probe_id(device_t dev)
dev->dev_id[0] = data[4];
dev->dev_id[1] = data[5];
dev->dev_id[2] = data[6];
id.ver_id = r16le(data + 4);
//id.ver_sub_id = 0; --> need TLV lookup for this
id.revision = data[6];
id.config = data[7];
id.fab = 0x55;
id.self = 0x5555;
id.fuses = 0x55;
} else {
dev->dev_id[0] = data[0];
dev->dev_id[1] = data[1];
dev->dev_id[2] = data[13];
id.ver_id = r16le(data);
id.ver_sub_id = 0;
id.revision = data[2];
id.fab = data[3];
id.self = r16le(data + 8);
id.config = data[13] & 0x7f;
}
printc_dbg("Chip ID data: %02x %02x", dev->dev_id[0], dev->dev_id[1]);
if (dev->dev_id[2])
printc_dbg(" %02x", dev->dev_id[2]);
printc_dbg("Chip ID data:\n");
printc_dbg(" ver_id: %04x\n", id.ver_id);
printc_dbg(" ver_sub_id: %04x\n", id.ver_sub_id);
printc_dbg(" revision: %02x\n", id.revision);
printc_dbg(" fab: %02x\n", id.fab);
printc_dbg(" self: %04x\n", id.self);
printc_dbg(" config: %02x\n", id.config);
//printc_dbg(" fuses: %02x\n", id.fuses);
//printc_dbg(" activation_key: %08x\n", id.activation_key);
if (device_is_fram(dev))
printc_dbg(" [FRAM]");
dev->chip = chipinfo_find_by_id(&id);
if (!dev->chip)
return -1;
printc_dbg("\n");
show_device_type(dev);
return 0;
}

View File

@ -22,6 +22,7 @@
#include <stdint.h>
#include "util.h"
#include "powerbuf.h"
#include "chipinfo.h"
struct device;
typedef struct device *device_t;
@ -134,12 +135,17 @@ struct device {
* device.
*/
powerbuf_t power_buf;
/* Chip information data.
*/
const struct chipinfo *chip;
int need_probe;
};
/* Probe the device memory and extract ID bytes. This should be called
* after the device structure is ready.
*/
int device_probe_id(device_t dev);
int device_probe_id(device_t dev, const char *force_id);
/* Determine, from the device ID bytes, whether this chip is an FRAM or
* flash-based device.

View File

@ -231,6 +231,8 @@ static int debug_init(struct fet3 *fet, const struct device_args *args)
goto fail_stop_jtag;
}
fet->base.chip = fet->hil.chip;
if (v3hil_configure(&fet->hil) < 0)
goto fail_stop_jtag;
if (v3hil_update_regs(&fet->hil) < 0)

View File

@ -308,7 +308,6 @@ fail:
static int init_device(sport_t fd)
{
struct packet pkt;
uint8_t chip_id[2];
printc_dbg("Initializing...\n");
@ -352,14 +351,6 @@ static int init_device(sport_t fd)
return -1;
}
if (read_words(fd, 0xff0, 2, chip_id) < 0) {
printc_err("goodfet: failed to read chip ID\n");
xfer(fd, APP_JTAG430, GLOBAL_STOP, 0, NULL, &pkt);
return -1;
}
printc_dbg("Chip ID: 0x%02x%02x\n", chip_id[0], chip_id[1]);
return 0;
}
@ -628,6 +619,7 @@ static device_t goodfet_open(const struct device_args *args)
gc->base.type = &device_goodfet;
gc->base.max_breakpoints = 0;
gc->base.need_probe = 1;
gc->serial_fd = sport_open(args->path, 115200, 0);
if (SPORT_ISERR(gc->serial_fd)) {

View File

@ -124,7 +124,6 @@ static int write_byte( struct jtdev *p,
static int init_device(struct jtdev *p)
{
unsigned int jtag_id;
unsigned int chip_id;
printc_dbg("Starting JTAG\n");
jtag_id = jtag_init(p);
@ -135,9 +134,6 @@ static int init_device(struct jtdev *p)
return -1;
}
chip_id =jtag_chip_id(p);
printc_dbg("Chip ID: %04X\n", chip_id);
return 0;
}
@ -409,6 +405,7 @@ static device_t pif_open(const struct device_args *args)
memset(dev, 0, sizeof(*dev));
dev->base.type = &device_pif;
dev->base.max_breakpoints = 2; //supported by all devices
dev->base.need_probe = 1;
(&dev->jtag)->f = &jtdev_func_pif;
if ((&dev->jtag)->f->jtdev_open(&dev->jtag, args->path) < 0) {

View File

@ -486,7 +486,7 @@ int main(int argc, char **argv)
goto fail_driver;
}
if (device_probe_id(device_default) < 0)
if (device_probe_id(device_default, args.devarg.forced_chip_id) < 0)
printc_err("warning: device ID probe failed\n");
simio_init();