Commit bfa1c4d9 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

tools: lm32-loader works over raw Ethernet, genraminit adapted to general-cores RAM format

parent 8b8a31c7
CFLAGS = -Wall -ggdb -I. -I../include CFLAGS = -Wall -ggdb -I. -I../include -Imini_bone
AS = $(CROSS_COMPILE)as AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld LD = $(CROSS_COMPILE)ld
...@@ -12,9 +12,10 @@ OBJDUMP = $(CROSS_COMPILE)objdump ...@@ -12,9 +12,10 @@ OBJDUMP = $(CROSS_COMPILE)objdump
all: lm32-loader genraminit vuart_console all: lm32-loader genraminit vuart_console
OBJS_LOADER = lm32-loader.o rr_io.o OBJS_LOADER = lm32-loader.o rr_io.o mini_bone/ptpd_netif.o mini_bone/minibone_lib.o
lm32-loader: $(OBJS_LOADER) lm32-loader: $(OBJS_LOADER)
# make -C mini_bone
${CC} -o lm32-loader $(OBJS_LOADER) ${CC} -o lm32-loader $(OBJS_LOADER)
genraminit: genraminit.o genraminit: genraminit.o
......
...@@ -13,13 +13,9 @@ main(int argc, char *argv[]) ...@@ -13,13 +13,9 @@ main(int argc, char *argv[])
while(!feof(f)) while(!feof(f))
{ {
fread(x,1,4,f); fread(x,1,4,f);
printf("%d => x\"%02X%02X%02X%02X\",\n", i++, x[0],x[1],x[2],x[3]); printf("write %x %02X%02X%02X%02X\n", i++, x[0], x[1], x[2], x[3]);
} }
for(;i<n;)
{
printf("%d => x\"%02X%02X%02X%02X\",\n", i++, 0,0,0,0);
}
fclose(f); fclose(f);
return 0; return 0;
} }
\ No newline at end of file
...@@ -37,7 +37,7 @@ static void *mb_handle = NULL; ...@@ -37,7 +37,7 @@ static void *mb_handle = NULL;
static void spec_writel(uint32_t value, uint32_t addr) static void spec_writel(uint32_t value, uint32_t addr)
{ {
if(mb_handle) if(mb_handle)
mbn_writel(mb_handle, value, BASE_MBONE + addr); mbn_writel(mb_handle, value, (BASE_MBONE + addr)>>2);
else else
rr_writel(value, BASE_PCIE + addr); rr_writel(value, BASE_PCIE + addr);
} }
...@@ -46,7 +46,7 @@ static uint32_t spec_readl(uint32_t addr) ...@@ -46,7 +46,7 @@ static uint32_t spec_readl(uint32_t addr)
{ {
uint32_t rval; uint32_t rval;
if(mb_handle) if(mb_handle)
rval = mbn_readl(mb_handle, BASE_MBONE + addr); rval = mbn_readl(mb_handle, (BASE_MBONE + addr)>>2);
else else
rval = rr_readl(BASE_PCIE + addr); rval = rr_readl(BASE_PCIE + addr);
...@@ -142,10 +142,16 @@ int main(int argc, char **argv) ...@@ -142,10 +142,16 @@ int main(int argc, char **argv)
buf = malloc(size + 4); buf = malloc(size + 4);
fread(buf, 1, size, f); fread(buf, 1, size, f);
fclose(f); fclose(f);
rst_lm32(1); rst_lm32(1);
copy_lm32(buf, (size + 3) / 4, 0); rst_lm32(1);
rst_lm32(0); rst_lm32(1);
rst_lm32(1);
copy_lm32(buf, (size + 3) / 4, 0);
rst_lm32(0);
// mbn_stats(mb_handle);
return 0; return 0;
} }
\ No newline at end of file
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#define F_READBACK (1<<0) #define F_READBACK (1<<0)
#define F_WRITE (1<<4) #define F_WRITE (1<<4)
#define RX_TIMEOUT 100 #define RX_TIMEOUT 10
#define MBN_ETHERTYPE 0xa0a0 #define MBN_ETHERTYPE 0xa0a0
...@@ -30,6 +30,7 @@ struct mb_device { ...@@ -30,6 +30,7 @@ struct mb_device {
mac_addr_t dest; mac_addr_t dest;
uint16_t ethertype; uint16_t ethertype;
wr_socket_t *sock; wr_socket_t *sock;
int tx_packets, rx_packets, tx_retries, rx_retries;
}; };
typedef struct typedef struct
...@@ -74,7 +75,9 @@ void *mbn_open(const char *if_name, mac_addr_t target) ...@@ -74,7 +75,9 @@ void *mbn_open(const char *if_name, mac_addr_t target)
if(!dev) if(!dev)
return NULL; return NULL;
memset(dev, 0, sizeof(struct mb_device));
memcpy(dev->dest, target, 6); memcpy(dev->dest, target, 6);
strcpy(saddr.if_name, if_name); strcpy(saddr.if_name, if_name);
memcpy(saddr.mac, target, 6); memcpy(saddr.mac, target, 6);
...@@ -92,6 +95,7 @@ void *mbn_open(const char *if_name, mac_addr_t target) ...@@ -92,6 +95,7 @@ void *mbn_open(const char *if_name, mac_addr_t target)
return (void *)dev; return (void *)dev;
} }
static int mbn_send(void *priv, uint8_t *data, int size) static int mbn_send(void *priv, uint8_t *data, int size)
{ {
struct mb_device *dev = (struct mb_device *)priv; struct mb_device *dev = (struct mb_device *)priv;
...@@ -115,29 +119,50 @@ static int mbn_recv(void *handle, uint8_t *data, int size, int timeout) ...@@ -115,29 +119,50 @@ static int mbn_recv(void *handle, uint8_t *data, int size, int timeout)
if(n > 0 && from.ethertype == MBN_ETHERTYPE && !memcmp(from.mac, dev->dest, 6)) if(n > 0 && from.ethertype == MBN_ETHERTYPE && !memcmp(from.mac, dev->dest, 6))
{ {
dev->rx_packets++;
return n; return n;
} }
// dev->rx_retries++;
} while(!tmo_expired(&rx_tmo)); } while(!tmo_expired(&rx_tmo));
return 0; return 0;
} }
void mbn_writel(void *handle, uint32_t d, uint32_t a) void mbn_writel(void *handle, uint32_t d, uint32_t a)
{ {
struct mb_device *dev = (struct mb_device *)handle;
int n_retries = 3; int n_retries = 3;
struct mbn_packet pkt; struct mbn_packet pkt;
pkt.flags = htons(F_SEL(0xf) | F_WRITE);
pkt.a_d= htonl(a);
pkt.d=htonl(d);
while(n_retries--) while(n_retries--)
{ {
pkt.flags = htons(F_SEL(0xf) | F_WRITE);
pkt.a_d= htonl(a);
pkt.d=htonl(d);
mbn_send(handle, (uint8_t *)&pkt, sizeof(pkt)); mbn_send(handle, (uint8_t *)&pkt, sizeof(pkt));
int n = mbn_recv(handle, (uint8_t *)&pkt, sizeof(pkt), RX_TIMEOUT); int n = mbn_recv(handle, (uint8_t *)&pkt, sizeof(pkt), RX_TIMEOUT);
pkt.flags = ntohs(pkt.flags); pkt.flags = ntohs(pkt.flags);
if(n == sizeof(pkt) && !(pkt.flags && F_READBACK) && !(pkt.flags & F_ERROR)) if(n == sizeof(pkt) && ! (!(pkt.flags && F_READBACK) && !(pkt.flags & F_ERROR)))
{ {
int i;
fprintf(stderr,"\nBadPacket: ");
for(i=0;i<n; i++) fprintf(stderr,"%02x ", *(uint8_t*) (&pkt + i));
fprintf(stderr,"\n");
} if(n == sizeof(pkt) && !(pkt.flags && F_READBACK) && !(pkt.flags & F_ERROR))
{
int i;
// fprintf(stderr,"GoodFlags: %x\n", pkt.flags);
/*fprintf(stderr,"\nGoodPacket: ");
for(i=0;i<n; i++) fprintf(stderr,"%02x ", *(uint8_t*) (&pkt + i));
fprintf(stderr,"\n");*/
dev->tx_packets++;
return ; return ;
} }
dev->tx_retries++;
} }
fprintf(stderr, "No ack.\n"); fprintf(stderr, "No ack.\n");
...@@ -146,6 +171,7 @@ void mbn_writel(void *handle, uint32_t d, uint32_t a) ...@@ -146,6 +171,7 @@ void mbn_writel(void *handle, uint32_t d, uint32_t a)
uint32_t mbn_readl(void *handle, uint32_t a) uint32_t mbn_readl(void *handle, uint32_t a)
{ {
int n_retries = 3; int n_retries = 3;
struct mb_device *dev = (struct mb_device *)handle;
struct mbn_packet pkt; struct mbn_packet pkt;
pkt.flags = htons(F_SEL(0xf)); pkt.flags = htons(F_SEL(0xf));
pkt.a_d= htonl(a); pkt.a_d= htonl(a);
...@@ -159,11 +185,20 @@ uint32_t mbn_readl(void *handle, uint32_t a) ...@@ -159,11 +185,20 @@ uint32_t mbn_readl(void *handle, uint32_t a)
{ {
return ntohl(pkt.a_d); return ntohl(pkt.a_d);
} }
dev->tx_retries++;
} }
fprintf(stderr, "No ack.\n"); fprintf(stderr, "No ack.\n");
} }
void mbn_stats(void *handle)
{
struct mb_device *dev = (struct mb_device *)handle;
fprintf(stderr,"Sent: %d [retries: %d], rcvd: %d [retries: %d]\n", dev->tx_packets, dev->tx_retries, dev->rx_packets, dev->rx_retries);
}
void mbn_close(void *handle) void mbn_close(void *handle)
{ {
struct mb_device *dev = (struct mb_device *)handle; struct mb_device *dev = (struct mb_device *)handle;
......
...@@ -176,8 +176,8 @@ int ptpd_netif_sendto(wr_socket_t *sock, wr_sockaddr_t *to, void *data, ...@@ -176,8 +176,8 @@ int ptpd_netif_sendto(wr_socket_t *sock, wr_sockaddr_t *to, void *data,
size_t len = data_length + sizeof(struct ethhdr); size_t len = data_length + sizeof(struct ethhdr);
if(len < 64) if(len < 72)
len = 64; len = 72;
memset(&sll, 0, sizeof(struct sockaddr_ll)); memset(&sll, 0, sizeof(struct sockaddr_ll));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment