diff options
Diffstat (limited to 'scripts/omap3-usb-loader.c')
-rw-r--r-- | scripts/omap3-usb-loader.c | 70 |
1 files changed, 9 insertions, 61 deletions
diff --git a/scripts/omap3-usb-loader.c b/scripts/omap3-usb-loader.c index 0f352c8453..38cdbfac93 100644 --- a/scripts/omap3-usb-loader.c +++ b/scripts/omap3-usb-loader.c @@ -19,10 +19,6 @@ #define PROG_NAME "OMAP Loader" #define VERSION "1.0.0" -#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) -#define OMAP_IS_BIG_ENDIAN -#endif - #include <unistd.h> /* for usleep and friends */ #include <getopt.h> #include <errno.h> @@ -30,6 +26,9 @@ #include <libusb.h> /* the main event */ +#include "common.h" +#include "common.c" + /* Device specific defines (OMAP) * Primary source: http://www.ti.com/lit/pdf/sprugn4 * Section 26.4.5 "Peripheral Booting" @@ -43,15 +42,6 @@ #define OMAP_USB_BULK_OUT 0x01 #define OMAP_ASIC_ID_LEN 69 -#ifdef OMAP_IS_BIG_ENDIAN -#define cpu_to_le32(v) (((v & 0xff) << 24) | ((v & 0xff00) << 8) | \ - ((v & 0xff0000) >> 8) | ((v & 0xff000000) >> 24)) -#define le32_to_cpu(v) cpu_to_le32(v) -#else -#define cpu_to_le32(v) (v) -#define le32_to_cpu(v) (v) -#endif - /* * taken from x-loader/drivers/usb/usb.c * All credit to Martin Mueller @@ -325,50 +315,6 @@ found: return handle; } -static unsigned char *read_file(char *path, size_t *readamt) -{ - FILE *fp = fopen(path, "rb"); - - if (!fp) { - log_error("failed to open file \'%s\': %s\n", path, - strerror(errno)); - return NULL; - } - - unsigned char *data = NULL; - size_t allocsize = 0; - size_t iter = 0; - - while (1) { - allocsize += 1024; - data = realloc(data, allocsize); - if (!data) - return NULL; - - size_t readsize = allocsize - iter; - size_t ret = fread(data + iter, sizeof (unsigned char), readsize, fp); - - iter += ret; - - if (ret != readsize) { - if (feof(fp)) { - break; - } else if (ferror(fp)) { - log_error("error file reading file \'%s\': %s\n", - path, strerror(errno)); - free(data); - return NULL; - } - } - } - - /* trim the allocation down to size */ - data = realloc(data, iter); - *readamt = iter; - - return data; -} - static int transfer_first_stage(libusb_device_handle * handle, struct arg_state *args) { unsigned char *buffer = NULL; @@ -384,7 +330,7 @@ static int transfer_first_stage(libusb_device_handle * handle, struct arg_state /* TODO determine buffer size based on endpoint */ buffer = calloc(bufsize, sizeof (unsigned char)); - filelen = cpu_to_le32(file->size); + filelen = file->size; data = file->data; dbuf = data; @@ -451,6 +397,8 @@ static int transfer_first_stage(libusb_device_handle * handle, struct arg_state goto fail; } + filelen = cpu_to_le32(filelen); + /* send the length of the first file (little endian) */ if (!omap_usb_write (handle, (unsigned char *) &filelen, sizeof (filelen))) { @@ -460,9 +408,9 @@ static int transfer_first_stage(libusb_device_handle * handle, struct arg_state } /* send the file! */ - if (!omap_usb_write(handle, data, filelen)) { + if (!omap_usb_write(handle, data, file->size)) { log_error("failed to send file \'%s\' (size %u)\n", - file->basename, filelen); + file->basename, file->size); goto fail; } @@ -825,7 +773,7 @@ int main(int argc, char *argv[]) file.addr = OMAP_BASE_ADDRESS; /* commit the file object with the processor specified base address */ - args->files = realloc(args->files, filecount); + args->files = realloc(args->files, filecount * sizeof(*args->files)); args->numfiles = filecount; args->files[filecount - 1] = malloc(sizeof (file)); memcpy(args->files[filecount - 1], &file, sizeof (file)); |