1
0
mirror of git://projects.qi-hardware.com/xburst-tools.git synced 2024-11-25 18:44:40 +02:00
This commit is contained in:
Lars-Peter Clausen 2010-02-03 16:21:08 +01:00
parent 9aa52b7947
commit f040ec232f
3 changed files with 194 additions and 0 deletions

61
usbboot/src/mem.c Normal file
View File

@ -0,0 +1,61 @@
#include <stdint.h>
#include <stdio.h>
#include "ingenic_usb.h"
#define MEM_WRITE 0
#define MEM_READ 1
#define MEM_8BIT (0 << 1)
#define MEM_16BIT (1 << 1)
#define MEM_32BIT (2 << 1)
static void mem_write(struct ingenic_dev *dev, uint32_t addr, uint32_t val, unsigned int width)
{
char ret[8];
usb_send_data_address_to_ingenic(dev, addr);
usb_send_data_length_to_ingenic(dev, val);
usb_ingenic_mem_ops(dev, MEM_WRITE | width);
usb_read_data_from_ingenic(dev, ret, ARRAY_SIZE(ret));
}
static uint32_t mem_read(struct ingenic_dev *dev, uint32_t addr, unsigned int width)
{
char ret[8];
usb_send_data_address_to_ingenic(dev, addr);
usb_ingenic_mem_ops(dev, MEM_READ | width);
usb_read_data_from_ingenic(dev, ret, ARRAY_SIZE(ret));
return (((unsigned char)ret[3]) << 24) | (((unsigned char)ret[2]) << 16) |
(((unsigned char)ret[1]) << 8) | ((unsigned char)ret[0]);
}
void mem_write8(struct ingenic_dev *dev, uint32_t addr, uint8_t val)
{
mem_write(dev, addr, val, MEM_8BIT);
}
void mem_write16(struct ingenic_dev *dev, uint32_t addr, uint16_t val)
{
mem_write(dev, addr, val, MEM_16BIT);
}
void mem_write32(struct ingenic_dev *dev, uint32_t addr, uint32_t val)
{
mem_write(dev, addr, val, MEM_32BIT);
}
uint8_t mem_read8(struct ingenic_dev *dev, uint32_t addr)
{
uint8_t val = mem_read(dev, addr, MEM_8BIT) & 0xff;
return val;
}
uint16_t mem_read16(struct ingenic_dev *dev, uint32_t addr)
{
return mem_read(dev, addr, MEM_16BIT) & 0xffff;
}
uint32_t mem_read32(struct ingenic_dev *dev, uint32_t addr)
{
return mem_read(dev, addr, MEM_32BIT);
}

13
usbboot/src/mem.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef __MEM_H
#define __MEM_H
struct ingenic_dev;
void mem_write32(struct ingenic_dev *dev, uint32_t addr, uint32_t val);
void mem_write16(struct ingenic_dev *dev, uint32_t addr, uint16_t val);
void mem_write8(struct ingenic_dev *dev, uint32_t addr, uint8_t val);
uint32_t mem_read32(struct ingenic_dev *dev, uint32_t addr);
uint16_t mem_read16(struct ingenic_dev *dev, uint32_t addr);
uint8_t mem_read8(struct ingenic_dev *dev, uint32_t addr);
#endif

120
usbboot/src/server.c Normal file
View File

@ -0,0 +1,120 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "mem.h"
#include "cmd.h"
#include "ingenic_usb.h"
#include "ingenic_cfg.h"
#define PORT 1338
#define TYPE_READ8 0
#define TYPE_READ16 1
#define TYPE_READ32 2
#define TYPE_WRITE8 3
#define TYPE_WRITE16 4
#define TYPE_WRITE32 5
struct request {
uint32_t addr;
uint32_t value;
uint8_t type;
};
struct response {
uint32_t value;
};
#define CONFIG_FILE_PATH "/etc/xburst-tools/usbboot.cfg"
struct ingenic_dev ingenic_dev;
int main(int argc, char *argv[])
{
int s, t;
unsigned int sinlen;
struct sockaddr_in sin;
struct request request;
struct response response;
char *cfgpath = CONFIG_FILE_PATH;
if (usb_ingenic_init(&ingenic_dev))
return EXIT_FAILURE;
if (parse_configure(&ingenic_dev.config, cfgpath))
return EXIT_FAILURE;
boot(&ingenic_dev, STAGE1_FILE_PATH, STAGE2_FILE_PATH);
if ( (s = socket(AF_INET, SOCK_STREAM, 0 ) ) < 0) {
return -1;
}
sin.sin_family = AF_INET; /*set protocol family to Internet */
sin.sin_port = htons(PORT); /* set port no. */
sin.sin_addr.s_addr = INADDR_ANY; /* set IP addr to any interface */
if (bind(s, (struct sockaddr *)&sin, sizeof(sin) ) < 0 ){
perror("bind"); return -1; /* bind error */
}
/* server indicates it's ready, max. listen queue is 5 */
if (listen(s, 5)) {
return -1;
}
sinlen = sizeof(sin);
if ( (t = accept(s, (struct sockaddr *) &sin, &sinlen) ) < 0 ){
perror("accept "); /* accpet error */
return -1;
}
while (1) {
if (recv(t, (char*)&request, sizeof(request), 0) < 0) {
perror("recv");
return -1;
}
/* printf("Got request %x %x %x\n", request.type, request.addr,
request.value);*/
switch (request.type) {
case TYPE_READ8:
response.value = mem_read8(&ingenic_dev, request.addr);
break;
case TYPE_READ16:
response.value = mem_read16(&ingenic_dev, request.addr);
break;
case TYPE_READ32:
response.value = mem_read32(&ingenic_dev, request.addr);
break;
case TYPE_WRITE8:
mem_write8(&ingenic_dev, request.addr, request.value);
break;
case TYPE_WRITE16:
mem_write16(&ingenic_dev, request.addr, request.value);
break;
case TYPE_WRITE32:
mem_write32(&ingenic_dev, request.addr, request.value);
break;
}
/* printf("Got response %x\n", response.value);*/
if (send(t, (char*)&response, sizeof(response),0 ) < 0 ) {
perror("send");
return -1;
}
}
close(t);
close(s);
return 0;
}