diff options
author | Joe Hershberger | 2018-07-03 19:36:43 -0500 |
---|---|---|
committer | Joe Hershberger | 2018-07-26 14:08:20 -0500 |
commit | 6ab12830921c1de4eb90a0d471bf5f4677af734c (patch) | |
tree | e843a02a84a0797ab7d0dbb7e4e4cc8d3cb0a3a9 /net | |
parent | f43308fa0c7834d9707a2c212591275d1e095e50 (diff) | |
download | u-boot-6ab12830921c1de4eb90a0d471bf5f4677af734c.tar.gz u-boot-6ab12830921c1de4eb90a0d471bf5f4677af734c.tar.xz u-boot-6ab12830921c1de4eb90a0d471bf5f4677af734c.zip |
net: Consolidate the parsing of bootfile
The same basic parsing was implemented in tftp and nfs, so add a helper
function to do the work once.
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/net.c | 20 | ||||
-rw-r--r-- | net/nfs.c | 15 | ||||
-rw-r--r-- | net/tftp.c | 13 |
3 files changed, 23 insertions, 25 deletions
@@ -1517,6 +1517,26 @@ int is_serverip_in_cmd(void) | |||
1517 | return !!strchr(net_boot_file_name, ':'); | 1517 | return !!strchr(net_boot_file_name, ':'); |
1518 | } | 1518 | } |
1519 | 1519 | ||
1520 | int net_parse_bootfile(struct in_addr *ipaddr, char *filename, int max_len) | ||
1521 | { | ||
1522 | char *colon; | ||
1523 | |||
1524 | if (net_boot_file_name[0] == '\0') | ||
1525 | return 0; | ||
1526 | |||
1527 | colon = strchr(net_boot_file_name, ':'); | ||
1528 | if (colon) { | ||
1529 | if (ipaddr) | ||
1530 | *ipaddr = string_to_ip(net_boot_file_name); | ||
1531 | strncpy(filename, colon + 1, max_len); | ||
1532 | } else { | ||
1533 | strncpy(filename, net_boot_file_name, max_len); | ||
1534 | } | ||
1535 | filename[max_len - 1] = '\0'; | ||
1536 | |||
1537 | return 1; | ||
1538 | } | ||
1539 | |||
1520 | #if defined(CONFIG_CMD_NFS) || \ | 1540 | #if defined(CONFIG_CMD_NFS) || \ |
1521 | defined(CONFIG_CMD_SNTP) || \ | 1541 | defined(CONFIG_CMD_SNTP) || \ |
1522 | defined(CONFIG_CMD_DNS) | 1542 | defined(CONFIG_CMD_DNS) |
@@ -859,7 +859,8 @@ void nfs_start(void) | |||
859 | return; | 859 | return; |
860 | } | 860 | } |
861 | 861 | ||
862 | if (net_boot_file_name[0] == '\0') { | 862 | if (!net_parse_bootfile(&nfs_server_ip, nfs_path, |
863 | sizeof(nfs_path_buff))) { | ||
863 | sprintf(nfs_path, "/nfsroot/%02X%02X%02X%02X.img", | 864 | sprintf(nfs_path, "/nfsroot/%02X%02X%02X%02X.img", |
864 | net_ip.s_addr & 0xFF, | 865 | net_ip.s_addr & 0xFF, |
865 | (net_ip.s_addr >> 8) & 0xFF, | 866 | (net_ip.s_addr >> 8) & 0xFF, |
@@ -868,18 +869,6 @@ void nfs_start(void) | |||
868 | 869 | ||
869 | printf("*** Warning: no boot file name; using '%s'\n", | 870 | printf("*** Warning: no boot file name; using '%s'\n", |
870 | nfs_path); | 871 | nfs_path); |
871 | } else { | ||
872 | char *p = net_boot_file_name; | ||
873 | |||
874 | p = strchr(p, ':'); | ||
875 | |||
876 | if (p != NULL) { | ||
877 | nfs_server_ip = string_to_ip(net_boot_file_name); | ||
878 | ++p; | ||
879 | strcpy(nfs_path, p); | ||
880 | } else { | ||
881 | strcpy(nfs_path, net_boot_file_name); | ||
882 | } | ||
883 | } | 872 | } |
884 | 873 | ||
885 | nfs_filename = basename(nfs_path); | 874 | nfs_filename = basename(nfs_path); |
diff --git a/net/tftp.c b/net/tftp.c index 6671b1f7ca..68ffd81414 100644 --- a/net/tftp.c +++ b/net/tftp.c | |||
@@ -735,7 +735,7 @@ void tftp_start(enum proto_t protocol) | |||
735 | tftp_block_size_option, timeout_ms); | 735 | tftp_block_size_option, timeout_ms); |
736 | 736 | ||
737 | tftp_remote_ip = net_server_ip; | 737 | tftp_remote_ip = net_server_ip; |
738 | if (net_boot_file_name[0] == '\0') { | 738 | if (!net_parse_bootfile(&tftp_remote_ip, tftp_filename, MAX_LEN)) { |
739 | sprintf(default_filename, "%02X%02X%02X%02X.img", | 739 | sprintf(default_filename, "%02X%02X%02X%02X.img", |
740 | net_ip.s_addr & 0xFF, | 740 | net_ip.s_addr & 0xFF, |
741 | (net_ip.s_addr >> 8) & 0xFF, | 741 | (net_ip.s_addr >> 8) & 0xFF, |
@@ -747,17 +747,6 @@ void tftp_start(enum proto_t protocol) | |||
747 | 747 | ||
748 | printf("*** Warning: no boot file name; using '%s'\n", | 748 | printf("*** Warning: no boot file name; using '%s'\n", |
749 | tftp_filename); | 749 | tftp_filename); |
750 | } else { | ||
751 | char *p = strchr(net_boot_file_name, ':'); | ||
752 | |||
753 | if (p == NULL) { | ||
754 | strncpy(tftp_filename, net_boot_file_name, MAX_LEN); | ||
755 | tftp_filename[MAX_LEN - 1] = 0; | ||
756 | } else { | ||
757 | tftp_remote_ip = string_to_ip(net_boot_file_name); | ||
758 | strncpy(tftp_filename, p + 1, MAX_LEN); | ||
759 | tftp_filename[MAX_LEN - 1] = 0; | ||
760 | } | ||
761 | } | 750 | } |
762 | 751 | ||
763 | printf("Using %s device\n", eth_get_name()); | 752 | printf("Using %s device\n", eth_get_name()); |