BAREBOX_CMD_END #endif /* CONFIG_NET_RARP */ static int do_ethact(struct command *cmdtp, int argc, char *argv[]) { struct eth_device *edev; if (argc == 1) { edev = eth_get_current(); if (edev) printf("%s%d\n", edev->dev.name, edev->dev.id); return 0; } if (argc != 2) return COMMAND_ERROR_USAGE; edev = eth_get_byname(argv[1]); if (edev) eth_set_current(edev); else { printf("no such net device: %s\n", argv[1]); return 1; } return 0; }
static int do_ethact(int argc, char *argv[]) { struct eth_device *edev; if (argc == 1) { edev = eth_get_current(); if (edev) printf("%s%d\n", edev->dev.name, edev->dev.id); return 0; } if (argc != 2) return COMMAND_ERROR_USAGE; edev = eth_get_byname(argv[1]); if (edev) eth_set_current(edev); else { printf("no such net device: %s\n", argv[1]); return 1; } return 0; }
static void *am33xx_net_boot(void) { void *buf = NULL; int err; int len; struct dhcp_req_param dhcp_param; const char *bootfile; IPaddr_t ip; char *file; char ip4_str[sizeof("255.255.255.255")]; struct eth_device *edev; struct dhcp_result *dhcp_res; am33xx_register_ethaddr(0, 0); memset(&dhcp_param, 0, sizeof(struct dhcp_req_param)); dhcp_param.vendor_id = "am335x barebox-mlo"; edev = eth_get_byname("eth0"); if (!edev) { printf("eth0 not found\n"); return NULL; } err = dhcp_request(edev, &dhcp_param, &dhcp_res); if (err) { printf("dhcp failed\n"); return NULL; } dhcp_set_result(edev, dhcp_res); edev->ifup = true; /* * Older tftp server don't send the file size. * Then tftpfs needs temporary place to store the file. */ err = mount("none", "ramfs", "/", NULL); if (err < 0) { printf("failed to mount ramfs\n"); return NULL; } err = make_directory(TFTP_MOUNT); if (err) return NULL; ip = net_get_serverip(); sprintf(ip4_str, "%pI4", &ip); err = mount(ip4_str, "tftp", TFTP_MOUNT, NULL); if (err < 0) { printf("Unable to mount.\n"); return NULL; } bootfile = dhcp_res->bootfile; if (!bootfile) { printf("bootfile not found.\n"); return NULL; } file = basprintf("%s/%s", TFTP_MOUNT, bootfile); buf = read_file(file, &len); if (!buf) printf("could not read %s.\n", bootfile); free(file); umount(TFTP_MOUNT); return buf; }
int ifup(const char *name, unsigned flags) { int ret; char *cmd, *cmd_discover; const char *ip; struct stat s; int i; struct device_d *dev; struct eth_device *edev = eth_get_byname(name); if (edev && edev->ipaddr && !(flags & IFUP_FLAG_FORCE)) return 0; eth_set_current(edev); env_push_context(); setenv("ip", ""); for (i = 0; i < ARRAY_SIZE(vars); i++) setenv(vars[i], ""); cmd = basprintf("source /env/network/%s", name); cmd_discover = basprintf("/env/network/%s-discover", name); ret = run_command(cmd); if (ret) { pr_err("Running '%s' failed with %d\n", cmd, ret); goto out; } ret = stat(cmd_discover, &s); if (!ret) { ret = run_command(cmd_discover); if (ret) { pr_err("Running '%s' failed with %d\n", cmd, ret); goto out; } } dev = get_device_by_name(name); if (!dev) { pr_err("Cannot find device %s\n", name); goto out; } ret = eth_set_param(dev, "ethaddr"); if (ret) goto out; ip = getenv("ip"); if (!ip) ip = ""; if (!strcmp(ip, "dhcp")) { ret = run_command("dhcp"); if (ret) goto out; ret = eth_set_param(dev, "serverip"); if (ret) goto out; } else if (!strcmp(ip, "static")) { for (i = 0; i < ARRAY_SIZE(vars); i++) { ret = eth_set_param(dev, vars[i]); if (ret) goto out; } } else { pr_err("unknown ip type: %s\n", ip); ret = -EINVAL; goto out; } ret = 0; out: env_pop_context(); free(cmd); free(cmd_discover); return ret; }