mirror of
git://projects.qi-hardware.com/xburst-tools.git
synced 2024-11-01 10:22:48 +02:00
USB abstraction: implemented sent length checking
Ingenic: implemented SDRAM load and go USBBoot cmdset: implemented 'load' and 'go'
This commit is contained in:
parent
4a19dabdd4
commit
86ba12af12
76
ingenic.c
76
ingenic.c
@ -238,8 +238,8 @@ uint32_t ingenic_sdram_size(void *hndl) {
|
||||
return handle->total_sdram_size;
|
||||
}
|
||||
|
||||
static int ingenic_address(void *usb, uint32_t base) {
|
||||
return usbdev_vendor(usb, USBDEV_TODEV, VR_SET_DATA_ADDRESS, (base >> 16), base & 0xFFFF, 0, 0);
|
||||
static int ingenic_wordop(void *usb, int op, uint32_t base) {
|
||||
return usbdev_vendor(usb, USBDEV_TODEV, op, (base >> 16), base & 0xFFFF, 0, 0);
|
||||
}
|
||||
|
||||
int ingenic_stage1_debugop(void *hndl, const char *filename, uint32_t op, uint32_t pin, uint32_t base, uint32_t size) {
|
||||
@ -307,7 +307,7 @@ int ingenic_loadstage(void *hndl, int id, const char *file) {
|
||||
|
||||
memcpy(data + 8, &handle->cfg, sizeof(firmware_config_t));
|
||||
|
||||
if(ingenic_address(handle->usb, base) == -1) {
|
||||
if(ingenic_wordop(handle->usb, VR_SET_DATA_ADDRESS, base) == -1) {
|
||||
free(data);
|
||||
|
||||
return -1;
|
||||
@ -403,3 +403,73 @@ int ingenic_configure_stage2(void *hndl) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ingenic_load_sdram(void *hndl, void *data, uint32_t base, uint32_t size) {
|
||||
HANDLE;
|
||||
|
||||
while(size) {
|
||||
int block = size > 65535 ? 65535 : size;
|
||||
|
||||
debug(LEVEL_DEBUG, "Loading SDRAM from %p to 0x%08X, size %u\n", data, base, block);
|
||||
|
||||
if(ingenic_wordop(handle->usb, VR_SET_DATA_ADDRESS, base) == -1)
|
||||
return -1;
|
||||
|
||||
if(ingenic_wordop(handle->usb, VR_SET_DATA_LENGTH, block) == -1)
|
||||
return -1;
|
||||
|
||||
|
||||
if(usbdev_sendbulk(handle->usb, data, block) == -1)
|
||||
return -1;
|
||||
|
||||
|
||||
|
||||
if(usbdev_vendor(handle->usb, USBDEV_TODEV, VR_SDRAM_OPS, SDRAM_LOAD, 0, 0, 0) == -1)
|
||||
return -1;
|
||||
|
||||
uint32_t result[8];
|
||||
|
||||
if(usbdev_recvbulk(handle->usb, result, sizeof(result)) == -1)
|
||||
return -1;
|
||||
|
||||
data += 65535;
|
||||
base += 65535;
|
||||
if(size <= 65535)
|
||||
break;
|
||||
|
||||
size -= 65535;
|
||||
}
|
||||
debug(LEVEL_DEBUG, "Load done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ingenic_load_sdram_file(void *hndl, uint32_t base, const char *file) {
|
||||
HANDLE;
|
||||
|
||||
FILE *fd = fopen(file, "rb");
|
||||
|
||||
if(fd == NULL)
|
||||
return -1;
|
||||
|
||||
fseek(fd, 0, SEEK_END);
|
||||
int size = ftell(fd);
|
||||
fseek(fd, 0, SEEK_SET);
|
||||
|
||||
void *data = malloc(size);
|
||||
fread(data, size, 1, fd);
|
||||
|
||||
fclose(fd);
|
||||
|
||||
int ret = ingenic_load_sdram(handle, data, base, size);
|
||||
|
||||
free(data);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ingenic_go(void *hndl, uint32_t address) {
|
||||
HANDLE;
|
||||
|
||||
return ingenic_wordop(handle->usb, VR_PROGRAM_START2, address);
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,9 @@ int ingenic_stage1_debugop(void *device, const char *filename, uint32_t op, uint
|
||||
int ingenic_memtest(void *hndl, const char *filename, uint32_t base, uint32_t size, uint32_t *fail);
|
||||
|
||||
int ingenic_configure_stage2(void *hndl);
|
||||
int ingenic_load_sdram(void *hndl, void *data, uint32_t base, uint32_t size);
|
||||
int ingenic_load_sdram_file(void *hndl, uint32_t base, const char *filename);
|
||||
int ingenic_go(void *hndl, uint32_t address);
|
||||
|
||||
#define CMDSET_SPL 1
|
||||
#define CMDSET_USBBOOT 2
|
||||
@ -54,6 +57,9 @@ int ingenic_configure_stage2(void *hndl);
|
||||
|
||||
#define DS_flash_info 0
|
||||
#define DS_hand 1
|
||||
|
||||
#define SDRAM_LOAD 0
|
||||
|
||||
typedef struct {
|
||||
/* debug args */
|
||||
uint8_t debug_ops;
|
||||
|
@ -18,15 +18,20 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "shell.h"
|
||||
#include "config.h"
|
||||
#include "ingenic.h"
|
||||
|
||||
static int usbboot_boot(int argc, char *argv[]);
|
||||
static int usbboot_load(int argc, char *argv[]);
|
||||
static int usbboot_go(int argc, char *argv[]);
|
||||
|
||||
const shell_command_t usbboot_cmdset[] = {
|
||||
{ "boot", "- Reconfigure stage2", usbboot_boot },
|
||||
{ "load", "<FILE> <BASE> - Load file to SDRAM", usbboot_load },
|
||||
{ "go", "<ADDRESS> - Jump to <ADDRESS>", usbboot_go },
|
||||
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
@ -40,3 +45,33 @@ static int usbboot_boot(int argc, char *argv[]) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int usbboot_load(int argc, char *argv[]) {
|
||||
if(argc != 3) {
|
||||
printf("Usage: %s <FILE> <BASE>\n", argv[0]);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = ingenic_load_sdram_file(shell_device(), strtoul(argv[2], NULL, 0), argv[1]);
|
||||
|
||||
if(ret == -1)
|
||||
perror("ingenic_load_sdram_file");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int usbboot_go(int argc, char *argv[]) {
|
||||
if(argc != 2) {
|
||||
printf("Usage: %s <ADDRESS>\n", argv[0]);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = ingenic_go(shell_device(), strtoul(argv[1], NULL, 0));
|
||||
|
||||
if(ret == -1)
|
||||
perror("ingenic_go");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
14
usbdev.c
14
usbdev.c
@ -141,7 +141,19 @@ int usbdev_sendbulk(void *hndl, void *data, int size) {
|
||||
|
||||
debug(LEVEL_DEBUG, "Bulk: writing data %p, size %d\n", data, size);
|
||||
|
||||
return translate_libusb(libusb_bulk_transfer(hndl, ENDPOINT_OUT, data, size, &trans, CONTROL_TIMEOUT));
|
||||
if(translate_libusb(libusb_bulk_transfer(hndl, ENDPOINT_OUT, data, size, &trans, CONTROL_TIMEOUT)) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(trans != size) {
|
||||
debug(LEVEL_WARNING, "Bulk data truncated: requested %d, sent %d\n", size, trans);
|
||||
|
||||
errno = EIO;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int usbdev_recvbulk(void *hndl, void *data, int size) {
|
||||
|
Loading…
Reference in New Issue
Block a user