URL
https://opencores.org/ocsvn/eus100lx/eus100lx/trunk
Subversion Repositories eus100lx
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 2 to Rev 3
- ↔ Reverse comparison
Rev 2 → Rev 3
/trunk/tools/cris-boot/mcs.c
0,0 → 1,146
/* $Id: mcs.c,v 1.1.1.1 2006-02-04 03:35:01 freza Exp $ */ |
|
#include <sys/types.h> |
#include <errno.h> |
#include <stdio.h> |
#include <stdlib.h> |
|
static int |
decode_byte(FILE *file, u_int8_t *dst) |
{ |
int c; |
|
if ((c = fgetc(file)) == EOF) |
return EINVAL; |
|
if (c >= '0' && c <= '9') |
*dst = (c - '0') << 4; |
else if (c >= 'a' && c <= 'f') |
*dst = ((c - 'a') + 10) << 4; |
else if (c >= 'A' && c <= 'F') |
*dst = ((c - 'A') + 10) << 4; |
else |
return EINVAL; |
|
if ((c = fgetc(file)) == EOF) |
return EINVAL; |
|
if (c >= '0' && c <= '9') |
*dst |= (c - '0'); |
else if (c >= 'a' && c <= 'f') |
*dst |= ((c - 'a') + 10); |
else if (c >= 'A' && c <= 'F') |
*dst |= ((c - 'A') + 10); |
else |
return EINVAL; |
|
return 0; |
} |
|
#define decode_uint8(dst) \ |
do { \ |
if (decode_byte(file, &(dst)) < 0) \ |
goto __error; \ |
} while (0) |
|
#define decode_uint16(dst) \ |
do { \ |
if (decode_byte(file, &x) < 0) \ |
goto __error; \ |
(dst) = x << 8; \ |
\ |
if (decode_byte(file, &x) < 0) \ |
goto __error; \ |
(dst) |= x; \ |
} while (0) |
|
int |
mcsdecode(FILE *file, u_int8_t **data, size_t *num) |
{ |
u_int16_t lsb, msb; |
u_int8_t bytes, type, x, val; |
int ret; |
|
*data = NULL; |
ret = EINVAL; |
*num = 0; |
lsb = 0; |
msb = 0; |
|
/* |
* Every line begins with ':'. |
*/ |
if (fgetc(file) != ':') |
return EINVAL; |
|
for(;;) { |
decode_uint8(bytes); /* Line length */ |
decode_uint16(lsb); /* Address LSB */ |
decode_uint8(type); /* Record type */ |
|
switch (type) { |
case 0x00: |
/* |
* Data item. |
*/ |
break; |
case 0x01: |
/* |
* Last record. |
*/ |
return 0; |
case 0x04: |
/* |
* Address MSB. |
*/ |
decode_uint16(msb); |
bytes -= 2; |
break; |
} |
|
*data = (u_int8_t *) realloc(*data, *num + bytes); |
if (*data == NULL) { |
ret = ENOMEM; |
goto __error; |
} |
|
/* |
* Sanity check |
*/ |
if (((((u_int32_t)msb) << 16) | lsb) != *num) |
goto __error; |
|
while (bytes-- > 0) { |
/* |
* Read a byte of data. |
*/ |
decode_uint8(val); |
(*data)[*num] = val; |
(*num)++; |
} |
|
#if 0 |
/* |
* Each line has a CRC. |
*/ |
decode_uint8(crc); |
#endif |
|
/* |
* Skip newline (may be DOS-ish). |
*/ |
do { |
x = fgetc(file); |
} while (x != ':'); |
} |
|
/* Bail out if we failed. */ |
__error: |
if (*data != NULL) { |
free(*data); |
*data = NULL; |
} |
|
*num = 0; |
return ret; |
} |
/trunk/tools/cris-boot/boot.c
0,0 → 1,203
/* $Id: boot.c,v 1.1.1.1 2006-02-04 03:35:00 freza Exp $ */ |
|
#include <sys/mman.h> |
|
#include <errno.h> |
#include <fcntl.h> |
#include <stdarg.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <unistd.h> |
|
|
extern int mcsdecode(FILE *, u_int8_t **, size_t *); |
|
static int verbose = 0; |
static int is_ftp = 0; |
|
#define VERBOSE(arg) if (verbose) warnx arg |
#define TRACE(arg) if (verbose > 1) warnx arg |
|
|
void |
warnx(char *fmt, ...) |
{ |
va_list ap; |
|
if (is_ftp) |
fprintf(stdout, "150-"); |
fprintf(stdout, "boot: "); |
va_start(ap, fmt); |
vfprintf(stdout, fmt, ap); |
va_end(ap); |
fprintf(stdout, "\r\n"); |
} |
|
void |
errx(int ret, char *fmt, ...) |
{ |
va_list ap; |
|
if (is_ftp) |
fprintf(stdout, "510-"); |
fprintf(stderr, "boot: "); |
va_start(ap, fmt); |
vfprintf(stderr, fmt, ap); |
va_end(ap); |
fprintf(stderr, "\n"); |
|
exit(ret); |
} |
|
void |
err(int ret, char *fmt, ...) |
{ |
va_list ap; |
|
if (is_ftp) |
fprintf(stdout, "510-"); |
fprintf(stderr, "boot: "); |
va_start(ap, fmt); |
vfprintf(stderr, fmt, ap); |
va_end(ap); |
fprintf(stderr, ": %s\n", strerror(errno)); |
|
exit(ret); |
} |
|
/* |
* Main and stuff. |
*/ |
#define ARGUMENTS "d:hp:v" |
|
void |
usage() |
{ |
printf("Usage: boot [options] [file.mcs]\n"); |
printf("-d s Use device 's' [/dev/virtex0]\n"); |
printf("-h Print this help\n"); |
printf("-p b Don't boot, set PROG to 'b' (1 or 0)\n"); |
printf("-v Verbose operation\n"); |
} |
|
int |
main(int argc, char *argv[]) |
{ |
FILE *file; |
u_int8_t *data; |
char *path, *device, *str; |
size_t count; |
int fd, progval; |
int c, do_setprog, do_raw_boot; |
|
do_raw_boot = 0; /* via kernel by default */ |
do_setprog = 0; /* boot by default */ |
is_ftp = 0; |
progval = 0; /* gcc */ |
device = "/dev/virtex0"; |
path = NULL; |
|
if ((str = getenv("FTP_METHOD")) != NULL) { |
if (strcasecmp(str, "PUT") == 0) { |
is_ftp = 1; |
} else { |
errx(1, "FTP method %s, only PUT supported", str); |
} |
} |
|
while((c = getopt(argc, argv, ARGUMENTS)) != -1) { |
switch (c) { |
case 'd': /* Select device */ |
device = optarg; |
break; |
|
case 'h': /* Show help */ |
usage(); |
return 0; |
|
case 'p': |
do_setprog = 1; |
switch (optarg[0]) { |
case '0': |
progval = 0; |
break; |
case '1': |
progval = 1; |
break; |
default: |
errx(1, "Argument to -p should be 0 or 1"); |
/*UNREACHED*/ |
} |
break; |
|
case 'v': /* Verbose operation */ |
verbose++; |
break; |
|
default: |
errx(1, "unknown argument -%c", optopt); |
} |
} |
|
argc -= optind; |
argv += optind; |
|
if (argc > (do_setprog ? 0 : 1)) |
errx(1, "stray arguments"); |
|
/* We're going to boot, so read the design. */ |
if (do_setprog == 0) { |
if (argc == 1) |
path = argv[0]; |
|
if (path != NULL) { |
VERBOSE(("open design file %s", path)); |
file = fopen(path, "r"); |
if (file == NULL) |
err(1, "could not open %s", path); |
} else { |
/* NOTE: vftpd is broken in that it will blocking |
* copy statfd (fd 3) to the user until the end, |
* then it will transfer the file, and in the |
* end copy messages again. So we have to close |
* statfd so that we can proceed reading stdin. |
*/ |
if (is_ftp) { |
write(3, "150-boot: design file is stdin\r\n", |
32); |
(void) close(3); |
} else { |
VERBOSE(("design file is stdin")); |
} |
|
file = stdin; |
} |
|
if (mcsdecode(file, &data, &count) != 0) |
errx(1, "could not decode %s", path); |
VERBOSE(("decoded %d bytes", count)); |
} else { |
/* XXX: Control PROG from kernel */ |
return (1); |
} |
|
/* Let's do the well behaved boot then. */ |
VERBOSE(("open device")); |
fd = open(device, O_RDWR, 0); |
if (fd == -1) |
err(1, "could not open %s", device); |
|
VERBOSE(("write configuration stream")); |
if (write(fd, (const void *) data, count) != count) |
err(1, "failed to boot%s", \ |
errno == EIO ? ": CRC error" : ""); |
|
VERBOSE(("acknowledge startup")); |
if (close(fd) == -1) |
err(1, "failed to boot%s", \ |
errno == EIO ? ": DONE timeout" : ""); |
|
VERBOSE(("success")); |
return (0); |
} |
/trunk/tools/cris-boot/Makefile
0,0 → 1,32
# $Id: Makefile,v 1.1.1.1 2006-02-04 03:35:00 freza Exp $ |
|
AXIS_USABLE_LIBS = UCLIBC GLIBC |
include $(AXIS_TOP_DIR)/tools/build/Rules.axis |
|
PROGS= boot |
|
INSTDIR= $(prefix)/bin |
INSTMODE= 0755 |
|
SRCS= boot.c mcs.c |
OBJS= boot.o mcs.o |
|
CFLAGS+= -Wall -Werror |
|
boot: $(OBJS) |
|
all: $(PROGS) |
|
install: $(PROGS) |
$(INSTALL) -d $(INSTDIR) |
$(INSTALL) -m 0755 $(PROGS) $(prefix)/bin |
#$(INSTALL) -m 0644 testled.mcs $(prefix)/ |
|
clean: |
rm -rf $(PROGS) *.o |
|
depend: |
makedepend -Y -- $(CFLAGS) -- $(SRCS) 2>/dev/null |
|
lo: all |
( cd .. ; ./_upload ) |
/trunk/tools/cris-bus/bus.c
0,0 → 1,316
/* $Id: bus.c,v 1.1.1.1 2006-02-04 03:35:01 freza Exp $ */ |
|
#include <sys/mman.h> |
|
#include <errno.h> |
#include <fcntl.h> |
#include <stdarg.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <string.h> |
#include <unistd.h> |
|
#include <asm/page.h> |
|
|
typedef int bus_space_tag_t; |
typedef u_char *bus_space_handle_t; |
|
#define bus_space_read_4(t, h, addr) \ |
*((volatile u_int32_t *) ((h) + (addr))) |
|
#define bus_space_write_4(t, h, addr, val) \ |
(*((volatile u_int32_t *) ((h) + (addr))) = (u_int32_t)(val)) |
|
#define bus_space_read_2(t, h, addr) \ |
*((volatile u_int16_t *) ((h) + (u_int16_t)(addr))) |
|
#define bus_space_write_2(t, h, addr, val) \ |
(*((volatile u_int16_t *) ((h) + (addr))) = (u_int16_t)(val)) |
|
#define bus_space_read_1(t, h, addr) \ |
*((volatile u_int8_t *) ((h) + (addr))) |
|
#define bus_space_write_1(t, h, addr, val) \ |
(*((volatile u_int8_t *) ((h) + (addr))) = (u_int8_t)(val)) |
|
#define VERBOSE(arg) if (verbose) warnx arg |
|
static int verbose = 0; |
|
|
void |
warnx(char *fmt, ...) |
{ |
va_list ap; |
|
fprintf(stderr, "bus: "); |
va_start(ap, fmt); |
vfprintf(stderr, fmt, ap); |
va_end(ap); |
fprintf(stderr, "\n"); |
} |
|
void |
errx(int ret, char *fmt, ...) |
{ |
va_list ap; |
|
fprintf(stderr, "bus: "); |
va_start(ap, fmt); |
vfprintf(stderr, fmt, ap); |
va_end(ap); |
fprintf(stderr, "\n"); |
|
exit(ret); |
} |
|
void |
err(int ret, char *fmt, ...) |
{ |
va_list ap; |
|
fprintf(stderr, "bus: "); |
va_start(ap, fmt); |
vfprintf(stderr, fmt, ap); |
va_end(ap); |
fprintf(stderr, ": %s\n", strerror(errno)); |
|
exit(ret); |
} |
|
|
#include <stdlib.h> |
#include <errno.h> |
|
int |
xstrtou(char *str, u_long *val) |
{ |
char *end; |
int base = 10; |
|
if (str[0] == '0') |
switch (str[1]) { |
case 'x': |
base = 16; |
str += 2; |
break; |
case 'd': |
base = 10; |
str += 2; |
break; |
case 'o': |
base = 8; |
str += 2; |
break; |
case 'b': |
base = 2; |
str += 2; |
break; |
default: |
return EINVAL; |
} |
|
*val = (u_long) strtoul(str, &end, base); |
if (*end != '\0' || str[0] == '\0') |
return EINVAL; |
|
return 0; |
} |
|
int |
bus_space_tag(bus_space_tag_t *t) |
{ |
*t = open("/dev/mem", O_RDWR | O_SYNC, 0); |
if (*t == -1) |
return (errno); |
return 0; |
} |
|
#ifndef PAGE_ALIGN |
#define PAGE_ALIGN(val) (((val) + PAGE_SIZE - 1) & PAGE_MASK) |
#endif |
|
int |
bus_space_map(bus_space_tag_t t, u_int32_t base, u_int32_t size, int flags, |
bus_space_handle_t *h) |
{ |
off_t real; |
|
real = base & PAGE_MASK; |
size = PAGE_ALIGN(size); |
|
VERBOSE(("fd %d, mapping %dB at 0x%08x with offs 0x%08x", |
t, size, real, base % PAGE_SIZE)); |
|
*h = mmap(0, size, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, t, real); |
if (*h == MAP_FAILED) |
return (errno); |
*h += base % PAGE_SIZE; |
|
return (0); |
} |
|
/* |
* Main and stuff. |
*/ |
#define ARGUMENTS "a:b:c:f:hvw:" |
|
void |
usage() |
{ |
printf("Version: $Freza: bus.c,v 1.6 2005/11/22 12:57:25 jh Exp $\n"); |
printf("Usage: bus [opts]\n"); |
printf("-a x Set bus address\n"); |
printf("-b n Set bus access width, one of 1, 2, 4 [4]\n"); |
printf("-c n How many values to process\n"); |
printf("-f s Copy data FROM hexa text file TO memory\n"); |
printf("-h Print this help\n"); |
printf("-v Verbose operation\n"); |
printf("-w x Write value x\n"); |
} |
|
int |
main(int argc, char *argv[]) |
{ |
FILE *data; |
bus_space_handle_t ioh; |
bus_space_tag_t tag; |
u_int32_t addr; |
u_int32_t value; |
int do_write, has_addr; |
int count; |
int width; |
int i, c, ret; |
|
do_write = 0; |
has_addr = 0; |
count = -1; |
width = 4; |
data = NULL; |
|
while((c = getopt(argc, argv, ARGUMENTS)) != -1) { |
switch (c) { |
case 'a': /* Set address */ |
if (xstrtou(optarg, (u_long *) &addr) != 0) |
errx(1, "not a number: %s", optarg); |
has_addr = 1; |
break; |
|
case 'b': /* Set access width */ |
if (xstrtou(optarg, (u_long *) &width) != 0) |
errx(1, "not a number: %s", optarg); |
switch (width) { |
case 1: |
case 2: |
case 4: |
break; |
default: |
errx(1, "bad width: %d", width); |
} |
break; |
|
case 'c': /* Set value count */ |
if (xstrtou(optarg, (u_long *) &count) != 0) |
errx(1, "not a number: %s", optarg); |
break; |
|
case 'f': /* File to read from/write to */ |
do_write = 1; |
if ((data = fopen(optarg, "r")) == NULL) |
err(1, "could not open %s", optarg); |
|
break; |
|
case 'h': /* Show help */ |
usage(); |
return 0; |
|
case 'v': /* Verbose operation */ |
verbose = 1; |
break; |
|
case 'w': /* Value to write */ |
if (xstrtou(optarg, (u_long *) &value) != 0) |
errx(1, "not a number: %s", optarg); |
do_write = 1; |
break; |
|
default: |
errx(1, "unknown argument -%c", optopt); |
} |
} |
|
argc -= optind; |
argv += optind; |
|
/* Validate user isn't insane. */ |
if (argc > 0) |
errx(1, "stray arguments"); |
|
if (! has_addr) |
errx(1, "address is mandatory"); |
|
/* Grab bus space. */ |
if ((ret = bus_space_tag(&tag)) != 0) |
err(1, "could not access physical memory, error %d", ret); |
|
if (count == -1) { |
if (data != NULL) |
count = PAGE_SIZE / width; |
else |
count = 1; |
} |
|
if ((ret = bus_space_map(tag, addr, count * width, 0, &ioh)) != 0) |
err(1, "could not map bus space, error %d", ret); |
|
if (do_write) { |
for (i = 0; i < count; i++) { |
if (data != NULL) { |
if (fscanf(data, "%x", &value) != 1) { |
if (feof(data)) |
break; |
else |
if (ferror(data)) |
err(1, "file read error"); |
else |
err(1, "invalid input"); |
} |
} |
VERBOSE(("[%03d] 0x%08x <- 0x%08x", i, |
addr + i * width, value)); |
|
switch (width) { |
case 1: |
bus_space_write_1(tag, ioh, i * width, value); |
break; |
case 2: |
bus_space_write_2(tag, ioh, i * width, value); |
break; |
case 4: |
bus_space_write_4(tag, ioh, i * width, value); |
break; |
} |
} |
} else { |
for (i = 0; i < count; i++) { |
switch (width) { |
case 1: |
value = bus_space_read_1(tag, ioh, i * width); |
printf("%02x\n", value); |
break; |
case 2: |
value = bus_space_read_2(tag, ioh, i * width); |
printf("%04x\n", value); |
break; |
case 4: |
value = bus_space_read_4(tag, ioh, i * width); |
printf("%08x\n", value); |
break; |
} |
} |
} |
|
return (0); |
} |
/trunk/tools/cris-bus/Makefile
0,0 → 1,28
# $Id: Makefile,v 1.1.1.1 2006-02-04 03:35:01 freza Exp $ |
|
AXIS_USABLE_LIBS = UCLIBC GLIBC |
include $(AXIS_TOP_DIR)/tools/build/Rules.axis |
|
PROGS= bus |
|
INSTDIR= $(prefix)/bin |
INSTMODE= 0755 |
|
SRCS= bus.c |
OBJS= bus.o |
|
CFLAGS+= -Wall -Werror |
|
boot: $(OBJS) |
|
all: $(PROGS) |
|
install: $(PROGS) |
$(INSTALL) -d $(INSTDIR) |
$(INSTALL) -m $(INSTMODE) $(PROGS) $(INSTDIR) |
|
clean: |
rm -rf $(PROGS) *.o |
|
depend: |
makedepend -Y -- $(CFLAGS) -- $(SRCS) 2>/dev/null |