Commit fb8977c5be93f8e967df224fe0a44721d60e34dc

Authored by Joe Hershberger
1 parent b38c3a641f

net: Always build the string_to_enetaddr() helper

Part of the env cleanup moved this out of the environment code and into
the net code. However, this helper is sometimes needed even when the net
stack isn't included.

Move the helper to lib/net_utils.c like it's similarly-purposed
string_to_ip(). Also rename the moved function to similar naming.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reported-by: Ondrej Jirman <megous@megous.com>

Showing 12 changed files with 39 additions and 37 deletions Side-by-side Diff

arch/arm/mach-tegra/cboot.c
... ... @@ -495,7 +495,7 @@
495 495 return -ENOENT;
496 496 }
497 497  
498   - eth_parse_enetaddr(prop, mac);
  498 + string_to_enetaddr(prop, mac);
499 499  
500 500 if (!is_valid_ethaddr(mac)) {
501 501 printf("Invalid MAC address: %s\n", prop);
board/renesas/sh7752evb/sh7752evb.c
... ... @@ -94,7 +94,7 @@
94 94 unsigned char mac[6];
95 95 unsigned long val;
96 96  
97   - eth_parse_enetaddr(mac_string, mac);
  97 + string_to_enetaddr(mac_string, mac);
98 98  
99 99 if (!channel)
100 100 ether = GETHER0_MAC_BASE;
board/renesas/sh7753evb/sh7753evb.c
... ... @@ -101,7 +101,7 @@
101 101 unsigned char mac[6];
102 102 unsigned long val;
103 103  
104   - eth_parse_enetaddr(mac_string, mac);
  104 + string_to_enetaddr(mac_string, mac);
105 105  
106 106 if (!channel)
107 107 ether = GETHER0_MAC_BASE;
board/renesas/sh7757lcr/sh7757lcr.c
... ... @@ -141,7 +141,7 @@
141 141 unsigned char mac[6];
142 142 unsigned long val;
143 143  
144   - eth_parse_enetaddr(mac_string, mac);
  144 + string_to_enetaddr(mac_string, mac);
145 145  
146 146 if (!channel)
147 147 ether = ETHER0_MAC_BASE;
... ... @@ -160,7 +160,7 @@
160 160 unsigned char mac[6];
161 161 unsigned long val;
162 162  
163   - eth_parse_enetaddr(mac_string, mac);
  163 + string_to_enetaddr(mac_string, mac);
164 164  
165 165 if (!channel)
166 166 ether = GETHER0_MAC_BASE;
... ... @@ -864,7 +864,7 @@
864 864 return 0;
865 865 }
866 866  
867   - eth_parse_enetaddr(argv[*argc_nr + 1], parsed_cmd->ethaddr);
  867 + string_to_enetaddr(argv[*argc_nr + 1], parsed_cmd->ethaddr);
868 868  
869 869 if (is_broadcast_ethaddr(parsed_cmd->ethaddr)) {
870 870 memset(parsed_cmd->ethaddr, 0xFF, sizeof(parsed_cmd->ethaddr));
... ... @@ -361,7 +361,7 @@
361 361  
362 362 int eth_env_get_enetaddr(const char *name, uint8_t *enetaddr)
363 363 {
364   - eth_parse_enetaddr(env_get(name), enetaddr);
  364 + string_to_enetaddr(env_get(name), enetaddr);
365 365 return is_valid_ethaddr(enetaddr);
366 366 }
367 367  
... ... @@ -76,12 +76,12 @@
76 76 should use these rather than attempt to do any kind of parsing/manipulation
77 77 yourself as many common errors have arisen in the past.
78 78  
79   - * void eth_parse_enetaddr(const char *addr, uchar *enetaddr);
  79 + * void string_to_enetaddr(const char *addr, uchar *enetaddr);
80 80  
81 81 Convert a string representation of a MAC address to the binary version.
82 82 char *addr = "00:11:22:33:44:55";
83 83 uchar enetaddr[6];
84   -eth_parse_enetaddr(addr, enetaddr);
  84 +string_to_enetaddr(addr, enetaddr);
85 85 /* enetaddr now equals { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 } */
86 86  
87 87 * int eth_env_get_enetaddr(char *name, uchar *enetaddr);
... ... @@ -826,6 +826,19 @@
826 826 addr[0] |= 0x02; /* set local assignment bit (IEEE802) */
827 827 }
828 828  
  829 +/**
  830 + * string_to_enetaddr() - Parse a MAC address
  831 + *
  832 + * Convert a string MAC address
  833 + *
  834 + * Implemented in lib/net_utils.c (built unconditionally)
  835 + *
  836 + * @addr: MAC address in aa:bb:cc:dd:ee:ff format, where each part is a 2-digit
  837 + * hex value
  838 + * @enetaddr: Place to put MAC address (6 bytes)
  839 + */
  840 +void string_to_enetaddr(const char *addr, uint8_t *enetaddr);
  841 +
829 842 /* Convert an IP address to a string */
830 843 void ip_to_string(struct in_addr x, char *s);
831 844  
832 845  
... ... @@ -880,20 +893,7 @@
880 893 */
881 894 int update_tftp(ulong addr, char *interface, char *devstring);
882 895  
883   -/**********************************************************************/
884   -
885 896 /**
886   - * eth_parse_enetaddr() - Parse a MAC address
887   - *
888   - * Convert a string MAC address
889   - *
890   - * @addr: MAC address in aa:bb:cc:dd:ee:ff format, where each part is a 2-digit
891   - * hex value
892   - * @enetaddr: Place to put MAC address (6 bytes)
893   - */
894   -void eth_parse_enetaddr(const char *addr, uint8_t *enetaddr);
895   -
896   -/**
897 897 * env_get_ip() - Convert an environment value to to an ip address
898 898 *
899 899 * @var: Environment variable to convert. The value of this variable must be
... ... @@ -905,6 +905,5 @@
905 905 {
906 906 return string_to_ip(env_get(var));
907 907 }
908   -
909 908 #endif /* __NET_H__ */
... ... @@ -41,4 +41,19 @@
41 41 addr.s_addr = htonl(addr.s_addr);
42 42 return addr;
43 43 }
  44 +
  45 +void string_to_enetaddr(const char *addr, uint8_t *enetaddr)
  46 +{
  47 + char *end;
  48 + int i;
  49 +
  50 + if (!enetaddr)
  51 + return;
  52 +
  53 + for (i = 0; i < 6; ++i) {
  54 + enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0;
  55 + if (addr)
  56 + addr = (*end) ? end + 1 : end;
  57 + }
  58 +}
... ... @@ -227,7 +227,7 @@
227 227 switch (op) {
228 228 case env_op_create:
229 229 case env_op_overwrite:
230   - eth_parse_enetaddr(value, pdata->enetaddr);
  230 + string_to_enetaddr(value, pdata->enetaddr);
231 231 eth_write_hwaddr(dev);
232 232 break;
233 233 case env_op_delete:
... ... @@ -117,7 +117,7 @@
117 117 switch (op) {
118 118 case env_op_create:
119 119 case env_op_overwrite:
120   - eth_parse_enetaddr(value, dev->enetaddr);
  120 + string_to_enetaddr(value, dev->enetaddr);
121 121 eth_write_hwaddr(dev, "eth", dev->index);
122 122 break;
123 123 case env_op_delete:
... ... @@ -1625,16 +1625,4 @@
1625 1625 {
1626 1626 return string_to_vlan(env_get(var));
1627 1627 }
1628   -
1629   -void eth_parse_enetaddr(const char *addr, uint8_t *enetaddr)
1630   -{
1631   - char *end;
1632   - int i;
1633   -
1634   - for (i = 0; i < 6; ++i) {
1635   - enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0;
1636   - if (addr)
1637   - addr = (*end) ? end + 1 : end;
1638   - }
1639   -}