bios: add bootp to netboot

This changes netboot to first try getting IPs and filename via BOOTP. If
`netboot` is run multiple times, the assigned values are cached.
To update this cache, a new command `bootp` has been added that will
always make a new request to the BOOTP server. After updating the cache,
`netboot` can be run again.

Signed-off-by: Matthias Breithaupt <m.breithaupt@vogl-electronic.com>
This commit is contained in:
Matthias Breithaupt 2024-09-12 09:10:18 +02:00
parent d9ac1e9d1b
commit 94a7cbf672
3 changed files with 62 additions and 9 deletions

View file

@ -21,6 +21,8 @@
#include "sfl.h"
#include "boot.h"
#include <bios/helpers.h>
#include <libbase/uart.h>
#include <libbase/console.h>
@ -29,6 +31,7 @@
#include <libbase/progress.h>
#include <libliteeth/udp.h>
#include <libliteeth/bootp.h>
#include <libliteeth/tftp.h>
#include <liblitesdcard/spisdcard.h>
@ -538,34 +541,82 @@ static void netboot_from_bin(const char * filename, unsigned int ip, unsigned sh
}
#endif
void bootp(void)
{
uint32_t client_ip;
uint32_t server_ip;
char bootp_filename[64];
int ret;
printf("Requesting ip...\n");
udp_start(macadr, IPTOINT(local_ip[0], local_ip[1], local_ip[2], local_ip[3]));
ret = bootp_get(macadr, &client_ip, &server_ip, (char *) &bootp_filename, sizeof(bootp_filename), 1);
if (ret == 0) {
printf("Local IP: ");
print_ip(client_ip);
printf("\n");
printf("Remote IP: ");
print_ip(server_ip);
printf("\n");
}
printf("BOOTP done.\n");
}
void netboot(int nb_params, char **params)
{
unsigned int ip;
char * filename = NULL;
char bootp_name[64];
uint8_t bootp_len;
uint8_t bootp_ret;
uint32_t client_ip;
uint32_t server_ip;
if (nb_params > 0 )
filename = params[0];
printf("Booting from network...\n");
printf("Local IP: %d.%d.%d.%d\n", local_ip[0], local_ip[1], local_ip[2], local_ip[3]);
printf("Remote IP: %d.%d.%d.%d\n", remote_ip[0], remote_ip[1], remote_ip[2], remote_ip[3]);
ip = IPTOINT(remote_ip[0], remote_ip[1], remote_ip[2], remote_ip[3]);
server_ip = IPTOINT(remote_ip[0], remote_ip[1], remote_ip[2], remote_ip[3]);
if(udp_get_ip() == 0)
udp_start(macadr, IPTOINT(local_ip[0], local_ip[1], local_ip[2], local_ip[3]));
if (filename) {
bootp_ret = bootp_get(macadr, &client_ip, &server_ip, (char *) &bootp_name, sizeof(bootp_name), 0);
bootp_len = strlen(bootp_name);
if(bootp_ret == 0)
printf("Received configuration via BOOTP.\n");
printf("Local IP: ");
print_ip(client_ip);
printf("\n");
printf("Remote IP: ");
print_ip(server_ip);
printf("\n");
if(bootp_ret == 0 && bootp_len > 0 && bootp_len < sizeof(bootp_name)) {
#ifdef MAIN_RAM_BASE
if(bootp_name[bootp_len - 4] == '.' && bootp_name[bootp_len - 3] == 'b' &&
bootp_name[bootp_len - 2] == 'i' && bootp_name[bootp_len - 1] == 'n'){
printf("Booting from %s...\n", bootp_name);
netboot_from_bin(bootp_name, server_ip, TFTP_SERVER_PORT);
} else {
#else
if(1){
#endif
printf("Booting from %s (JSON)...\n", bootp_name);
netboot_from_json(bootp_name, server_ip, TFTP_SERVER_PORT);
}
} else if (filename) {
printf("Booting from %s (JSON)...\n", filename);
netboot_from_json(filename, ip, TFTP_SERVER_PORT);
netboot_from_json(filename, server_ip, TFTP_SERVER_PORT);
} else {
/* Boot from boot.json */
printf("Booting from boot.json...\n");
netboot_from_json("boot.json", ip, TFTP_SERVER_PORT);
netboot_from_json("boot.json", server_ip, TFTP_SERVER_PORT);
#ifdef MAIN_RAM_BASE
/* Boot from boot.bin */
printf("Booting from boot.bin...\n");
netboot_from_bin("boot.bin", ip, TFTP_SERVER_PORT);
netboot_from_bin("boot.bin", server_ip, TFTP_SERVER_PORT);
#endif
}

View file

@ -8,6 +8,7 @@ void set_mac_addr(const char * mac_address);
void __attribute__((noreturn)) boot(unsigned long r1, unsigned long r2, unsigned long r3, unsigned long addr);
int serialboot(void);
void netboot(int nb_params, char **params);
void bootp(void);
void flashboot(void);
void romboot(void);
void sdcardboot(void);

View file

@ -114,6 +114,7 @@ define_command(serialboot, serialboot, "Boot from Serial (SFL)", BOOT_CMDS);
*/
#ifdef CSR_ETHMAC_BASE
define_command(netboot, netboot, "Boot via Ethernet (TFTP)", BOOT_CMDS);
define_command(bootp, bootp, "Request IP (BOOTP)", BOOT_CMDS);
#endif
/**