changeset 19:c0e063494194

loadagent built with memory dump commands
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 04 May 2013 00:25:30 +0000
parents fa3e9a5665bd
children be293e656a6f
files target-utils/libload/Makefile target-utils/libload/cmd_memdump_human.c target-utils/libload/cmd_memdump_machine.c target-utils/loadagent/Makefile target-utils/loadagent/cmdtab.c target-utils/loadagent/main.c target-utils/loadagent/mygetchar.c
diffstat 7 files changed, 216 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/libload/Makefile	Sat May 04 00:25:30 2013 +0000
@@ -0,0 +1,16 @@
+CC=	arm-elf-gcc
+CFLAGS=	-Os -fno-builtin
+CPPFLAGS=-I../include
+AR=	arm-elf-ar
+RANLIB=	arm-elf-ranlib
+
+OBJS=	cmd_memdump_human.o cmd_memdump_machine.o
+
+all:	libload.a
+
+libload.a:	${OBJS}
+	${AR} cru $@ ${OBJS}
+	${RANLIB} $@
+
+clean:
+	rm -f *.[oa] *errs
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/libload/cmd_memdump_human.c	Sat May 04 00:25:30 2013 +0000
@@ -0,0 +1,50 @@
+/*
+ * This is a human-oriented memory dump command.  The dump is given in
+ * both hex and ASCII, with readable spacing.
+ */
+
+#include <sys/types.h>
+#include "types.h"
+
+void
+cmd_memdump_human(argbulk)
+	char *argbulk;
+{
+	char *argv[3];
+	u_long start, length;
+	u_long offset;
+	u_char intbuf[16];
+	int i, c;
+
+	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
+		return;
+	if (parse_hexarg(argv[0], 8, &start) < 0) {
+		printf("ERROR: arg1 must be a valid 32-bit hex address\n");
+		return;
+	}
+	if (parse_hexarg(argv[1], 2, &length) < 0) {
+	    printf("ERROR: arg2 must be a valid 32-bit hex value (length)\n");
+		return;
+	}
+	if (start & 0xF || length & 0xF) {
+	    printf("ERROR: implementation limit: 16-byte alignment required\n");
+		return;
+	}
+	for (offset = 0; offset < length; offset += 0x10) {
+		bcopy(start + offset, intbuf, 0x10);
+		printf("%08X: ", start + offset);
+		for (i = 0; i < 16; i++) {
+			printf("%02X ", intbuf[i]);
+			if ((i & 3) == 3)
+				putchar(' ');
+		}
+		for (i = 0; i < 16; i++) {
+			c = intbuf[i];
+			if (c >= ' ' && c <= '~')
+				putchar(c);
+			else
+				putchar('.');
+		}
+		putchar('\n');
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/libload/cmd_memdump_machine.c	Sat May 04 00:25:30 2013 +0000
@@ -0,0 +1,50 @@
+/*
+ * This is a machine-oriented memory dump command.  The output is in the
+ * form of S3 records.
+ */
+
+#include <sys/types.h>
+#include "types.h"
+
+void
+cmd_memdump_machine(argbulk)
+	char *argbulk;
+{
+	char *argv[3];
+	u_long start, length;
+	u_long addr;
+	u_char srbuf[0x86], cksum;
+	int i;
+
+	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
+		return;
+	if (parse_hexarg(argv[0], 8, &start) < 0) {
+		printf("ERROR: arg1 must be a valid 32-bit hex address\n");
+		return;
+	}
+	if (parse_hexarg(argv[1], 2, &length) < 0) {
+	    printf("ERROR: arg2 must be a valid 32-bit hex value (length)\n");
+		return;
+	}
+	if (start & 0x7F || length & 0x7F) {
+	   printf("ERROR: implementation limit: 128-byte alignment required\n");
+		return;
+	}
+	srbuf[0] = 0x85;
+	for (addr = start; addr < start + length; addr += 0x80) {
+		srbuf[1] = addr >> 24;
+		srbuf[2] = addr >> 16;
+		srbuf[3] = addr >> 8;
+		srbuf[4] = addr;
+		bcopy(addr, srbuf + 5, 0x80);
+		cksum = 0;
+		for (i = 0; i < 0x85; i++)
+			cksum += srbuf[i];
+		srbuf[i] = ~cksum;
+		putchar('S');
+		putchar('3');
+		for (i = 0; i < 0x86; i++)
+			printf("%02X", srbuf[i]);
+		putchar('\n');
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/loadagent/Makefile	Sat May 04 00:25:30 2013 +0000
@@ -0,0 +1,31 @@
+CC=	arm-elf-gcc
+CFLAGS=	-Os -fno-builtin
+CPPFLAGS=-I../include
+LD=	arm-elf-ld
+OBJCOPY=arm-elf-objcopy
+
+PROG=	loadagent
+OBJS=	crt0.o cmdtab.o main.o mygetchar.o
+LIBS=	../libcommon/libcommon.a ../libload/libload.a ../libprintf/libprintf.a
+LDS=	../env/iram.lds
+
+TC_LIBS=`${CC} -print-file-name=libc.a` \
+	`${CC} -print-file-name=libgcc.a`
+
+all:	${PROG}.srec
+
+crt0.S:	../env/crt0.S
+	ln -s $< .
+
+${PROG}.elf:	${OBJS} ${LIBS} ${LDS}
+	${LD} -N --defsym stack_bottom=0x83FFFC -T ${LDS} -o $@ ${OBJS} \
+		--start-group ${LIBS} --end-group \
+		--start-group ${TC_LIBS} --end-group
+
+${PROG}.srec:	${PROG}.elf
+	${OBJCOPY} -O srec --srec-forceS3 --srec-len=30 $< $@
+
+clean:
+	rm -f *.o *errs *core *.elf *.bin *.srec crt0.S
+
+FRC:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/loadagent/cmdtab.c	Sat May 04 00:25:30 2013 +0000
@@ -0,0 +1,23 @@
+#include "cmdtab.h"
+
+extern void cmd_r8();
+extern void cmd_r16();
+extern void cmd_r32();
+extern void cmd_w8();
+extern void cmd_w16();
+extern void cmd_w32();
+
+extern void cmd_memdump_human();
+extern void cmd_memdump_machine();
+
+const struct cmdtab cmdtab[] = {
+	{"DUMP", cmd_memdump_machine},
+	{"dump", cmd_memdump_human},
+	{"r8", cmd_r8},
+	{"r16", cmd_r16},
+	{"r32", cmd_r32},
+	{"w8", cmd_w8},
+	{"w16", cmd_w16},
+	{"w32", cmd_w32},
+	{0, 0}
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/loadagent/main.c	Sat May 04 00:25:30 2013 +0000
@@ -0,0 +1,25 @@
+/*
+ * FreeCalypso loadagent main() function lives here
+ */
+
+#include "types.h"
+#include "romvars.h"
+
+extern struct boot_rom_vars rom_vars;
+
+extern char *uart_name;
+
+main()
+{
+	uart_select_init();
+	printf("FreeCalypso loadagent running\n");
+	printf("Loaded via UART %d (%s) at baud rate #%d\n", rom_vars.uart_id,
+		uart_name, rom_vars.baud_rate_code);
+	printf("TCXO clock input autodetected to be %d MHz\n",
+		rom_vars.clktcxo_13mhz ? 13 : 26);
+	for (;;) {
+		putchar('=');
+		if (command_entry())
+			command_dispatch();
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/target-utils/loadagent/mygetchar.c	Sat May 04 00:25:30 2013 +0000
@@ -0,0 +1,21 @@
+/*
+ * The interactive command entry (editing) function in libcommon
+ * will call mygetchar() for its character input.  It is supposed
+ * to be a blocking wait for input, but in some programs other
+ * processing can be done while waiting - for example, check for
+ * keypad presses as well.  This is the basic version which waits
+ * for serial input and nothing else.
+ */
+
+extern int serial_in_poll();
+
+int
+mygetchar()
+{
+	register int c;
+
+	do
+		c = serial_in_poll();
+	while (c < 0);
+	return c;
+}