[PATCH rtems-lwip] lwip.py: Move bsp-specific information out

Kinsey Moore kinsey.moore at oarcorp.com
Wed Nov 9 22:57:13 UTC 2022


This moves all BSP-specific information out of lwip.py and into JSON
descriptions of the files required to compile the drivers for each BSP.

Note that file-import.json is kept separate because it is used to manage
updating from upstream.
---
 COPYING.defs                                  |  23 ++++
 ORIGIN.defs                                   |   1 +
 defs/bsps/aarch64/xilinx_zynqmp_base.json     |  30 ++++
 .../aarch64/xilinx_zynqmp_ilp32_qemu.json     |  11 ++
 .../aarch64/xilinx_zynqmp_ilp32_zu3eg.json    |  11 ++
 .../bsps/aarch64/xilinx_zynqmp_lp64_qemu.json |  11 ++
 .../aarch64/xilinx_zynqmp_lp64_zu3eg.json     |  11 ++
 defs/bsps/arm/beaglebone_bw_base.json         |  10 ++
 defs/bsps/arm/beagleboneblack.json            |   5 +
 defs/bsps/arm/beaglebonewhite.json            |   5 +
 defs/bsps/arm/tms570_base.json                |   9 ++
 defs/bsps/arm/tms570ls3137_hdk.json           |   5 +
 defs/bsps/arm/tms570ls3137_hdk_intram.json    |   5 +
 defs/bsps/arm/tms570ls3137_hdk_sdram.json     |   5 +
 .../arm/tms570ls3137_hdk_with_loader.json     |   5 +
 defs/common/lwip.json                         |  17 +++
 lwip.py                                       | 129 ++++--------------
 17 files changed, 194 insertions(+), 99 deletions(-)
 create mode 100644 COPYING.defs
 create mode 100644 ORIGIN.defs
 create mode 100644 defs/bsps/aarch64/xilinx_zynqmp_base.json
 create mode 100644 defs/bsps/aarch64/xilinx_zynqmp_ilp32_qemu.json
 create mode 100644 defs/bsps/aarch64/xilinx_zynqmp_ilp32_zu3eg.json
 create mode 100644 defs/bsps/aarch64/xilinx_zynqmp_lp64_qemu.json
 create mode 100644 defs/bsps/aarch64/xilinx_zynqmp_lp64_zu3eg.json
 create mode 100644 defs/bsps/arm/beaglebone_bw_base.json
 create mode 100644 defs/bsps/arm/beagleboneblack.json
 create mode 100644 defs/bsps/arm/beaglebonewhite.json
 create mode 100644 defs/bsps/arm/tms570_base.json
 create mode 100644 defs/bsps/arm/tms570ls3137_hdk.json
 create mode 100644 defs/bsps/arm/tms570ls3137_hdk_intram.json
 create mode 100644 defs/bsps/arm/tms570ls3137_hdk_sdram.json
 create mode 100644 defs/bsps/arm/tms570ls3137_hdk_with_loader.json
 create mode 100644 defs/common/lwip.json

diff --git a/COPYING.defs b/COPYING.defs
new file mode 100644
index 0000000..d971823
--- /dev/null
+++ b/COPYING.defs
@@ -0,0 +1,23 @@
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
diff --git a/ORIGIN.defs b/ORIGIN.defs
new file mode 100644
index 0000000..33c421c
--- /dev/null
+++ b/ORIGIN.defs
@@ -0,0 +1 @@
+The files under the defs/ directory are written specifically for this project.
diff --git a/defs/bsps/aarch64/xilinx_zynqmp_base.json b/defs/bsps/aarch64/xilinx_zynqmp_base.json
new file mode 100644
index 0000000..515ad6e
--- /dev/null
+++ b/defs/bsps/aarch64/xilinx_zynqmp_base.json
@@ -0,0 +1,30 @@
+{
+	"header-paths-to-import": [
+		"embeddedsw/ThirdParty/sw_services/lwip211/src/contrib/ports/xilinx/include",
+		"embeddedsw/lib/bsp/standalone/src/common",
+		"embeddedsw/XilinxProcessorIPLib/drivers/common/src/",
+		"embeddedsw/XilinxProcessorIPLib/drivers/scugic/src",
+		"embeddedsw/XilinxProcessorIPLib/drivers/emacps/src",
+		"rtemslwip/xilinx",
+		"rtemslwip/zynqmp",
+		"embeddedsw/lib/bsp/standalone/src/arm/ARMv8/64bit",
+		"embeddedsw/lib/bsp/standalone/src/arm/common/gcc",
+		"embeddedsw/lib/bsp/standalone/src/arm/common"
+	],
+	"source-paths-to-import": [
+		"rtemslwip/zynqmp"
+	],
+	"source-files-to-import": [
+		"embeddedsw/ThirdParty/sw_services/lwip211/src/contrib/ports/xilinx/netif/xadapter.c",
+		"embeddedsw/ThirdParty/sw_services/lwip211/src/contrib/ports/xilinx/netif/xpqueue.c",
+		"embeddedsw/ThirdParty/sw_services/lwip211/src/contrib/ports/xilinx/netif/xemacpsif.c",
+		"embeddedsw/ThirdParty/sw_services/lwip211/src/contrib/ports/xilinx/netif/xemacpsif_dma.c",
+		"embeddedsw/ThirdParty/sw_services/lwip211/src/contrib/ports/xilinx/netif/xemacpsif_hw.c",
+		"embeddedsw/ThirdParty/sw_services/lwip211/src/contrib/ports/xilinx/netif/xemacpsif_physpeed.c",
+		"embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps_bdring.c",
+		"embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps.c",
+		"embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps_control.c",
+		"embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps_intr.c",
+		"embeddedsw/lib/bsp/standalone/src/common/xil_assert.c"
+	]
+}
diff --git a/defs/bsps/aarch64/xilinx_zynqmp_ilp32_qemu.json b/defs/bsps/aarch64/xilinx_zynqmp_ilp32_qemu.json
new file mode 100644
index 0000000..ed8667d
--- /dev/null
+++ b/defs/bsps/aarch64/xilinx_zynqmp_ilp32_qemu.json
@@ -0,0 +1,11 @@
+{
+	"includes": [
+		"xilinx_zynqmp_base"
+	],
+	"header-paths-to-import": [
+		"rtemslwip/zynqmp_qemu"
+	],
+	"source-paths-to-import": [
+		"rtemslwip/zynqmp_qemu"
+	]
+}
diff --git a/defs/bsps/aarch64/xilinx_zynqmp_ilp32_zu3eg.json b/defs/bsps/aarch64/xilinx_zynqmp_ilp32_zu3eg.json
new file mode 100644
index 0000000..4438ed2
--- /dev/null
+++ b/defs/bsps/aarch64/xilinx_zynqmp_ilp32_zu3eg.json
@@ -0,0 +1,11 @@
+{
+	"includes": [
+		"xilinx_zynqmp_base"
+	],
+	"header-paths-to-import": [
+		"rtemslwip/zynqmp_hardware"
+	],
+	"source-paths-to-import": [
+		"rtemslwip/zynqmp_hardware"
+	]
+}
diff --git a/defs/bsps/aarch64/xilinx_zynqmp_lp64_qemu.json b/defs/bsps/aarch64/xilinx_zynqmp_lp64_qemu.json
new file mode 100644
index 0000000..ed8667d
--- /dev/null
+++ b/defs/bsps/aarch64/xilinx_zynqmp_lp64_qemu.json
@@ -0,0 +1,11 @@
+{
+	"includes": [
+		"xilinx_zynqmp_base"
+	],
+	"header-paths-to-import": [
+		"rtemslwip/zynqmp_qemu"
+	],
+	"source-paths-to-import": [
+		"rtemslwip/zynqmp_qemu"
+	]
+}
diff --git a/defs/bsps/aarch64/xilinx_zynqmp_lp64_zu3eg.json b/defs/bsps/aarch64/xilinx_zynqmp_lp64_zu3eg.json
new file mode 100644
index 0000000..4438ed2
--- /dev/null
+++ b/defs/bsps/aarch64/xilinx_zynqmp_lp64_zu3eg.json
@@ -0,0 +1,11 @@
+{
+	"includes": [
+		"xilinx_zynqmp_base"
+	],
+	"header-paths-to-import": [
+		"rtemslwip/zynqmp_hardware"
+	],
+	"source-paths-to-import": [
+		"rtemslwip/zynqmp_hardware"
+	]
+}
diff --git a/defs/bsps/arm/beaglebone_bw_base.json b/defs/bsps/arm/beaglebone_bw_base.json
new file mode 100644
index 0000000..9d25a67
--- /dev/null
+++ b/defs/bsps/arm/beaglebone_bw_base.json
@@ -0,0 +1,10 @@
+{
+	"header-paths-to-import": [
+		"rtemslwip/beaglebone",
+		"cpsw/src/include"
+	],
+	"source-paths-to-import": [
+		"rtemslwip/beaglebone",
+		"cpsw/src"
+	]
+}
diff --git a/defs/bsps/arm/beagleboneblack.json b/defs/bsps/arm/beagleboneblack.json
new file mode 100644
index 0000000..4eec688
--- /dev/null
+++ b/defs/bsps/arm/beagleboneblack.json
@@ -0,0 +1,5 @@
+{
+	"includes": [
+		"beablebone_bw_base"
+	]
+}
diff --git a/defs/bsps/arm/beaglebonewhite.json b/defs/bsps/arm/beaglebonewhite.json
new file mode 100644
index 0000000..4eec688
--- /dev/null
+++ b/defs/bsps/arm/beaglebonewhite.json
@@ -0,0 +1,5 @@
+{
+	"includes": [
+		"beablebone_bw_base"
+	]
+}
diff --git a/defs/bsps/arm/tms570_base.json b/defs/bsps/arm/tms570_base.json
new file mode 100644
index 0000000..33cd969
--- /dev/null
+++ b/defs/bsps/arm/tms570_base.json
@@ -0,0 +1,9 @@
+{
+	"header-paths-to-import": [
+		"uLan/ports/driver/tms570_emac",
+		"uLan/ports/os"
+	],
+	"source-paths-to-import": [
+		"uLan/ports/driver/tms570_emac"
+	]
+}
diff --git a/defs/bsps/arm/tms570ls3137_hdk.json b/defs/bsps/arm/tms570ls3137_hdk.json
new file mode 100644
index 0000000..3b6210f
--- /dev/null
+++ b/defs/bsps/arm/tms570ls3137_hdk.json
@@ -0,0 +1,5 @@
+{
+	"includes": [
+		"tms570_base"
+	]
+}
diff --git a/defs/bsps/arm/tms570ls3137_hdk_intram.json b/defs/bsps/arm/tms570ls3137_hdk_intram.json
new file mode 100644
index 0000000..3b6210f
--- /dev/null
+++ b/defs/bsps/arm/tms570ls3137_hdk_intram.json
@@ -0,0 +1,5 @@
+{
+	"includes": [
+		"tms570_base"
+	]
+}
diff --git a/defs/bsps/arm/tms570ls3137_hdk_sdram.json b/defs/bsps/arm/tms570ls3137_hdk_sdram.json
new file mode 100644
index 0000000..3b6210f
--- /dev/null
+++ b/defs/bsps/arm/tms570ls3137_hdk_sdram.json
@@ -0,0 +1,5 @@
+{
+	"includes": [
+		"tms570_base"
+	]
+}
diff --git a/defs/bsps/arm/tms570ls3137_hdk_with_loader.json b/defs/bsps/arm/tms570ls3137_hdk_with_loader.json
new file mode 100644
index 0000000..3b6210f
--- /dev/null
+++ b/defs/bsps/arm/tms570ls3137_hdk_with_loader.json
@@ -0,0 +1,5 @@
+{
+	"includes": [
+		"tms570_base"
+	]
+}
diff --git a/defs/common/lwip.json b/defs/common/lwip.json
new file mode 100644
index 0000000..a637c45
--- /dev/null
+++ b/defs/common/lwip.json
@@ -0,0 +1,17 @@
+{
+	"header-paths-to-import": [
+		"rtemslwip/bsd_compat_include",
+		"lwip/src/include",
+		"uLan/ports/os/rtems",
+		"rtemslwip/include"
+	],
+	"source-files-to-import" : [
+		"uLan/ports/os/rtems/arch/sys_arch.c",
+		"rtemslwip/common/syslog.c",
+		"rtemslwip/common/rtems_lwip_io.c",
+		"rtemslwip/common/network_compat.c",
+		"rtemslwip/bsd_compat/netdb.c",
+		"rtemslwip/bsd_compat/ifaddrs.c",
+		"rtemslwip/bsd_compat/rtems-kernel-program.c"
+	]
+}
diff --git a/lwip.py b/lwip.py
index 23ffccf..bcd898f 100644
--- a/lwip.py
+++ b/lwip.py
@@ -36,63 +36,6 @@ def removeprefix(data, prefix):
     return data
 
 
-xilinx_lwip_prefix = 'embeddedsw/ThirdParty/sw_services/lwip211/src/contrib/'
-xilinx_standalone_prefix = 'embeddedsw/lib/bsp/standalone/src/'
-
-xilinx_drv_incl = [
-    xilinx_lwip_prefix + 'ports/xilinx/include',
-    xilinx_standalone_prefix + 'common',
-    'embeddedsw/XilinxProcessorIPLib/drivers/common/src/',
-    'embeddedsw/XilinxProcessorIPLib/drivers/scugic/src',
-    'embeddedsw/XilinxProcessorIPLib/drivers/emacps/src',
-    'rtemslwip/xilinx'
-]
-
-xilinx_aarch64_drv_incl = [
-    'rtemslwip/zynqmp',
-    xilinx_standalone_prefix + 'arm/ARMv8/64bit',
-    xilinx_standalone_prefix + 'arm/common/gcc',
-    xilinx_standalone_prefix + 'arm/common'
-]
-
-# These sources are explicitly listed instead of using walk_sources below
-# because multiple BSPs of varying architecture are expected to use code from
-# the embeddedsw repository.
-xilinx_aarch64_driver_source = [
-    xilinx_lwip_prefix + 'ports/xilinx/netif/xadapter.c',
-    xilinx_lwip_prefix + 'ports/xilinx/netif/xpqueue.c',
-    xilinx_lwip_prefix + 'ports/xilinx/netif/xemacpsif.c',
-    xilinx_lwip_prefix + 'ports/xilinx/netif/xemacpsif_dma.c',
-    xilinx_lwip_prefix + 'ports/xilinx/netif/xemacpsif_hw.c',
-    xilinx_lwip_prefix + 'ports/xilinx/netif/xemacpsif_physpeed.c',
-    'embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps_bdring.c',
-    'embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps.c',
-    'embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps_control.c',
-    'embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps_intr.c',
-    xilinx_standalone_prefix + 'common/xil_assert.c'
-]
-
-common_includes = [
-    'lwip/src/include',
-    'uLan/ports/os/rtems',
-    'rtemslwip/include'
-]
-
-bsd_compat_incl = [
-    'rtemslwip/bsd_compat_include'
-]
-
-common_source_files = [
-    'uLan/ports/os/rtems/arch/sys_arch.c',
-    'rtemslwip/common/syslog.c',
-    'rtemslwip/common/rtems_lwip_io.c',
-    'rtemslwip/common/network_compat.c',
-    'rtemslwip/bsd_compat/netdb.c',
-    'rtemslwip/bsd_compat/ifaddrs.c',
-    'rtemslwip/bsd_compat/rtems-kernel-program.c'
-]
-
-
 def build(bld):
     source_files = []
     driver_source = []
@@ -101,59 +44,48 @@ def build(bld):
                                             bld.env.RTEMS_ARCH_BSP)
     arch = rtems.arch(bld.env.RTEMS_ARCH_BSP)
     bsp = rtems.bsp(bld.env.RTEMS_ARCH_BSP)
+
+    # file-import.json is kept separate from the rest of the defs because it
+    # describes which files are imported from upstream lwip
     with open('file-import.json', 'r') as cf:
         files = json.load(cf)
         for f in files['files-to-import']:
             if f[-2:] == '.c':
                 source_files.append(os.path.join('lwip', f))
 
-    source_files.extend(common_source_files)
-
     def walk_sources(path):
         return bld.path.ant_glob([path + '/**/*.c', path + '/**/*.S'])
 
-    if arch == 'arm':
-        # These files will not compile for BSPs other than TMS570
-        if bsp in ['tms570ls3137_hdk', 'tms570ls3137_hdk_intram',
-                   'tms570ls3137_hdk_sdram', 'tms570ls3137_hdk_with_loader']:
-            drv_incl.append('uLan/ports/driver/tms570_emac')
-            drv_incl.append('uLan/ports/os')
-            driver_source.extend(walk_sources('uLan/ports/driver/tms570_emac'))
-
-        # These files will only compile for BeagleBone BSPs
-        if bsp in ['beagleboneblack', 'beaglebonewhite']:
-            driver_source.extend(walk_sources('rtemslwip/beaglebone'))
-            drv_incl.append('rtemslwip/beaglebone')
-            drv_incl.append('cpsw/src/include')
-            driver_source.extend(walk_sources('cpsw/src'))
-
-
-    # These files will only compile for BSPs on Xilinx hardware
-    is_xilinx_bsp = False
-    is_aarch64_bsp = False
-    is_qemu = False
-    if arch == 'aarch64' and bsp in ['xilinx_zynqmp_lp64_qemu',
-                                     'xilinx_zynqmp_lp64_zu3eg',
-                                     'xilinx_zynqmp_ilp32_qemu',
-                                     'xilinx_zynqmp_ilp32_zu3eg']:
-        is_xilinx_bsp = True
-        is_aarch64_bsp = True
-    if bsp in ['xilinx_zynqmp_lp64_qemu', 'xilinx_zynqmp_ilp32_qemu']:
-        is_qemu = True
-    if is_xilinx_bsp:
-        drv_incl.extend(xilinx_drv_incl)
-        if is_aarch64_bsp:
-            driver_source.extend(walk_sources('rtemslwip/zynqmp'))
-            if is_qemu:
-                driver_source.extend(walk_sources('rtemslwip/zynqmp_qemu'))
-            else:
-                driver_source.extend(walk_sources('rtemslwip/zynqmp_hardware'))
-            driver_source.extend(xilinx_aarch64_driver_source)
-            drv_incl.extend(xilinx_aarch64_drv_incl)
+    def import_json_definition(prefix, path):
+        sources = []
+        includes = []
+        with open(os.path.join(prefix, path), 'r') as bspconfig:
+            files = json.load(bspconfig)
+            if 'includes' in files:
+                for f in files['includes']:
+                    tmpsrc, tmpincl = import_json_definition(prefix, f+'.json')
+                    sources.extend(tmpsrc)
+                    includes.extend(tmpincl)
+            if 'source-files-to-import' in files:
+                sources.extend(files['source-files-to-import'])
+            if 'source-paths-to-import' in files:
+                for f in files['source-paths-to-import']:
+                    sources.extend(walk_sources(f))
+            if 'header-paths-to-import' in files:
+                includes.extend(files['header-paths-to-import'])
+        return (sources, includes)
+
+    # import additional lwip source
+    more_lwip_sources, common_includes = import_json_definition(
+        'defs/common', 'lwip.json')
+    source_files.extend(more_lwip_sources)
+
+    # import bsp files
+    driver_source, drv_incl = import_json_definition(
+        os.path.join('defs/bsps', arch), bsp+'.json')
 
     lwip_obj_incl = []
     lwip_obj_incl.extend(drv_incl)
-    lwip_obj_incl.extend(bsd_compat_incl)
     lwip_obj_incl.extend(common_includes)
 
     bld(features='c',
@@ -194,7 +126,6 @@ def build(bld):
 
     [install_headers(path) for path in common_includes]
     [install_headers(path) for path in drv_incl]
-    [install_headers(path) for path in bsd_compat_incl]
 
     test_app_incl = []
     test_app_incl.extend(drv_incl)
-- 
2.30.2



More information about the devel mailing list