Skip to content

Commit ec0c09c

Browse files
committed
Allow usage of network gateway and subnets in SoC generation
1 parent 5d896c4 commit ec0c09c

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

make.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def main():
5757
parser.add_argument("--doc", action="store_true", help="Build documentation.")
5858
parser.add_argument("--local-ip", default="192.168.1.50", help="Local IP address.")
5959
parser.add_argument("--remote-ip", default="192.168.1.100", help="Remote IP address of TFTP server.")
60+
parser.add_argument("--use-gateway", action="store_true", help="Use a network gateway for out-of-subnet TFTP servers.")
61+
parser.add_argument("--gateway-ip", default="192.168.1.1", help="Default gateway IP address.")
62+
parser.add_argument("--subnet-mask", default="255.255.255.0", help="Subnet mask.")
6063
parser.add_argument("--spi-data-width", default=8, type=int, help="SPI data width (max bits per xfer).")
6164
parser.add_argument("--spi-clk-freq", default=1e6, type=int, help="SPI clock frequency.")
6265
parser.add_argument("--fdtoverlays", default="", help="Device Tree Overlays to apply.")
@@ -159,7 +162,13 @@ def main():
159162
if "sdcard" in board.soc_capabilities:
160163
soc.add_sdcard()
161164
if "ethernet" in board.soc_capabilities:
162-
soc.configure_ethernet(remote_ip=args.remote_ip, local_ip=args.local_ip)
165+
soc.configure_ethernet(
166+
remote_ip = args.remote_ip,
167+
local_ip = args.local_ip,
168+
use_gateway = args.use_gateway,
169+
gateway_ip = args.gateway_ip,
170+
subnet_mask = args.subnet_mask
171+
)
163172
#if "leds" in board.soc_capabilities:
164173
# soc.add_leds()
165174
if "rgb_led" in board.soc_capabilities:

soc_linux.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ def add_i2c(self):
5757

5858
# Ethernet configuration -------------------------------------------------------------------
5959

60-
def configure_ethernet(self, remote_ip, local_ip):
60+
def configure_ethernet(self, remote_ip, local_ip, use_gateway, gateway_ip, subnet_mask):
6161
remote_ip = remote_ip.split(".")
6262
local_ip = local_ip.split(".")
63+
gateway_ip = gateway_ip.split(".")
64+
subnet_mask = subnet_mask.split(".")
6365

6466
try: # FIXME: Improve.
6567
self.constants.pop("REMOTEIP1")
@@ -85,6 +87,33 @@ def configure_ethernet(self, remote_ip, local_ip):
8587
self.add_constant("LOCALIP3", int(local_ip[2]))
8688
self.add_constant("LOCALIP4", int(local_ip[3]))
8789

90+
try: # FIXME: Improve.
91+
self.constants.pop("GATEWAYIP1")
92+
self.constants.pop("GATEWAYIP2")
93+
self.constants.pop("GATEWAYIP3")
94+
self.constants.pop("GATEWAYIP4")
95+
except:
96+
pass
97+
self.add_constant("GATEWAYIP1", int(gateway_ip[0]))
98+
self.add_constant("GATEWAYIP2", int(gateway_ip[1]))
99+
self.add_constant("GATEWAYIP3", int(gateway_ip[2]))
100+
self.add_constant("GATEWAYIP4", int(gateway_ip[3]))
101+
102+
try: # FIXME: Improve.
103+
self.constants.pop("SUBNETMASK1")
104+
self.constants.pop("SUBNETMASK2")
105+
self.constants.pop("SUBNETMASK3")
106+
self.constants.pop("SUBNETMASK4")
107+
except:
108+
pass
109+
self.add_constant("SUBNETMASK1", int(subnet_mask[0]))
110+
self.add_constant("SUBNETMASK2", int(subnet_mask[1]))
111+
self.add_constant("SUBNETMASK3", int(subnet_mask[2]))
112+
self.add_constant("SUBNETMASK4", int(subnet_mask[3]))
113+
114+
if use_gateway:
115+
self.add_constant("ETH_NETBOOT_USE_GATEWAY")
116+
88117
# DTS generation ---------------------------------------------------------------------------
89118

90119
def generate_dts(self, board_name, rootfs="ram0"):

0 commit comments

Comments
 (0)