Merge pull request #52 from ewen-naos-nz/tftp-alt-port
BIOS: Support alternate TFTP server port
This commit is contained in:
commit
fcc22350fb
|
@ -1,6 +1,11 @@
|
||||||
include ../include/generated/variables.mak
|
include ../include/generated/variables.mak
|
||||||
include $(SOC_DIRECTORY)/software/common.mak
|
include $(SOC_DIRECTORY)/software/common.mak
|
||||||
|
|
||||||
|
# Permit TFTP_SERVER_PORT override from shell environment / command line
|
||||||
|
ifdef TFTP_SERVER_PORT
|
||||||
|
CFLAGS += -DTFTP_SERVER_PORT=$(TFTP_SERVER_PORT)
|
||||||
|
endif
|
||||||
|
|
||||||
OBJECTS=isr.o sdram.o main.o boot-helper-$(CPU).o boot.o
|
OBJECTS=isr.o sdram.o main.o boot-helper-$(CPU).o boot.o
|
||||||
|
|
||||||
all: bios.bin
|
all: bios.bin
|
||||||
|
|
|
@ -213,11 +213,17 @@ int serialboot(void)
|
||||||
#define REMOTEIP4 100
|
#define REMOTEIP4 100
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int tftp_get_v(unsigned int ip, const char *filename, char *buffer)
|
#define DEFAULT_TFTP_SERVER_PORT 69 /* IANA well known port: UDP/69 */
|
||||||
|
#ifndef TFTP_SERVER_PORT
|
||||||
|
#define TFTP_SERVER_PORT DEFAULT_TFTP_SERVER_PORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int tftp_get_v(unsigned int ip, unsigned short server_port,
|
||||||
|
const char *filename, char *buffer)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = tftp_get(ip, filename, buffer);
|
r = tftp_get(ip, server_port, filename, buffer);
|
||||||
if(r > 0)
|
if(r > 0)
|
||||||
printf("Successfully downloaded %d bytes from %s over TFTP\n", r, filename);
|
printf("Successfully downloaded %d bytes from %s over TFTP\n", r, filename);
|
||||||
else
|
else
|
||||||
|
@ -232,6 +238,7 @@ void netboot(void)
|
||||||
int size;
|
int size;
|
||||||
unsigned int cmdline_adr, initrdstart_adr, initrdend_adr;
|
unsigned int cmdline_adr, initrdstart_adr, initrdend_adr;
|
||||||
unsigned int ip;
|
unsigned int ip;
|
||||||
|
unsigned short tftp_port;
|
||||||
|
|
||||||
printf("Booting from network...\n");
|
printf("Booting from network...\n");
|
||||||
printf("Local IP : %d.%d.%d.%d\n", LOCALIP1, LOCALIP2, LOCALIP3, LOCALIP4);
|
printf("Local IP : %d.%d.%d.%d\n", LOCALIP1, LOCALIP2, LOCALIP3, LOCALIP4);
|
||||||
|
@ -241,13 +248,27 @@ void netboot(void)
|
||||||
|
|
||||||
microudp_start(macadr, IPTOINT(LOCALIP1, LOCALIP2, LOCALIP3, LOCALIP4));
|
microudp_start(macadr, IPTOINT(LOCALIP1, LOCALIP2, LOCALIP3, LOCALIP4));
|
||||||
|
|
||||||
if(tftp_get_v(ip, "boot.bin", (void *)MAIN_RAM_BASE) <= 0) {
|
tftp_port = TFTP_SERVER_PORT;
|
||||||
|
printf("Fetching from: UDP/%d\n", tftp_port);
|
||||||
|
|
||||||
|
size = tftp_get_v(ip, tftp_port, "boot.bin", (void *)MAIN_RAM_BASE);
|
||||||
|
|
||||||
|
if ((size <= 0) && (tftp_port != DEFAULT_TFTP_SERVER_PORT)) {
|
||||||
|
/* Try default TFTP port if timed out on non-standard port */
|
||||||
|
tftp_port = DEFAULT_TFTP_SERVER_PORT;
|
||||||
|
printf("Fetching from: UDP/%d\n", tftp_port);
|
||||||
|
|
||||||
|
size = tftp_get_v(ip, tftp_port, "boot.bin",
|
||||||
|
(void *)MAIN_RAM_BASE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size <= 0) {
|
||||||
printf("Network boot failed\n");
|
printf("Network boot failed\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdline_adr = MAIN_RAM_BASE+0x1000000;
|
cmdline_adr = MAIN_RAM_BASE+0x1000000;
|
||||||
size = tftp_get_v(ip, "cmdline.txt", (void *)cmdline_adr);
|
size = tftp_get_v(ip, tftp_port, "cmdline.txt", (void *)cmdline_adr);
|
||||||
if(size <= 0) {
|
if(size <= 0) {
|
||||||
printf("No command line parameters found\n");
|
printf("No command line parameters found\n");
|
||||||
cmdline_adr = 0;
|
cmdline_adr = 0;
|
||||||
|
@ -255,7 +276,7 @@ void netboot(void)
|
||||||
*((char *)(cmdline_adr+size)) = 0x00;
|
*((char *)(cmdline_adr+size)) = 0x00;
|
||||||
|
|
||||||
initrdstart_adr = MAIN_RAM_BASE+0x1002000;
|
initrdstart_adr = MAIN_RAM_BASE+0x1002000;
|
||||||
size = tftp_get_v(ip, "initrd.bin", (void *)initrdstart_adr);
|
size = tftp_get_v(ip, tftp_port, "initrd.bin", (void *)initrdstart_adr);
|
||||||
if(size <= 0) {
|
if(size <= 0) {
|
||||||
printf("No initial ramdisk found\n");
|
printf("No initial ramdisk found\n");
|
||||||
initrdstart_adr = 0;
|
initrdstart_adr = 0;
|
||||||
|
|
|
@ -3,8 +3,10 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
int tftp_get(uint32_t ip, const char *filename, void *buffer);
|
int tftp_get(uint32_t ip, uint16_t server_port, const char *filename,
|
||||||
int tftp_put(uint32_t ip, const char *filename, const void *buffer, int size);
|
void *buffer);
|
||||||
|
int tftp_put(uint32_t ip, uint16_t server_port, const char *filename,
|
||||||
|
const void *buffer, int size);
|
||||||
|
|
||||||
#endif /* __TFTP_H */
|
#endif /* __TFTP_H */
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <net/microudp.h>
|
#include <net/microudp.h>
|
||||||
#include <net/tftp.h>
|
#include <net/tftp.h>
|
||||||
|
|
||||||
#define PORT_OUT 69
|
/* Local TFTP client port (arbitrary) */
|
||||||
#define PORT_IN 7642
|
#define PORT_IN 7642
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -100,7 +100,8 @@ static void rx_callback(uint32_t src_ip, uint16_t src_port,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int tftp_get(uint32_t ip, const char *filename, void *buffer)
|
int tftp_get(uint32_t ip, uint16_t server_port, const char *filename,
|
||||||
|
void *buffer)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
int tries;
|
int tries;
|
||||||
|
@ -120,7 +121,7 @@ int tftp_get(uint32_t ip, const char *filename, void *buffer)
|
||||||
while(1) {
|
while(1) {
|
||||||
packet_data = microudp_get_tx_buffer();
|
packet_data = microudp_get_tx_buffer();
|
||||||
len = format_request(packet_data, TFTP_RRQ, filename);
|
len = format_request(packet_data, TFTP_RRQ, filename);
|
||||||
microudp_send(PORT_IN, PORT_OUT, len);
|
microudp_send(PORT_IN, server_port, len);
|
||||||
for(i=0;i<2000000;i++) {
|
for(i=0;i<2000000;i++) {
|
||||||
microudp_service();
|
microudp_service();
|
||||||
if((total_length > 0) || transfer_finished) break;
|
if((total_length > 0) || transfer_finished) break;
|
||||||
|
@ -152,7 +153,8 @@ int tftp_get(uint32_t ip, const char *filename, void *buffer)
|
||||||
return total_length;
|
return total_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tftp_put(uint32_t ip, const char *filename, const void *buffer, int size)
|
int tftp_put(uint32_t ip, uint16_t server_port, const char *filename,
|
||||||
|
const void *buffer, int size)
|
||||||
{
|
{
|
||||||
int len, send;
|
int len, send;
|
||||||
int tries;
|
int tries;
|
||||||
|
@ -172,7 +174,7 @@ int tftp_put(uint32_t ip, const char *filename, const void *buffer, int size)
|
||||||
while(1) {
|
while(1) {
|
||||||
packet_data = microudp_get_tx_buffer();
|
packet_data = microudp_get_tx_buffer();
|
||||||
len = format_request(packet_data, TFTP_WRQ, filename);
|
len = format_request(packet_data, TFTP_WRQ, filename);
|
||||||
microudp_send(PORT_IN, PORT_OUT, len);
|
microudp_send(PORT_IN, server_port, len);
|
||||||
for(i=0;i<2000000;i++) {
|
for(i=0;i<2000000;i++) {
|
||||||
last_ack = -1;
|
last_ack = -1;
|
||||||
microudp_service();
|
microudp_service();
|
||||||
|
|
Loading…
Reference in New Issue