From 70a67ce7ed0791eb79eb05d075f310612f9f50fb Mon Sep 17 00:00:00 2001 From: Florent Kermarrec Date: Mon, 18 May 2020 21:04:54 +0200 Subject: [PATCH] software/bios: rename libnet to libliteeth and move all ethernet files to it. --- litex/soc/integration/builder.py | 2 +- litex/soc/software/bios/Makefile | 6 +-- litex/soc/software/bios/boot.c | 6 +-- litex/soc/software/bios/main.c | 2 +- litex/soc/software/common.mak | 7 ++- litex/soc/software/include/net/microudp.h | 20 -------- .../software/{libnet => libliteeth}/Makefile | 12 ++--- .../software/{libnet => libliteeth}/tftp.c | 48 +++++++++---------- .../{include/net => libliteeth}/tftp.h | 0 .../{libnet/microudp.c => libliteeth/udp.c} | 24 +++++----- litex/soc/software/libliteeth/udp.h | 20 ++++++++ 11 files changed, 76 insertions(+), 71 deletions(-) delete mode 100644 litex/soc/software/include/net/microudp.h rename litex/soc/software/{libnet => libliteeth}/Makefile (57%) rename litex/soc/software/{libnet => libliteeth}/tftp.c (83%) rename litex/soc/software/{include/net => libliteeth}/tftp.h (100%) rename litex/soc/software/{libnet/microudp.c => libliteeth/udp.c} (96%) create mode 100644 litex/soc/software/libliteeth/udp.h diff --git a/litex/soc/integration/builder.py b/litex/soc/integration/builder.py index 4fd1b233..79c6b95d 100644 --- a/litex/soc/integration/builder.py +++ b/litex/soc/integration/builder.py @@ -25,7 +25,7 @@ __all__ = ["soc_software_packages", "soc_directory", soc_software_packages = [ "libcompiler_rt", "libbase", - "libnet", + "libliteeth", "bios" ] diff --git a/litex/soc/software/bios/Makefile b/litex/soc/software/bios/Makefile index ac7725e6..8d4090b7 100755 --- a/litex/soc/software/bios/Makefile +++ b/litex/soc/software/bios/Makefile @@ -59,15 +59,15 @@ endif bios.elf: $(BIOS_DIRECTORY)/linker.ld $(OBJECTS) -%.elf: ../libbase/crt0-ctr.o ../libnet/libnet.a ../libbase/libbase-nofloat.a ../libcompiler_rt/libcompiler_rt.a +%.elf: ../libbase/crt0-ctr.o ../libliteeth/libliteeth.a ../libbase/libbase-nofloat.a ../libcompiler_rt/libcompiler_rt.a $(LD) $(LDFLAGS) -T $(BIOS_DIRECTORY)/linker.ld -N -o $@ \ ../libbase/crt0-ctr.o \ $(OBJECTS) \ - -L../libnet \ + -L../libliteeth \ -L../libbase \ -L../libcompiler_rt \ $(BP_LIBS) \ - -lnet -lbase-nofloat -lcompiler_rt \ + -lliteeth -lbase-nofloat -lcompiler_rt \ $(BP_FLAGS) ifneq ($(OS),Windows_NT) diff --git a/litex/soc/software/bios/boot.c b/litex/soc/software/bios/boot.c index c12cfe25..36993a6f 100644 --- a/litex/soc/software/bios/boot.c +++ b/litex/soc/software/bios/boot.c @@ -21,8 +21,8 @@ #include #ifdef CSR_ETHMAC_BASE -#include -#include +#include +#include #endif #ifdef CSR_SPIFLASH_BASE @@ -340,7 +340,7 @@ void netboot(void) ip = IPTOINT(REMOTEIP1, REMOTEIP2, REMOTEIP3, REMOTEIP4); - microudp_start(macadr, IPTOINT(LOCALIP1, LOCALIP2, LOCALIP3, LOCALIP4)); + udp_start(macadr, IPTOINT(LOCALIP1, LOCALIP2, LOCALIP3, LOCALIP4)); tftp_port = TFTP_SERVER_PORT; printf("Fetching from: UDP/%d\n", tftp_port); diff --git a/litex/soc/software/bios/main.c b/litex/soc/software/bios/main.c index 7864260a..a9857c88 100644 --- a/litex/soc/software/bios/main.c +++ b/litex/soc/software/bios/main.c @@ -30,7 +30,7 @@ #include #ifdef CSR_ETHMAC_BASE -#include +#include "udp.h" #endif #ifdef CSR_SPIFLASH_BASE diff --git a/litex/soc/software/common.mak b/litex/soc/software/common.mak index 83f1aba4..fb97fc48 100644 --- a/litex/soc/software/common.mak +++ b/litex/soc/software/common.mak @@ -45,7 +45,12 @@ DEPFLAGS += -MD -MP # Toolchain options # -INCLUDES = -I$(SOC_DIRECTORY)/software/include/base -I$(SOC_DIRECTORY)/software/include -I$(SOC_DIRECTORY)/common -I$(BUILDINC_DIRECTORY) -I$(CPU_DIRECTORY) +INCLUDES = -I$(SOC_DIRECTORY)/software/include/base \ + -I$(SOC_DIRECTORY)/software/include \ + -I$(SOC_DIRECTORY)/common \ + -I$(BUILDINC_DIRECTORY) \ + -I$(CPU_DIRECTORY) \ + -I$(SOC_DIRECTORY)/software/libliteeth COMMONFLAGS = $(DEPFLAGS) -Os $(CPUFLAGS) -g3 -fomit-frame-pointer -Wall -fno-builtin -nostdinc $(INCLUDES) CFLAGS = $(COMMONFLAGS) -fexceptions -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes CXXFLAGS = $(COMMONFLAGS) -std=c++11 -I$(SOC_DIRECTORY)/software/include/basec++ -fexceptions -fno-rtti -ffreestanding diff --git a/litex/soc/software/include/net/microudp.h b/litex/soc/software/include/net/microudp.h deleted file mode 100644 index f148a341..00000000 --- a/litex/soc/software/include/net/microudp.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __MICROUDP_H -#define __MICROUDP_H - -#define IPTOINT(a, b, c, d) ((a << 24)|(b << 16)|(c << 8)|d) - -#define MICROUDP_BUFSIZE (5*1532) - -typedef void (*udp_callback)(unsigned int src_ip, unsigned short src_port, unsigned short dst_port, void *data, unsigned int length); - -void microudp_start(const unsigned char *macaddr, unsigned int ip); -int microudp_arp_resolve(unsigned int ip); -void *microudp_get_tx_buffer(void); -int microudp_send(unsigned short src_port, unsigned short dst_port, unsigned int length); -void microudp_set_callback(udp_callback callback); -void microudp_service(void); - -void eth_init(void); -void eth_mode(void); - -#endif /* __MICROUDP_H */ diff --git a/litex/soc/software/libnet/Makefile b/litex/soc/software/libliteeth/Makefile similarity index 57% rename from litex/soc/software/libnet/Makefile rename to litex/soc/software/libliteeth/Makefile index 188e48d6..593acc20 100644 --- a/litex/soc/software/libnet/Makefile +++ b/litex/soc/software/libliteeth/Makefile @@ -1,17 +1,17 @@ include ../include/generated/variables.mak include $(SOC_DIRECTORY)/software/common.mak -OBJECTS=microudp.o tftp.o +OBJECTS=udp.o tftp.o -all: libnet.a +all: libliteeth.a -libnet.a: $(OBJECTS) - $(AR) crs libnet.a $(OBJECTS) +libliteeth.a: $(OBJECTS) + $(AR) crs libliteeth.a $(OBJECTS) # pull in dependency info for *existing* .o files -include $(OBJECTS:.o=.d) -%.o: $(LIBNET_DIRECTORY)/%.c +%.o: $(LIBLITEETH_DIRECTORY)/%.c $(compile) %.o: %.S @@ -20,4 +20,4 @@ libnet.a: $(OBJECTS) .PHONY: all clean clean: - $(RM) $(OBJECTS) libnet.a .*~ *~ + $(RM) $(OBJECTS) libliteeth.a .*~ *~ diff --git a/litex/soc/software/libnet/tftp.c b/litex/soc/software/libliteeth/tftp.c similarity index 83% rename from litex/soc/software/libnet/tftp.c rename to litex/soc/software/libliteeth/tftp.c index 439b3e07..c5ac5f38 100644 --- a/litex/soc/software/libnet/tftp.c +++ b/litex/soc/software/libliteeth/tftp.c @@ -10,8 +10,8 @@ #include #include -#include -#include +#include "udp.h" +#include "tftp.h" /* Local TFTP client port (arbitrary) */ #define PORT_IN 7642 @@ -99,9 +99,9 @@ static void rx_callback(uint32_t src_ip, uint16_t src_port, if(length < BLOCK_SIZE) transfer_finished = 1; - packet_data = microudp_get_tx_buffer(); + packet_data = udp_get_tx_buffer(); length = format_ack(packet_data, block); - microudp_send(PORT_IN, src_port, length); + udp_send(PORT_IN, src_port, length); } if(opcode == TFTP_ERROR) { /* Error */ total_length = -1; @@ -118,10 +118,10 @@ int tftp_get(uint32_t ip, uint16_t server_port, const char *filename, int length_before; int spin = 0; - if(!microudp_arp_resolve(ip)) + if(!udp_arp_resolve(ip)) return -1; - microudp_set_callback(rx_callback); + udp_set_callback(rx_callback); dst_buffer = buffer; @@ -129,17 +129,17 @@ int tftp_get(uint32_t ip, uint16_t server_port, const char *filename, transfer_finished = 0; tries = 5; while(1) { - packet_data = microudp_get_tx_buffer(); + packet_data = udp_get_tx_buffer(); len = format_request(packet_data, TFTP_RRQ, filename); - microudp_send(PORT_IN, server_port, len); + udp_send(PORT_IN, server_port, len); for(i=0;i<2000000;i++) { - microudp_service(); + udp_service(); if((total_length > 0) || transfer_finished) break; } if((total_length > 0) || transfer_finished) break; tries--; if(tries == 0) { - microudp_set_callback(NULL); + udp_set_callback(NULL); return -1; } } @@ -156,13 +156,13 @@ int tftp_get(uint32_t ip, uint16_t server_port, const char *filename, } } if(i-- == 0) { - microudp_set_callback(NULL); + udp_set_callback(NULL); return -1; } - microudp_service(); + udp_service(); } - microudp_set_callback(NULL); + udp_set_callback(NULL); return total_length; } @@ -175,23 +175,23 @@ int tftp_put(uint32_t ip, uint16_t server_port, const char *filename, int i; int block = 0, sent = 0; - if(!microudp_arp_resolve(ip)) + if(!udp_arp_resolve(ip)) return -1; - microudp_set_callback(rx_callback); + udp_set_callback(rx_callback); - packet_data = microudp_get_tx_buffer(); + packet_data = udp_get_tx_buffer(); total_length = 0; transfer_finished = 0; tries = 5; while(1) { - packet_data = microudp_get_tx_buffer(); + packet_data = udp_get_tx_buffer(); len = format_request(packet_data, TFTP_WRQ, filename); - microudp_send(PORT_IN, server_port, len); + udp_send(PORT_IN, server_port, len); for(i=0;i<2000000;i++) { last_ack = -1; - microudp_service(); + udp_service(); if(last_ack == block) goto send_data; if(transfer_finished) @@ -208,11 +208,11 @@ send_data: send = sent+BLOCK_SIZE > size ? size-sent : BLOCK_SIZE; tries = 5; while(1) { - packet_data = microudp_get_tx_buffer(); + packet_data = udp_get_tx_buffer(); len = format_data(packet_data, block, buffer, send); - microudp_send(PORT_IN, data_port, len); + udp_send(PORT_IN, data_port, len); for(i=0;i<12000000;i++) { - microudp_service(); + udp_service(); if(transfer_finished) goto fail; if(last_ack == block) @@ -226,11 +226,11 @@ next: buffer += send; } while (send == BLOCK_SIZE); - microudp_set_callback(NULL); + udp_set_callback(NULL); return sent; fail: - microudp_set_callback(NULL); + udp_set_callback(NULL); return -1; } diff --git a/litex/soc/software/include/net/tftp.h b/litex/soc/software/libliteeth/tftp.h similarity index 100% rename from litex/soc/software/include/net/tftp.h rename to litex/soc/software/libliteeth/tftp.h diff --git a/litex/soc/software/libnet/microudp.c b/litex/soc/software/libliteeth/udp.c similarity index 96% rename from litex/soc/software/libnet/microudp.c rename to litex/soc/software/libliteeth/udp.c index 3199456e..d8696213 100644 --- a/litex/soc/software/libnet/microudp.c +++ b/litex/soc/software/libliteeth/udp.c @@ -16,10 +16,10 @@ #include #include -#include +#include "udp.h" -//#define DEBUG_MICROUDP_TX -//#define DEBUG_MICROUDP_RX +//#define DEBUG_UDP_TX +//#define DEBUG_UDP_RX #define ETHERTYPE_ARP 0x0806 #define ETHERTYPE_IP 0x0800 @@ -145,7 +145,7 @@ static void send_packet(void) txlen += 4; #endif -#ifdef DEBUG_MICROUDP_TX +#ifdef DEBUG_LITEETH_UDP_TX int j; printf(">>>> txlen : %d\n", txlen); for(j=0;jframe.contents.udp.payload; } @@ -301,7 +301,7 @@ struct pseudo_header { unsigned short length; } __attribute__((packed)); -int microudp_send(unsigned short src_port, unsigned short dst_port, unsigned int length) +int udp_send(unsigned short src_port, unsigned short dst_port, unsigned int length) { struct pseudo_header h; unsigned int r; @@ -373,7 +373,7 @@ static void process_ip(void) udp_ip->payload, ntohs(udp_ip->udp.length)-sizeof(struct udp_header)); } -void microudp_set_callback(udp_callback callback) +void udp_set_callback(udp_callback callback) { rx_callback = callback; } @@ -382,7 +382,7 @@ static void process_frame(void) { flush_cpu_dcache(); -#ifdef DEBUG_MICROUDP_RX +#ifdef DEBUG_LITEETH_UDP_RX int j; printf("<<< rxlen : %d\n", rxlen); for(j=0;jframe.eth_header.ethertype) == ETHERTYPE_IP) process_ip(); } -void microudp_start(const unsigned char *macaddr, unsigned int ip) +void udp_start(const unsigned char *macaddr, unsigned int ip) { int i; ethmac_sram_reader_ev_pending_write(ETHMAC_EV_SRAM_READER); @@ -437,7 +437,7 @@ void microudp_start(const unsigned char *macaddr, unsigned int ip) rx_callback = (udp_callback)0; } -void microudp_service(void) +void udp_service(void) { if(ethmac_sram_writer_ev_pending_read() & ETHMAC_EV_SRAM_WRITER) { rxslot = ethmac_sram_writer_slot_read(); diff --git a/litex/soc/software/libliteeth/udp.h b/litex/soc/software/libliteeth/udp.h new file mode 100644 index 00000000..132ef76d --- /dev/null +++ b/litex/soc/software/libliteeth/udp.h @@ -0,0 +1,20 @@ +#ifndef __UDP_H +#define __UDP_H + +#define IPTOINT(a, b, c, d) ((a << 24)|(b << 16)|(c << 8)|d) + +#define UDP_BUFSIZE (5*1532) + +typedef void (*udp_callback)(unsigned int src_ip, unsigned short src_port, unsigned short dst_port, void *data, unsigned int length); + +void udp_start(const unsigned char *macaddr, unsigned int ip); +int udp_arp_resolve(unsigned int ip); +void *udp_get_tx_buffer(void); +int udp_send(unsigned short src_port, unsigned short dst_port, unsigned int length); +void udp_set_callback(udp_callback callback); +void udp_service(void); + +void eth_init(void); +void eth_mode(void); + +#endif /* __UDP_H */ -- 2.30.2