Commit fd3056337e6fcc140f400e11edd33f6f1cb37de1

Authored by Joe Hershberger
Committed by Tom Rini
1 parent 73c2bbeea3

net: Use env callbacks for net variables

Instead of checking for changes to the env each time we enter the
net_loop, use the env callbacks to update the values of the variables.
Don't update the variables when the source was programmatic, since the
variables were the source of the new value.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

Showing 2 changed files with 110 additions and 17 deletions Side-by-side Diff

include/env_callback.h
... ... @@ -37,6 +37,26 @@
37 37 #define ENV_DOT_ESCAPE
38 38 #endif
39 39  
  40 +#ifdef CONFIG_CMD_DNS
  41 +#define DNS_CALLBACK "dnsip:dnsip,"
  42 +#else
  43 +#define DNS_CALLBACK
  44 +#endif
  45 +
  46 +#ifdef CONFIG_NET
  47 +#define NET_CALLBACKS \
  48 + "bootfile:bootfile," \
  49 + "ipaddr:ipaddr," \
  50 + "gatewayip:gatewayip," \
  51 + "netmask:netmask," \
  52 + "serverip:serverip," \
  53 + "nvlan:nvlan," \
  54 + "vlan:vlan," \
  55 + DNS_CALLBACK
  56 +#else
  57 +#define NET_CALLBACKS
  58 +#endif
  59 +
40 60 /*
41 61 * This list of callback bindings is static, but may be overridden by defining
42 62 * a new association in the ".callbacks" environment variable.
... ... @@ -44,7 +64,7 @@
44 64 #define ENV_CALLBACK_LIST_STATIC ENV_DOT_ESCAPE ENV_CALLBACK_VAR ":callbacks," \
45 65 ENV_DOT_ESCAPE ENV_FLAGS_VAR ":flags," \
46 66 "baudrate:baudrate," \
47   - "bootfile:bootfile," \
  67 + NET_CALLBACKS \
48 68 "loadaddr:loadaddr," \
49 69 SILENT_CALLBACK \
50 70 SPLASHIMAGE_CALLBACK \
... ... @@ -208,6 +208,9 @@
208 208 static int on_bootfile(const char *name, const char *value, enum env_op op,
209 209 int flags)
210 210 {
  211 + if (flags & H_PROGRAMMATIC)
  212 + return 0;
  213 +
211 214 switch (op) {
212 215 case env_op_create:
213 216 case env_op_overwrite:
... ... @@ -222,6 +225,92 @@
222 225 }
223 226 U_BOOT_ENV_CALLBACK(bootfile, on_bootfile);
224 227  
  228 +static int on_ipaddr(const char *name, const char *value, enum env_op op,
  229 + int flags)
  230 +{
  231 + if (flags & H_PROGRAMMATIC)
  232 + return 0;
  233 +
  234 + net_ip = string_to_ip(value);
  235 +
  236 + return 0;
  237 +}
  238 +U_BOOT_ENV_CALLBACK(ipaddr, on_ipaddr);
  239 +
  240 +static int on_gatewayip(const char *name, const char *value, enum env_op op,
  241 + int flags)
  242 +{
  243 + if (flags & H_PROGRAMMATIC)
  244 + return 0;
  245 +
  246 + net_gateway = string_to_ip(value);
  247 +
  248 + return 0;
  249 +}
  250 +U_BOOT_ENV_CALLBACK(gatewayip, on_gatewayip);
  251 +
  252 +static int on_netmask(const char *name, const char *value, enum env_op op,
  253 + int flags)
  254 +{
  255 + if (flags & H_PROGRAMMATIC)
  256 + return 0;
  257 +
  258 + net_netmask = string_to_ip(value);
  259 +
  260 + return 0;
  261 +}
  262 +U_BOOT_ENV_CALLBACK(netmask, on_netmask);
  263 +
  264 +static int on_serverip(const char *name, const char *value, enum env_op op,
  265 + int flags)
  266 +{
  267 + if (flags & H_PROGRAMMATIC)
  268 + return 0;
  269 +
  270 + net_server_ip = string_to_ip(value);
  271 +
  272 + return 0;
  273 +}
  274 +U_BOOT_ENV_CALLBACK(serverip, on_serverip);
  275 +
  276 +static int on_nvlan(const char *name, const char *value, enum env_op op,
  277 + int flags)
  278 +{
  279 + if (flags & H_PROGRAMMATIC)
  280 + return 0;
  281 +
  282 + net_native_vlan = string_to_vlan(value);
  283 +
  284 + return 0;
  285 +}
  286 +U_BOOT_ENV_CALLBACK(nvlan, on_nvlan);
  287 +
  288 +static int on_vlan(const char *name, const char *value, enum env_op op,
  289 + int flags)
  290 +{
  291 + if (flags & H_PROGRAMMATIC)
  292 + return 0;
  293 +
  294 + net_our_vlan = string_to_vlan(value);
  295 +
  296 + return 0;
  297 +}
  298 +U_BOOT_ENV_CALLBACK(vlan, on_vlan);
  299 +
  300 +#if defined(CONFIG_CMD_DNS)
  301 +static int on_dnsip(const char *name, const char *value, enum env_op op,
  302 + int flags)
  303 +{
  304 + if (flags & H_PROGRAMMATIC)
  305 + return 0;
  306 +
  307 + net_dns_server = string_to_ip(value);
  308 +
  309 + return 0;
  310 +}
  311 +U_BOOT_ENV_CALLBACK(dnsip, on_dnsip);
  312 +#endif
  313 +
225 314 /*
226 315 * Check if autoload is enabled. If so, use either NFS or TFTP to download
227 316 * the boot file.
... ... @@ -252,22 +341,6 @@
252 341  
253 342 static void net_init_loop(void)
254 343 {
255   - static int env_changed_id;
256   - int env_id = get_env_id();
257   -
258   - /* update only when the environment has changed */
259   - if (env_changed_id != env_id) {
260   - net_ip = getenv_ip("ipaddr");
261   - net_gateway = getenv_ip("gatewayip");
262   - net_netmask = getenv_ip("netmask");
263   - net_server_ip = getenv_ip("serverip");
264   - net_native_vlan = getenv_vlan("nvlan");
265   - net_our_vlan = getenv_vlan("vlan");
266   -#if defined(CONFIG_CMD_DNS)
267   - net_dns_server = getenv_ip("dnsip");
268   -#endif
269   - env_changed_id = env_id;
270   - }
271 344 if (eth_get_dev())
272 345 memcpy(net_ethaddr, eth_get_ethaddr(), 6);
273 346