summaryrefslogtreecommitdiff
path: root/ao-tools/lib
diff options
context:
space:
mode:
Diffstat (limited to 'ao-tools/lib')
-rw-r--r--ao-tools/lib/Makefile.am7
-rw-r--r--ao-tools/lib/ao-elf.c293
-rw-r--r--ao-tools/lib/ao-elf.h39
-rw-r--r--ao-tools/lib/ao-hex.c (renamed from ao-tools/lib/ccdbg-hex.c)103
-rw-r--r--ao-tools/lib/ao-hex.h68
-rw-r--r--ao-tools/lib/ccdbg-command.c2
-rw-r--r--ao-tools/lib/ccdbg-flash.c2
-rw-r--r--ao-tools/lib/ccdbg-memory.c8
-rw-r--r--ao-tools/lib/ccdbg-rom.c8
-rw-r--r--ao-tools/lib/ccdbg.h56
10 files changed, 475 insertions, 111 deletions
diff --git a/ao-tools/lib/Makefile.am b/ao-tools/lib/Makefile.am
index fd4dab25..868b64f1 100644
--- a/ao-tools/lib/Makefile.am
+++ b/ao-tools/lib/Makefile.am
@@ -11,7 +11,6 @@ libao_tools_a_SOURCES = \
ccdbg-debug.h \
ccdbg-flash.c \
ccdbg.h \
- ccdbg-hex.c \
ccdbg-io.c \
ccdbg-manual.c \
ccdbg-memory.c \
@@ -40,4 +39,8 @@ libao_tools_a_SOURCES = \
i0.c \
chbevl.c \
mconf.h \
- cephes.h
+ cephes.h \
+ ao-hex.c \
+ ao-hex.h \
+ ao-elf.c \
+ ao-elf.h
diff --git a/ao-tools/lib/ao-elf.c b/ao-tools/lib/ao-elf.c
new file mode 100644
index 00000000..932dc853
--- /dev/null
+++ b/ao-tools/lib/ao-elf.c
@@ -0,0 +1,293 @@
+/*
+ * Copyright © 2013 Keith Packard <keithp@keithp.com>
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include <err.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include "ao-elf.h"
+#include "ao-hex.h"
+
+/*
+ * Look through the Elf file for symbols that can be adjusted before
+ * the image is written to the device
+ */
+static bool
+find_symbols (Elf *e, struct ao_elf_sym *symbols, int num_symbols)
+{
+ Elf_Scn *scn;
+ Elf_Data *symbol_data = NULL;
+ GElf_Shdr shdr;
+ GElf_Sym sym;
+ int i, symbol_count, s;
+ char *symbol_name;
+ size_t shstrndx;
+
+ if (elf_getshdrstrndx(e, &shstrndx) < 0)
+ return false;
+
+ /*
+ * Find the symbols
+ */
+
+ scn = NULL;
+ while ((scn = elf_nextscn(e, scn)) != NULL) {
+
+ if (gelf_getshdr(scn, &shdr) != &shdr)
+ return false;
+
+ if (shdr.sh_type == SHT_SYMTAB) {
+ symbol_data = elf_getdata(scn, NULL);
+ symbol_count = shdr.sh_size / shdr.sh_entsize;
+ break;
+ }
+ }
+
+ if (!symbol_data)
+ return false;
+
+ for (i = 0; i < symbol_count; i++) {
+ gelf_getsym(symbol_data, i, &sym);
+
+ symbol_name = elf_strptr(e, shdr.sh_link, sym.st_name);
+
+ for (s = 0; s < num_symbols; s++)
+ if (!strcmp (symbols[s].name, symbol_name)) {
+ symbols[s].addr = sym.st_value;
+ symbols[s].found = true;
+ }
+ }
+ for (s = 0; s < num_symbols; s++)
+ if (symbols[s].required && !symbols[s].found)
+ return false;
+ return true;
+}
+
+static uint32_t
+round4(uint32_t a) {
+ return (a + 3) & ~3;
+}
+
+static struct ao_hex_image *
+new_load (uint32_t addr, uint32_t len)
+{
+ struct ao_hex_image *new;
+
+ len = round4(len);
+ new = calloc (1, sizeof (struct ao_hex_image) + len);
+ if (!new)
+ abort();
+
+ new->address = addr;
+ new->length = len;
+ return new;
+}
+
+static void
+load_paste(struct ao_hex_image *into, struct ao_hex_image *from)
+{
+ if (from->address < into->address || into->address + into->length < from->address + from->length)
+ abort();
+
+ memcpy(into->data + from->address - into->address, from->data, from->length);
+}
+
+/*
+ * Make a new load structure large enough to hold the old one and
+ * the new data
+ */
+static struct ao_hex_image *
+expand_load(struct ao_hex_image *from, uint32_t address, uint32_t length)
+{
+ struct ao_hex_image *new;
+
+ if (from) {
+ uint32_t from_last = from->address + from->length;
+ uint32_t last = address + length;
+
+ if (address > from->address)
+ address = from->address;
+ if (last < from_last)
+ last = from_last;
+
+ length = last - address;
+
+ if (address == from->address && length == from->length)
+ return from;
+ }
+ new = new_load(address, length);
+ if (from) {
+ load_paste(new, from);
+ free (from);
+ }
+ return new;
+}
+
+/*
+ * Create a new load structure with data from the existing one
+ * and the new data
+ */
+static struct ao_hex_image *
+load_write(struct ao_hex_image *from, uint32_t address, uint32_t length, void *data)
+{
+ struct ao_hex_image *new;
+
+ new = expand_load(from, address, length);
+ memcpy(new->data + address - new->address, data, length);
+ return new;
+}
+
+/*
+ * Construct a large in-memory block for all
+ * of the loaded sections of the program
+ */
+static struct ao_hex_image *
+get_load(Elf *e)
+{
+ Elf_Scn *scn;
+ size_t shstrndx;
+ GElf_Shdr shdr;
+ Elf_Data *data;
+ size_t nphdr;
+ size_t p;
+ GElf_Phdr phdr;
+ GElf_Addr sh_paddr;
+ struct ao_hex_image *load = NULL;
+ char *section_name;
+ size_t nshdr;
+ size_t s;
+
+ if (elf_getshdrstrndx(e, &shstrndx) < 0)
+ return 0;
+
+ if (elf_getphdrnum(e, &nphdr) < 0)
+ return 0;
+
+ if (elf_getshdrnum(e, &nshdr) < 0)
+ return 0;
+
+ /*
+ * As far as I can tell, all of the phdr sections should
+ * be flashed to memory
+ */
+ for (p = 0; p < nphdr; p++) {
+
+ /* Find this phdr */
+ gelf_getphdr(e, p, &phdr);
+
+ if (phdr.p_type != PT_LOAD)
+ continue;
+
+ /* Get the associated file section */
+
+#if 0
+ printf ("offset %08x vaddr %08x paddr %08x filesz %08x memsz %08x\n",
+ (uint32_t) phdr.p_offset,
+ (uint32_t) phdr.p_vaddr,
+ (uint32_t) phdr.p_paddr,
+ (uint32_t) phdr.p_filesz,
+ (uint32_t) phdr.p_memsz);
+#endif
+
+ for (s = 0; s < nshdr; s++) {
+ scn = elf_getscn(e, s);
+
+ if (!scn) {
+ printf ("getscn failed\n");
+ abort();
+ }
+ if (gelf_getshdr(scn, &shdr) != &shdr) {
+ printf ("gelf_getshdr failed\n");
+ abort();
+ }
+
+ section_name = elf_strptr(e, shstrndx, shdr.sh_name);
+
+ if (phdr.p_offset <= shdr.sh_offset && shdr.sh_offset < phdr.p_offset + phdr.p_filesz) {
+
+ if (shdr.sh_size == 0)
+ continue;
+
+ sh_paddr = phdr.p_paddr + shdr.sh_offset - phdr.p_offset;
+
+ printf ("\tsize %08x rom %08x exec %08x %s\n",
+ (uint32_t) shdr.sh_size,
+ (uint32_t) sh_paddr,
+ (uint32_t) shdr.sh_addr,
+ section_name);
+
+ data = elf_getdata(scn, NULL);
+
+ /* Write the section data into the memory block */
+ load = load_write(load, sh_paddr, shdr.sh_size, data->d_buf);
+ }
+ }
+ }
+ return load;
+}
+
+/*
+ * Open the specified ELF file and
+ * check for the symbols we need
+ */
+
+struct ao_hex_image *
+ao_load_elf(char *name, struct ao_elf_sym *symbols, int num_symbols)
+{
+ int fd;
+ Elf *e;
+ size_t shstrndx;
+ struct ao_hex_image *image;
+
+ if (elf_version(EV_CURRENT) == EV_NONE)
+ return NULL;
+
+ fd = open(name, O_RDONLY, 0);
+
+ if (fd < 0)
+ return NULL;
+
+ e = elf_begin(fd, ELF_C_READ, NULL);
+
+ if (!e)
+ return NULL;
+
+ if (elf_kind(e) != ELF_K_ELF)
+ return NULL;
+
+ if (elf_getshdrstrndx(e, &shstrndx) != 0)
+ return NULL;
+
+ if (!find_symbols(e, symbols, num_symbols)) {
+ fprintf (stderr, "Cannot find required symbols\n");
+ return NULL;
+ }
+
+ image = get_load(e);
+ if (!image) {
+ fprintf (stderr, "Cannot create memory image from file\n");
+ return NULL;
+ }
+
+ return image;
+}
diff --git a/ao-tools/lib/ao-elf.h b/ao-tools/lib/ao-elf.h
new file mode 100644
index 00000000..f3a2358c
--- /dev/null
+++ b/ao-tools/lib/ao-elf.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright © 2013 Keith Packard <keithp@keithp.com>
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#ifndef _AO_ELF_H_
+#define _AO_ELF_H_
+
+#include <stdbool.h>
+#include <gelf.h>
+#include "ao-hex.h"
+
+struct ao_elf_sym {
+ unsigned addr;
+ unsigned default_addr;
+ char *name;
+ bool required;
+ bool found;
+};
+
+struct ao_hex_image *
+ao_load_elf(char *name, struct ao_elf_sym *symbols, int num_symbols);
+
+int
+ao_elf_find_symbols (Elf *e, struct ao_elf_sym *symbols, int num_symbols);
+
+#endif /* _AO_ELF_H_ */
diff --git a/ao-tools/lib/ccdbg-hex.c b/ao-tools/lib/ao-hex.c
index 184b4e3b..85acc07f 100644
--- a/ao-tools/lib/ccdbg-hex.c
+++ b/ao-tools/lib/ao-hex.c
@@ -16,17 +16,20 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include "ccdbg.h"
#include <stdarg.h>
#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "ao-hex.h"
-struct hex_input {
+struct ao_hex_input {
FILE *file;
int line;
char *name;
};
-enum hex_read_state {
+enum ao_hex_read_state {
read_marker,
read_length,
read_address,
@@ -40,7 +43,7 @@ enum hex_read_state {
static void
-ccdbg_hex_error(struct hex_input *input, char *format, ...)
+ao_hex_error(struct ao_hex_input *input, char *format, ...)
{
va_list ap;
@@ -52,18 +55,18 @@ ccdbg_hex_error(struct hex_input *input, char *format, ...)
}
static void
-ccdbg_hex_free(struct hex_record *record)
+ao_hex_free(struct ao_hex_record *record)
{
if (!record) return;
free(record);
}
-static struct hex_record *
-ccdbg_hex_alloc(uint8_t length)
+static struct ao_hex_record *
+ao_hex_alloc(uint8_t length)
{
- struct hex_record *record;
+ struct ao_hex_record *record;
- record = calloc(1, sizeof(struct hex_record) + length);
+ record = calloc(1, sizeof(struct ao_hex_record) + length);
record->length = length;
return record;
}
@@ -88,7 +91,7 @@ fromhex(char c)
}
static uint8_t
-ccdbg_hex_checksum(struct hex_record *record)
+ao_hex_checksum(struct ao_hex_record *record)
{
uint8_t checksum = 0;
int i;
@@ -102,11 +105,11 @@ ccdbg_hex_checksum(struct hex_record *record)
return -checksum;
}
-static struct hex_record *
-ccdbg_hex_read_record(struct hex_input *input)
+static struct ao_hex_record *
+ao_hex_read_record(struct ao_hex_input *input)
{
- struct hex_record *record = NULL;
- enum hex_read_state state = read_marker;
+ struct ao_hex_record *record = NULL;
+ enum ao_hex_read_state state = read_marker;
char c;
int nhexbytes;
uint32_t hex;
@@ -116,7 +119,7 @@ ccdbg_hex_read_record(struct hex_input *input)
while (state != read_done) {
c = getc(input->file);
if (c == EOF && state != read_white) {
- ccdbg_hex_error(input, "Unexpected EOF");
+ ao_hex_error(input, "Unexpected EOF");
goto bail;
}
if (c == ' ')
@@ -126,7 +129,7 @@ ccdbg_hex_read_record(struct hex_input *input)
switch (state) {
case read_marker:
if (c != ':') {
- ccdbg_hex_error(input, "Missing ':'");
+ ao_hex_error(input, "Missing ':'");
goto bail;
}
state = read_length;
@@ -139,7 +142,7 @@ ccdbg_hex_read_record(struct hex_input *input)
case read_data:
case read_checksum:
if (!ishex(c)) {
- ccdbg_hex_error(input, "Non-hex char '%c'",
+ ao_hex_error(input, "Non-hex char '%c'",
c);
goto bail;
}
@@ -150,9 +153,9 @@ ccdbg_hex_read_record(struct hex_input *input)
switch (state) {
case read_length:
- record = ccdbg_hex_alloc(hex);
+ record = ao_hex_alloc(hex);
if (!record) {
- ccdbg_hex_error(input, "Out of memory");
+ ao_hex_error(input, "Out of memory");
goto bail;
}
state = read_address;
@@ -190,7 +193,7 @@ ccdbg_hex_read_record(struct hex_input *input)
break;
case read_newline:
if (c != '\n' && c != '\r') {
- ccdbg_hex_error(input, "Missing newline");
+ ao_hex_error(input, "Missing newline");
goto bail;
}
state = read_white;
@@ -208,73 +211,73 @@ ccdbg_hex_read_record(struct hex_input *input)
break;
}
}
- checksum = ccdbg_hex_checksum(record);
+ checksum = ao_hex_checksum(record);
if (checksum != record->checksum) {
- ccdbg_hex_error(input, "Invalid checksum (read 0x%02x computed 0x%02x)\n",
+ ao_hex_error(input, "Invalid checksum (read 0x%02x computed 0x%02x)\n",
record->checksum, checksum);
goto bail;
}
return record;
bail:
- ccdbg_hex_free(record);
+ ao_hex_free(record);
return NULL;
}
void
-ccdbg_hex_file_free(struct hex_file *hex)
+ao_hex_file_free(struct ao_hex_file *hex)
{
int i;
if (!hex)
return;
for (i = 0; i < hex->nrecord; i++)
- ccdbg_hex_free(hex->records[i]);
+ ao_hex_free(hex->records[i]);
free(hex);
}
-struct hex_file *
-ccdbg_hex_file_read(FILE *file, char *name)
+struct ao_hex_file *
+ao_hex_file_read(FILE *file, char *name)
{
- struct hex_input input;
- struct hex_file *hex = NULL, *newhex;
- struct hex_record *record;
+ struct ao_hex_input input;
+ struct ao_hex_file *hex = NULL, *newhex;
+ struct ao_hex_record *record;
int srecord = 1;
int done = 0;
- hex = calloc(sizeof (struct hex_file) + sizeof (struct hex_record *), 1);
+ hex = calloc(sizeof (struct ao_hex_file) + sizeof (struct ao_hex_record *), 1);
input.name = name;
input.line = 1;
input.file = file;
while (!done) {
- record = ccdbg_hex_read_record(&input);
+ record = ao_hex_read_record(&input);
if (!record)
goto bail;
if (hex->nrecord == srecord) {
srecord *= 2;
newhex = realloc(hex,
- sizeof (struct hex_file) +
- srecord * sizeof (struct hex_record *));
+ sizeof (struct ao_hex_file) +
+ srecord * sizeof (struct ao_hex_record *));
if (!newhex)
goto bail;
hex = newhex;
}
hex->records[hex->nrecord++] = record;
- if (record->type == HEX_RECORD_EOF)
+ if (record->type == AO_HEX_RECORD_EOF)
done = 1;
}
return hex;
bail:
- ccdbg_hex_file_free(hex);
+ ao_hex_file_free(hex);
return NULL;
}
-struct hex_image *
-ccdbg_hex_image_create(struct hex_file *hex)
+struct ao_hex_image *
+ao_hex_image_create(struct ao_hex_file *hex)
{
- struct hex_image *image;
- struct hex_record *record;
+ struct ao_hex_image *image;
+ struct ao_hex_record *record;
int i;
uint32_t addr;
uint32_t base, bound;
@@ -314,7 +317,7 @@ ccdbg_hex_image_create(struct hex_file *hex)
}
length = bound - base;
- image = calloc(sizeof(struct hex_image) + length, 1);
+ image = calloc(sizeof(struct ao_hex_image) + length, 1);
if (!image)
return NULL;
image->address = base;
@@ -343,13 +346,13 @@ ccdbg_hex_image_create(struct hex_file *hex)
}
void
-ccdbg_hex_image_free(struct hex_image *image)
+ao_hex_image_free(struct ao_hex_image *image)
{
free(image);
}
int
-ccdbg_hex_image_equal(struct hex_image *a, struct hex_image *b)
+ao_hex_image_equal(struct ao_hex_image *a, struct ao_hex_image *b)
{
if (a->length != b->length)
return 0;
@@ -358,24 +361,24 @@ ccdbg_hex_image_equal(struct hex_image *a, struct hex_image *b)
return 1;
}
-struct hex_image *
-ccdbg_hex_load(char *filename)
+struct ao_hex_image *
+ao_hex_load(char *filename)
{
FILE *file;
- struct hex_file *hex_file;
- struct hex_image *hex_image;
+ struct ao_hex_file *hex_file;
+ struct ao_hex_image *hex_image;
file = fopen (filename, "r");
if (!file)
return 0;
- hex_file = ccdbg_hex_file_read(file, filename);
+ hex_file = ao_hex_file_read(file, filename);
fclose(file);
if (!hex_file)
return 0;
- hex_image = ccdbg_hex_image_create(hex_file);
+ hex_image = ao_hex_image_create(hex_file);
if (!hex_image)
return 0;
- ccdbg_hex_file_free(hex_file);
+ ao_hex_file_free(hex_file);
return hex_image;
}
diff --git a/ao-tools/lib/ao-hex.h b/ao-tools/lib/ao-hex.h
new file mode 100644
index 00000000..8528eb45
--- /dev/null
+++ b/ao-tools/lib/ao-hex.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright © 2013 Keith Packard <keithp@keithp.com>
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#ifndef _AO_HEX_H_
+#define _AO_HEX_H_
+
+#include <stdint.h>
+
+#define AO_HEX_RECORD_NORMAL 0x00
+#define AO_HEX_RECORD_EOF 0x01
+#define AO_HEX_RECORD_EXTENDED_ADDRESS_4 0x02
+#define AO_HEX_RECORD_EXTENDED_ADDRESS_8 0x04
+#define AO_HEX_RECORD_SYMBOL 0xfe
+
+/* Intel hex file format data
+ */
+struct ao_hex_record {
+ uint8_t length;
+ uint16_t address;
+ uint8_t type;
+ uint8_t checksum;
+ uint8_t data[0];
+};
+
+struct ao_hex_file {
+ int nrecord;
+ struct ao_hex_record *records[0];
+};
+
+struct ao_hex_image {
+ uint32_t address;
+ uint32_t length;
+ uint8_t data[0];
+};
+
+struct ao_hex_file *
+ao_hex_file_read(FILE *file, char *name);
+
+void
+ao_hex_file_free(struct ao_hex_file *hex);
+
+struct ao_hex_image *
+ao_hex_image_create(struct ao_hex_file *hex);
+
+void
+ao_hex_image_free(struct ao_hex_image *image);
+
+struct ao_hex_image *
+ao_hex_load(char *filename);
+
+int
+ao_hex_image_equal(struct ao_hex_image *a, struct ao_hex_image *b);
+
+#endif /* _AO_HEX_H_ */
diff --git a/ao-tools/lib/ccdbg-command.c b/ao-tools/lib/ccdbg-command.c
index a1002879..55c912b2 100644
--- a/ao-tools/lib/ccdbg-command.c
+++ b/ao-tools/lib/ccdbg-command.c
@@ -157,7 +157,7 @@ ccdbg_set_pc(struct ccdbg *dbg, uint16_t pc)
}
uint8_t
-ccdbg_execute_hex_image(struct ccdbg *dbg, struct hex_image *image)
+ccdbg_execute_hex_image(struct ccdbg *dbg, struct ao_hex_image *image)
{
uint16_t pc;
uint8_t status;
diff --git a/ao-tools/lib/ccdbg-flash.c b/ao-tools/lib/ccdbg-flash.c
index 1b46870b..44eb952b 100644
--- a/ao-tools/lib/ccdbg-flash.c
+++ b/ao-tools/lib/ccdbg-flash.c
@@ -238,7 +238,7 @@ ccdbg_flash_lock(struct ccdbg *dbg, uint8_t lock)
#endif
uint8_t
-ccdbg_flash_hex_image(struct ccdbg *dbg, struct hex_image *image)
+ccdbg_flash_hex_image(struct ccdbg *dbg, struct ao_hex_image *image)
{
uint16_t flash_prog;
uint16_t flash_len;
diff --git a/ao-tools/lib/ccdbg-memory.c b/ao-tools/lib/ccdbg-memory.c
index 554ac637..04059e2e 100644
--- a/ao-tools/lib/ccdbg-memory.c
+++ b/ao-tools/lib/ccdbg-memory.c
@@ -117,18 +117,18 @@ ccdbg_write_uint8(struct ccdbg *dbg, uint16_t addr, uint8_t byte)
}
uint8_t
-ccdbg_write_hex_image(struct ccdbg *dbg, struct hex_image *image, uint16_t offset)
+ccdbg_write_hex_image(struct ccdbg *dbg, struct ao_hex_image *image, uint16_t offset)
{
ccdbg_write_memory(dbg, image->address + offset, image->data, image->length);
return 0;
}
-struct hex_image *
+struct ao_hex_image *
ccdbg_read_hex_image(struct ccdbg *dbg, uint16_t address, uint16_t length)
{
- struct hex_image *image;
+ struct ao_hex_image *image;
- image = calloc(sizeof(struct hex_image) + length, 1);
+ image = calloc(sizeof(struct ao_hex_image) + length, 1);
image->address = address;
image->length = length;
memset(image->data, 0xff, length);
diff --git a/ao-tools/lib/ccdbg-rom.c b/ao-tools/lib/ccdbg-rom.c
index 71bed220..6e8e7378 100644
--- a/ao-tools/lib/ccdbg-rom.c
+++ b/ao-tools/lib/ccdbg-rom.c
@@ -19,10 +19,10 @@
#include "ccdbg.h"
uint8_t
-ccdbg_set_rom(struct ccdbg *dbg, struct hex_image *rom)
+ccdbg_set_rom(struct ccdbg *dbg, struct ao_hex_image *rom)
{
if (dbg->rom)
- ccdbg_hex_image_free(dbg->rom);
+ ao_hex_image_free(dbg->rom);
dbg->rom = rom;
return 0;
}
@@ -30,7 +30,7 @@ ccdbg_set_rom(struct ccdbg *dbg, struct hex_image *rom)
uint8_t
ccdbg_rom_contains(struct ccdbg *dbg, uint16_t addr, int nbytes)
{
- struct hex_image *rom = dbg->rom;
+ struct ao_hex_image *rom = dbg->rom;
if (!rom)
return 0;
if (addr < rom->address || rom->address + rom->length < addr + nbytes)
@@ -42,7 +42,7 @@ uint8_t
ccdbg_rom_replace_xmem(struct ccdbg *dbg,
uint16_t addr, uint8_t *bytes, int nbytes)
{
- struct hex_image *rom = dbg->rom;
+ struct ao_hex_image *rom = dbg->rom;
if (!rom)
return 0;
diff --git a/ao-tools/lib/ccdbg.h b/ao-tools/lib/ccdbg.h
index a27ff5d1..b17f289d 100644
--- a/ao-tools/lib/ccdbg.h
+++ b/ao-tools/lib/ccdbg.h
@@ -33,6 +33,7 @@
#include "ccdbg-debug.h"
#include "cc-bitbang.h"
#include "cc-usb.h"
+#include "ao-hex.h"
/* 8051 instructions
*/
@@ -103,29 +104,9 @@
struct ccdbg {
struct cc_bitbang *bb;
struct cc_usb *usb;
- struct hex_image *rom;
+ struct ao_hex_image *rom;
};
-/* Intel hex file format data
- */
-struct hex_record {
- uint8_t length;
- uint16_t address;
- uint8_t type;
- uint8_t checksum;
- uint8_t data[0];
-};
-
-struct hex_file {
- int nrecord;
- struct hex_record *records[0];
-};
-
-struct hex_image {
- uint32_t address;
- uint32_t length;
- uint8_t data[0];
-};
#define CC_STATE_ACC 0x1
#define CC_STATE_PSW 0x2
@@ -139,10 +120,6 @@ struct ccstate {
uint8_t sfr[CC_STATE_NSFR];
};
-#define HEX_RECORD_NORMAL 0x00
-#define HEX_RECORD_EOF 0x01
-#define HEX_RECORD_EXTENDED_ADDRESS 0x02
-
/* CC1111 debug port commands
*/
#define CC_CHIP_ERASE 0x14
@@ -234,30 +211,11 @@ uint8_t
ccdbg_set_pc(struct ccdbg *dbg, uint16_t pc);
uint8_t
-ccdbg_execute_hex_image(struct ccdbg *dbg, struct hex_image *image);
+ccdbg_execute_hex_image(struct ccdbg *dbg, struct ao_hex_image *image);
/* ccdbg-flash.c */
uint8_t
-ccdbg_flash_hex_image(struct ccdbg *dbg, struct hex_image *image);
-
-/* ccdbg-hex.c */
-struct hex_file *
-ccdbg_hex_file_read(FILE *file, char *name);
-
-void
-ccdbg_hex_file_free(struct hex_file *hex);
-
-struct hex_image *
-ccdbg_hex_image_create(struct hex_file *hex);
-
-void
-ccdbg_hex_image_free(struct hex_image *image);
-
-struct hex_image *
-ccdbg_hex_load(char *filename);
-
-int
-ccdbg_hex_image_equal(struct hex_image *a, struct hex_image *b);
+ccdbg_flash_hex_image(struct ccdbg *dbg, struct ao_hex_image *image);
/* ccdbg-io.c */
struct ccdbg *
@@ -304,9 +262,9 @@ uint8_t
ccdbg_write_uint8(struct ccdbg *dbg, uint16_t addr, uint8_t byte);
uint8_t
-ccdbg_write_hex_image(struct ccdbg *dbg, struct hex_image *image, uint16_t offset);
+ccdbg_write_hex_image(struct ccdbg *dbg, struct ao_hex_image *image, uint16_t offset);
-struct hex_image *
+struct ao_hex_image *
ccdbg_read_hex_image(struct ccdbg *dbg, uint16_t address, uint16_t length);
uint8_t
@@ -317,7 +275,7 @@ ccdbg_write_sfr(struct ccdbg *dbg, uint8_t addr, uint8_t *bytes, int nbytes);
/* ccdbg-rom.c */
uint8_t
-ccdbg_set_rom(struct ccdbg *dbg, struct hex_image *rom);
+ccdbg_set_rom(struct ccdbg *dbg, struct ao_hex_image *rom);
uint8_t
ccdbg_rom_contains(struct ccdbg *dbg, uint16_t addr, int nbytes);