diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/Kconfig | 32 | ||||
-rw-r--r-- | cmd/fastboot.c | 25 | ||||
-rw-r--r-- | cmd/net.c | 46 | ||||
-rw-r--r-- | cmd/pxe.c | 85 | ||||
-rw-r--r-- | cmd/sysboot.c | 2 | ||||
-rw-r--r-- | cmd/tlv_eeprom.c | 107 |
6 files changed, 232 insertions, 65 deletions
diff --git a/cmd/Kconfig b/cmd/Kconfig index e45b8847aef..65957da7f57 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1673,6 +1673,15 @@ config CMD_DHCP help Boot image via network using DHCP/TFTP protocol +config CMD_DHCP6 + bool "dhcp6" + depends on IPV6 + help + Boot image via network using DHCPv6/TFTP protocol using IPv6. + + Will perform 4-message exchange with DHCPv6 server, requesting + the minimum required options to TFTP boot. Complies with RFC 8415. + config BOOTP_MAY_FAIL bool "Allow for the BOOTP/DHCP server to not be found" depends on CMD_BOOTP @@ -1786,6 +1795,23 @@ config BOOTP_VCI_STRING default "U-Boot.arm" if ARM default "U-Boot" +if CMD_DHCP6 + +config DHCP6_PXE_CLIENTARCH + hex + default 0x16 if ARM64 + default 0x15 if ARM + default 0xFF + +config DHCP6_PXE_DHCP_OPTION + bool "Request & store 'pxe_configfile' from DHCP6 server" + +config DHCP6_ENTERPRISE_ID + int "Enterprise ID to send in DHCPv6 Vendor Class Option" + default 0 + +endif + config CMD_TFTPBOOT bool "tftpboot" default y @@ -1916,6 +1942,12 @@ config CMD_NCSI Normally this happens automatically before other network operations. +config IPV6_ROUTER_DISCOVERY + bool "Do IPv6 router discovery" + depends on IPV6 + help + Will automatically perform router solicitation on first IPv6 + network operation endif config CMD_ETHSW diff --git a/cmd/fastboot.c b/cmd/fastboot.c index 97dc02ce748..3d5ff951eb6 100644 --- a/cmd/fastboot.c +++ b/cmd/fastboot.c @@ -26,7 +26,7 @@ static int do_fastboot_udp(int argc, char *const argv[], return CMD_RET_FAILURE; } - err = net_loop(FASTBOOT); + err = net_loop(FASTBOOT_UDP); if (err < 0) { printf("fastboot udp error: %d\n", err); @@ -36,6 +36,26 @@ static int do_fastboot_udp(int argc, char *const argv[], return CMD_RET_SUCCESS; } +static int do_fastboot_tcp(int argc, char *const argv[], + uintptr_t buf_addr, size_t buf_size) +{ + int err; + + if (!IS_ENABLED(CONFIG_TCP_FUNCTION_FASTBOOT)) { + pr_err("Fastboot TCP not enabled\n"); + return CMD_RET_FAILURE; + } + + err = net_loop(FASTBOOT_TCP); + + if (err < 0) { + printf("fastboot tcp error: %d\n", err); + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; +} + static int do_fastboot_usb(int argc, char *const argv[], uintptr_t buf_addr, size_t buf_size) { @@ -141,7 +161,8 @@ NXTARG: if (!strcmp(argv[1], "udp")) return do_fastboot_udp(argc, argv, buf_addr, buf_size); - + if (!strcmp(argv[1], "tcp")) + return do_fastboot_tcp(argc, argv, buf_addr, buf_size); if (!strcmp(argv[1], "usb")) { argv++; argc--; diff --git a/cmd/net.c b/cmd/net.c index d5e20843dda..68d406291ef 100644 --- a/cmd/net.c +++ b/cmd/net.c @@ -111,6 +111,29 @@ U_BOOT_CMD( ); #endif +#if defined(CONFIG_CMD_DHCP6) +static int do_dhcp6(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + int i; + int dhcp_argc; + char *dhcp_argv[] = {NULL, NULL, NULL, NULL}; + + /* Add -ipv6 flag for autoload */ + for (i = 0; i < argc; i++) + dhcp_argv[i] = argv[i]; + dhcp_argc = argc + 1; + dhcp_argv[dhcp_argc - 1] = USE_IP6_CMD_PARAM; + + return netboot_common(DHCP6, cmdtp, dhcp_argc, dhcp_argv); +} + +U_BOOT_CMD(dhcp6, 3, 1, do_dhcp6, + "boot image via network using DHCPv6/TFTP protocol.\n" + "Use IPv6 hostIPaddr framed with [] brackets", + "[loadAddress] [[hostIPaddr:]bootfilename]"); +#endif + #if defined(CONFIG_CMD_DHCP) static int do_dhcp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) @@ -186,7 +209,7 @@ U_BOOT_CMD( static void netboot_update_env(void) { - char tmp[22]; + char tmp[44]; if (net_gateway.s_addr) { ip_to_string(net_gateway, tmp); @@ -247,6 +270,27 @@ static void netboot_update_env(void) env_set("ntpserverip", tmp); } #endif + + if (IS_ENABLED(CONFIG_IPV6)) { + if (!ip6_is_unspecified_addr(&net_ip6) || + net_prefix_length != 0) { + sprintf(tmp, "%pI6c", &net_ip6); + if (net_prefix_length != 0) + sprintf(tmp, "%s/%d", tmp, net_prefix_length); + + env_set("ip6addr", tmp); + } + + if (!ip6_is_unspecified_addr(&net_server_ip6)) { + sprintf(tmp, "%pI6c", &net_server_ip6); + env_set("serverip6", tmp); + } + + if (!ip6_is_unspecified_addr(&net_gateway6)) { + sprintf(tmp, "%pI6c", &net_gateway6); + env_set("gatewayip6", tmp); + } + } } /** diff --git a/cmd/pxe.c b/cmd/pxe.c index db8e4697f24..677142520bb 100644 --- a/cmd/pxe.c +++ b/cmd/pxe.c @@ -8,6 +8,8 @@ #include <command.h> #include <fs.h> #include <net.h> +#include <net6.h> +#include <malloc.h> #include "pxe_utils.h" @@ -29,12 +31,20 @@ static int do_get_tftp(struct pxe_context *ctx, const char *file_path, { char *tftp_argv[] = {"tftp", NULL, NULL, NULL}; int ret; + int num_args; tftp_argv[1] = file_addr; tftp_argv[2] = (void *)file_path; + if (ctx->use_ipv6) { + tftp_argv[3] = USE_IP6_CMD_PARAM; + num_args = 4; + } else { + num_args = 3; + } - if (do_tftpb(ctx->cmdtp, 0, 3, tftp_argv)) + if (do_tftpb(ctx->cmdtp, 0, num_args, tftp_argv)) return -ENOENT; + ret = pxe_get_file_size(sizep); if (ret) return log_msg_ret("tftp", ret); @@ -44,6 +54,22 @@ static int do_get_tftp(struct pxe_context *ctx, const char *file_path, } /* + * Looks for a pxe file with specified config file name, + * which is received from DHCPv4 option 209 or + * DHCPv6 option 60. + * + * Returns 1 on success or < 0 on error. + */ +static int pxe_dhcp_option_path(struct pxe_context *ctx, unsigned long pxefile_addr_r) +{ + int ret = get_pxe_file(ctx, pxelinux_configfile, pxefile_addr_r); + + free(pxelinux_configfile); + + return ret; +} + +/* * Looks for a pxe file with a name based on the pxeuuid environment variable. * * Returns 1 on success or < 0 on error. @@ -105,15 +131,24 @@ static int pxe_ipaddr_paths(struct pxe_context *ctx, unsigned long pxefile_addr_ return -ENOENT; } -int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong *sizep) +int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong *sizep, bool use_ipv6) { struct cmd_tbl cmdtp[] = {}; /* dummy */ struct pxe_context ctx; int i; if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false, - env_get("bootfile"))) + env_get("bootfile"), use_ipv6)) return -ENOMEM; + + if (IS_ENABLED(CONFIG_DHCP6_PXE_DHCP_OPTION) && + pxelinux_configfile && use_ipv6) { + if (pxe_dhcp_option_path(&ctx, pxefile_addr_r) > 0) + goto done; + + goto error_exit; + } + /* * Keep trying paths until we successfully get a file we're looking * for. @@ -131,6 +166,7 @@ int pxe_get(ulong pxefile_addr_r, char **bootdirp, ulong *sizep) i++; } +error_exit: pxe_destroy_ctx(&ctx); return -ENOENT; @@ -169,9 +205,18 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) char *fname; ulong size; int ret; + bool use_ipv6 = false; - if (argc != 1) - return CMD_RET_USAGE; + if (IS_ENABLED(CONFIG_IPV6)) { + if (!strcmp(argv[argc - 1], USE_IP6_CMD_PARAM)) + use_ipv6 = true; + + if (!(argc == 1 || (argc == 2 && use_ipv6))) + return CMD_RET_USAGE; + } else { + if (argc != 1) + return CMD_RET_USAGE; + } pxefile_addr_str = from_env("pxefile_addr_r"); @@ -183,7 +228,7 @@ do_pxe_get(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (ret < 0) return 1; - ret = pxe_get(pxefile_addr_r, &fname, &size); + ret = pxe_get(pxefile_addr_r, &fname, &size, use_ipv6); switch (ret) { case 0: printf("Config file '%s' found\n", fname); @@ -211,13 +256,19 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) char *pxefile_addr_str; struct pxe_context ctx; int ret; + bool use_ipv6 = false; + + if (IS_ENABLED(CONFIG_IPV6)) { + if (!strcmp(argv[argc - 1], USE_IP6_CMD_PARAM)) + use_ipv6 = true; + } - if (argc == 1) { + if (argc == 1 || (argc == 2 && use_ipv6)) { pxefile_addr_str = from_env("pxefile_addr_r"); if (!pxefile_addr_str) return 1; - } else if (argc == 2) { + } else if (argc == 2 || (argc == 3 && use_ipv6)) { pxefile_addr_str = argv[1]; } else { return CMD_RET_USAGE; @@ -229,7 +280,7 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } if (pxe_setup_ctx(&ctx, cmdtp, do_get_tftp, NULL, false, - env_get("bootfile"))) { + env_get("bootfile"), use_ipv6)) { printf("Out of memory\n"); return CMD_RET_FAILURE; } @@ -244,8 +295,8 @@ do_pxe_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) } static struct cmd_tbl cmd_pxe_sub[] = { - U_BOOT_CMD_MKENT(get, 1, 1, do_pxe_get, "", ""), - U_BOOT_CMD_MKENT(boot, 2, 1, do_pxe_boot, "", "") + U_BOOT_CMD_MKENT(get, 2, 1, do_pxe_get, "", ""), + U_BOOT_CMD_MKENT(boot, 3, 1, do_pxe_boot, "", "") }; static void __maybe_unused pxe_reloc(void) @@ -281,9 +332,11 @@ static int do_pxe(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return CMD_RET_USAGE; } -U_BOOT_CMD(pxe, 3, 1, do_pxe, - "commands to get and boot from pxe files", - "get - try to retrieve a pxe file using tftp\n" - "pxe boot [pxefile_addr_r] - boot from the pxe file at pxefile_addr_r\n" +U_BOOT_CMD(pxe, 4, 1, do_pxe, + "commands to get and boot from pxe files\n" + "To use IPv6 add -ipv6 parameter", + "get [" USE_IP6_CMD_PARAM "] - try to retrieve a pxe file using tftp\n" + "pxe boot [pxefile_addr_r] [-ipv6] - boot from the pxe file at pxefile_addr_r\n" ); -#endif + +#endif /* CONFIG_CMD_NET */ diff --git a/cmd/sysboot.c b/cmd/sysboot.c index 04c07020269..63a7806debe 100644 --- a/cmd/sysboot.c +++ b/cmd/sysboot.c @@ -101,7 +101,7 @@ static int do_sysboot(struct cmd_tbl *cmdtp, int flag, int argc, } if (pxe_setup_ctx(&ctx, cmdtp, sysboot_read_file, &info, true, - filename)) { + filename, false)) { printf("Out of memory\n"); return CMD_RET_FAILURE; } diff --git a/cmd/tlv_eeprom.c b/cmd/tlv_eeprom.c index 4591ff336bb..79796394c5c 100644 --- a/cmd/tlv_eeprom.c +++ b/cmd/tlv_eeprom.c @@ -29,26 +29,23 @@ DECLARE_GLOBAL_DATA_PTR; /* File scope function prototypes */ static bool is_checksum_valid(u8 *eeprom); -static int read_eeprom(u8 *eeprom); -static void show_eeprom(u8 *eeprom); +static int read_eeprom(int devnum, u8 *eeprom); +static void show_eeprom(int devnum, u8 *eeprom); static void decode_tlv(struct tlvinfo_tlv *tlv); static void update_crc(u8 *eeprom); -static int prog_eeprom(u8 *eeprom); +static int prog_eeprom(int devnum, u8 *eeprom); static bool tlvinfo_find_tlv(u8 *eeprom, u8 tcode, int *eeprom_index); static bool tlvinfo_delete_tlv(u8 *eeprom, u8 code); static bool tlvinfo_add_tlv(u8 *eeprom, int tcode, char *strval); static int set_mac(char *buf, const char *string); static int set_date(char *buf, const char *string); static int set_bytes(char *buf, const char *string, int *converted_accum); -static void show_tlv_devices(void); +static void show_tlv_devices(int current_dev); -/* Set to 1 if we've read EEPROM into memory */ -static int has_been_read; /* The EERPOM contents after being read into memory */ static u8 eeprom[TLV_INFO_MAX_LEN]; static struct udevice *tlv_devices[MAX_TLV_DEVICES]; -static unsigned int current_dev; #define to_header(p) ((struct tlvinfo_header *)p) #define to_entry(p) ((struct tlvinfo_tlv *)p) @@ -125,22 +122,20 @@ static bool is_checksum_valid(u8 *eeprom) * * Read the EEPROM into memory, if it hasn't already been read. */ -static int read_eeprom(u8 *eeprom) +static int read_eeprom(int devnum, u8 *eeprom) { int ret; struct tlvinfo_header *eeprom_hdr = to_header(eeprom); struct tlvinfo_tlv *eeprom_tlv = to_entry(&eeprom[HDR_SIZE]); - if (has_been_read) - return 0; - /* Read the header */ - ret = read_tlv_eeprom((void *)eeprom_hdr, 0, HDR_SIZE, current_dev); + ret = read_tlv_eeprom((void *)eeprom_hdr, 0, HDR_SIZE, devnum); /* If the header was successfully read, read the TLVs */ if (ret == 0 && is_valid_tlvinfo_header(eeprom_hdr)) ret = read_tlv_eeprom((void *)eeprom_tlv, HDR_SIZE, - be16_to_cpu(eeprom_hdr->totallen), - current_dev); + be16_to_cpu(eeprom_hdr->totallen), devnum); + else if (ret == -ENODEV) + return ret; // If the contents are invalid, start over with default contents if (!is_valid_tlvinfo_header(eeprom_hdr) || @@ -151,10 +146,8 @@ static int read_eeprom(u8 *eeprom) update_crc(eeprom); } - has_been_read = 1; - #ifdef DEBUG - show_eeprom(eeprom); + show_eeprom(devnum, eeprom); #endif return ret; @@ -165,7 +158,7 @@ static int read_eeprom(u8 *eeprom) * * Display the contents of the EEPROM */ -static void show_eeprom(u8 *eeprom) +static void show_eeprom(int devnum, u8 *eeprom) { int tlv_end; int curr_tlv; @@ -180,7 +173,7 @@ static void show_eeprom(u8 *eeprom) return; } - printf("TLV: %u\n", current_dev); + printf("TLV: %u\n", devnum); printf("TlvInfo Header:\n"); printf(" Id String: %s\n", eeprom_hdr->signature); printf(" Version: %d\n", eeprom_hdr->version); @@ -389,7 +382,7 @@ static void update_crc(u8 *eeprom) * * Write the EEPROM data from CPU memory to the hardware. */ -static int prog_eeprom(u8 *eeprom) +static int prog_eeprom(int devnum, u8 *eeprom) { int ret = 0; struct tlvinfo_header *eeprom_hdr = to_header(eeprom); @@ -398,7 +391,7 @@ static int prog_eeprom(u8 *eeprom) update_crc(eeprom); eeprom_len = HDR_SIZE + be16_to_cpu(eeprom_hdr->totallen); - ret = write_tlv_eeprom(eeprom, eeprom_len); + ret = write_tlv_eeprom(eeprom, eeprom_len, devnum); if (ret) { printf("Programming failed.\n"); return -1; @@ -433,11 +426,23 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { char cmd; struct tlvinfo_header *eeprom_hdr = to_header(eeprom); + static unsigned int current_dev; + /* Set to 1 if we've read EEPROM into memory */ + static int has_been_read; + int ret; // If no arguments, read the EERPOM and display its contents if (argc == 1) { - read_eeprom(eeprom); - show_eeprom(eeprom); + if (!has_been_read) { + ret = read_eeprom(current_dev, eeprom); + if (ret) { + printf("Failed to read EEPROM data from device.\n"); + return 0; + } + + has_been_read = 1; + } + show_eeprom(current_dev, eeprom); return 0; } @@ -445,12 +450,33 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) // "reset" will both be treated as "read". cmd = argv[1][0]; + // select device + if (cmd == 'd') { + /* 'dev' command */ + unsigned int devnum; + + devnum = simple_strtoul(argv[2], NULL, 0); + if (devnum >= MAX_TLV_DEVICES) { + printf("Invalid device number\n"); + return 0; + } + current_dev = devnum; + has_been_read = 0; + + return 0; + } + // Read the EEPROM contents if (cmd == 'r') { has_been_read = 0; - if (!read_eeprom(eeprom)) - printf("EEPROM data loaded from device to memory.\n"); - return 0; + ret = read_eeprom(current_dev, eeprom); + if (ret) { + printf("Failed to read EEPROM data from device.\n"); + return 0; + } + + printf("EEPROM data loaded from device to memory.\n"); + has_been_read = 1; } // Subsequent commands require that the EEPROM has already been read. @@ -463,7 +489,7 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (argc == 2) { switch (cmd) { case 'w': /* write */ - prog_eeprom(eeprom); + prog_eeprom(current_dev, eeprom); break; case 'e': /* erase */ strcpy(eeprom_hdr->signature, TLV_INFO_ID_STRING); @@ -476,7 +502,7 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) show_tlv_code_list(); break; case 'd': /* dev */ - show_tlv_devices(); + show_tlv_devices(current_dev); break; default: return CMD_RET_USAGE; @@ -498,16 +524,6 @@ int do_tlv_eeprom(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) tlvinfo_delete_tlv(eeprom, tcode); if (argc == 4) tlvinfo_add_tlv(eeprom, tcode, argv[3]); - } else if (cmd == 'd') { /* 'dev' command */ - unsigned int devnum; - - devnum = simple_strtoul(argv[2], NULL, 0); - if (devnum > MAX_TLV_DEVICES || !tlv_devices[devnum]) { - printf("Invalid device number\n"); - return 0; - } - current_dev = devnum; - has_been_read = 0; } else { return CMD_RET_USAGE; } @@ -883,7 +899,7 @@ static int set_bytes(char *buf, const char *string, int *converted_accum) return 0; } -static void show_tlv_devices(void) +static void show_tlv_devices(int current_dev) { unsigned int dev; @@ -953,14 +969,14 @@ int read_tlv_eeprom(void *eeprom, int offset, int len, int dev_num) /** * write_tlv_eeprom - write the hwinfo to i2c EEPROM */ -int write_tlv_eeprom(void *eeprom, int len) +int write_tlv_eeprom(void *eeprom, int len, int dev) { if (!(gd->flags & GD_FLG_RELOC)) return -ENODEV; - if (!tlv_devices[current_dev]) + if (!tlv_devices[dev]) return -ENODEV; - return i2c_eeprom_write(tlv_devices[current_dev], 0, eeprom, len); + return i2c_eeprom_write(tlv_devices[dev], 0, eeprom, len); } int read_tlvinfo_tlv_eeprom(void *eeprom, struct tlvinfo_header **hdr, @@ -1015,10 +1031,11 @@ int mac_read_from_eeprom(void) int maccount; u8 macbase[6]; struct tlvinfo_header *eeprom_hdr = to_header(eeprom); + int devnum = 0; // TODO: support multiple EEPROMs puts("EEPROM: "); - if (read_eeprom(eeprom)) { + if (read_eeprom(devnum, eeprom)) { printf("Read failed.\n"); return -1; } @@ -1083,7 +1100,7 @@ int mac_read_from_eeprom(void) * * This function must be called after relocation. */ -int populate_serial_number(void) +int populate_serial_number(int devnum) { char serialstr[257]; int eeprom_index; @@ -1092,7 +1109,7 @@ int populate_serial_number(void) if (env_get("serial#")) return 0; - if (read_eeprom(eeprom)) { + if (read_eeprom(devnum, eeprom)) { printf("Read failed.\n"); return -1; } |