1 | # |
---|
2 | # RTEMS Project (https://www.rtems.org/) |
---|
3 | # |
---|
4 | # Copyright (c) 2021 Vijay Kumar Banerjee <vijay@rtems.org>. |
---|
5 | # All rights reserved. |
---|
6 | # |
---|
7 | # Redistribution and use in source and binary forms, with or without |
---|
8 | # modification, are permitted provided that the following conditions |
---|
9 | # are met: |
---|
10 | # 1. Redistributions of source code must retain the above copyright |
---|
11 | # notice, this list of conditions and the following disclaimer. |
---|
12 | # 2. Redistributions in binary form must reproduce the above copyright |
---|
13 | # notice, this list of conditions and the following disclaimer in the |
---|
14 | # documentation and/or other materials provided with the distribution. |
---|
15 | # |
---|
16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
17 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
18 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
19 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
---|
20 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
21 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
---|
22 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
26 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
27 | |
---|
28 | from rtems_waf import rtems |
---|
29 | import json |
---|
30 | import os |
---|
31 | |
---|
32 | |
---|
33 | def removeprefix(data, prefix): |
---|
34 | if data.startswith(prefix): |
---|
35 | return data[len(prefix):] |
---|
36 | return data |
---|
37 | |
---|
38 | |
---|
39 | xilinx_lwip_prefix = 'embeddedsw/ThirdParty/sw_services/lwip211/src/contrib/' |
---|
40 | xilinx_standalone_prefix = 'embeddedsw/lib/bsp/standalone/src/' |
---|
41 | |
---|
42 | xilinx_drv_incl = [ |
---|
43 | xilinx_lwip_prefix + 'ports/xilinx/include', |
---|
44 | xilinx_standalone_prefix + 'common', |
---|
45 | 'embeddedsw/XilinxProcessorIPLib/drivers/common/src/', |
---|
46 | 'embeddedsw/XilinxProcessorIPLib/drivers/scugic/src', |
---|
47 | 'embeddedsw/XilinxProcessorIPLib/drivers/emacps/src', |
---|
48 | 'rtemslwip/xilinx' |
---|
49 | ] |
---|
50 | |
---|
51 | xilinx_aarch64_drv_incl = [ |
---|
52 | 'rtemslwip/zynqmp', |
---|
53 | xilinx_standalone_prefix + 'arm/ARMv8/64bit', |
---|
54 | xilinx_standalone_prefix + 'arm/common/gcc', |
---|
55 | xilinx_standalone_prefix + 'arm/common' |
---|
56 | ] |
---|
57 | |
---|
58 | # These sources are explicitly listed instead of using walk_sources below |
---|
59 | # because multiple BSPs of varying architecture are expected to use code from |
---|
60 | # the embeddedsw repository. |
---|
61 | xilinx_aarch64_driver_source = [ |
---|
62 | xilinx_lwip_prefix + 'ports/xilinx/netif/xadapter.c', |
---|
63 | xilinx_lwip_prefix + 'ports/xilinx/netif/xpqueue.c', |
---|
64 | xilinx_lwip_prefix + 'ports/xilinx/netif/xemacpsif.c', |
---|
65 | xilinx_lwip_prefix + 'ports/xilinx/netif/xemacpsif_dma.c', |
---|
66 | xilinx_lwip_prefix + 'ports/xilinx/netif/xemacpsif_hw.c', |
---|
67 | xilinx_lwip_prefix + 'ports/xilinx/netif/xemacpsif_physpeed.c', |
---|
68 | 'embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps_bdring.c', |
---|
69 | 'embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps.c', |
---|
70 | 'embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps_control.c', |
---|
71 | 'embeddedsw/XilinxProcessorIPLib/drivers/emacps/src/xemacps_intr.c', |
---|
72 | xilinx_standalone_prefix + 'common/xil_assert.c' |
---|
73 | ] |
---|
74 | |
---|
75 | common_includes = [ |
---|
76 | 'lwip/src/include', |
---|
77 | 'uLan/ports/os/rtems', |
---|
78 | 'rtemslwip/include' |
---|
79 | ] |
---|
80 | |
---|
81 | bsd_compat_incl = [ |
---|
82 | 'rtemslwip/bsd_compat_include' |
---|
83 | ] |
---|
84 | |
---|
85 | common_source_files = [ |
---|
86 | 'uLan/ports/os/rtems/arch/sys_arch.c', |
---|
87 | 'rtemslwip/common/syslog.c', |
---|
88 | 'rtemslwip/common/rtems_lwip_io.c', |
---|
89 | 'rtemslwip/common/network_compat.c', |
---|
90 | 'rtemslwip/bsd_compat/netdb.c', |
---|
91 | 'rtemslwip/bsd_compat/ifaddrs.c', |
---|
92 | 'rtemslwip/bsd_compat/rtems-kernel-program.c' |
---|
93 | ] |
---|
94 | |
---|
95 | |
---|
96 | def build(bld): |
---|
97 | source_files = [] |
---|
98 | driver_source = [] |
---|
99 | drv_incl = [] |
---|
100 | arch_lib_path = rtems.arch_bsp_lib_path(bld.env.RTEMS_VERSION, |
---|
101 | bld.env.RTEMS_ARCH_BSP) |
---|
102 | arch = rtems.arch(bld.env.RTEMS_ARCH_BSP) |
---|
103 | bsp = rtems.bsp(bld.env.RTEMS_ARCH_BSP) |
---|
104 | with open('file-import.json', 'r') as cf: |
---|
105 | files = json.load(cf) |
---|
106 | for f in files['files-to-import']: |
---|
107 | if f[-2:] == '.c': |
---|
108 | source_files.append(os.path.join('lwip', f)) |
---|
109 | |
---|
110 | source_files.extend(common_source_files) |
---|
111 | |
---|
112 | def walk_sources(path): |
---|
113 | return bld.path.ant_glob([path + '/**/*.c', path + '/**/*.S']) |
---|
114 | |
---|
115 | if arch == 'arm': |
---|
116 | # These files will not compile for BSPs other than TMS570 |
---|
117 | if bsp in ['tms570ls3137_hdk', 'tms570ls3137_hdk_intram', |
---|
118 | 'tms570ls3137_hdk_sdram', 'tms570ls3137_hdk_with_loader']: |
---|
119 | drv_incl.append('uLan/ports/driver/tms570_emac') |
---|
120 | drv_incl.append('uLan/ports/os') |
---|
121 | driver_source.extend(walk_sources('uLan/ports/driver/tms570_emac')) |
---|
122 | |
---|
123 | # These files will only compile for BeagleBone BSPs |
---|
124 | if bsp in ['beagleboneblack', 'beaglebonewhite']: |
---|
125 | driver_source.extend(walk_sources('rtemslwip/beaglebone')) |
---|
126 | drv_incl.append('rtemslwip/beaglebone') |
---|
127 | drv_incl.append('cpsw/src/include') |
---|
128 | driver_source.extend(walk_sources('cpsw/src')) |
---|
129 | |
---|
130 | |
---|
131 | # These files will only compile for BSPs on Xilinx hardware |
---|
132 | is_xilinx_bsp = False |
---|
133 | is_aarch64_bsp = False |
---|
134 | is_qemu = False |
---|
135 | if arch == 'aarch64' and bsp in ['xilinx_zynqmp_lp64_qemu', |
---|
136 | 'xilinx_zynqmp_lp64_zu3eg', |
---|
137 | 'xilinx_zynqmp_ilp32_qemu', |
---|
138 | 'xilinx_zynqmp_ilp32_zu3eg']: |
---|
139 | is_xilinx_bsp = True |
---|
140 | is_aarch64_bsp = True |
---|
141 | if bsp in ['xilinx_zynqmp_lp64_qemu', 'xilinx_zynqmp_ilp32_qemu']: |
---|
142 | is_qemu = True |
---|
143 | if is_xilinx_bsp: |
---|
144 | drv_incl.extend(xilinx_drv_incl) |
---|
145 | if is_aarch64_bsp: |
---|
146 | driver_source.extend(walk_sources('rtemslwip/zynqmp')) |
---|
147 | if is_qemu: |
---|
148 | driver_source.extend(walk_sources('rtemslwip/zynqmp_qemu')) |
---|
149 | else: |
---|
150 | driver_source.extend(walk_sources('rtemslwip/zynqmp_hardware')) |
---|
151 | driver_source.extend(xilinx_aarch64_driver_source) |
---|
152 | drv_incl.extend(xilinx_aarch64_drv_incl) |
---|
153 | |
---|
154 | lwip_obj_incl = [] |
---|
155 | lwip_obj_incl.extend(drv_incl) |
---|
156 | lwip_obj_incl.extend(bsd_compat_incl) |
---|
157 | lwip_obj_incl.extend(common_includes) |
---|
158 | |
---|
159 | bld(features='c', |
---|
160 | target='lwip_obj', |
---|
161 | cflags='-g -Wall -O0', |
---|
162 | includes=' '.join(lwip_obj_incl), |
---|
163 | source=source_files, |
---|
164 | ) |
---|
165 | |
---|
166 | drv_obj_incl = [] |
---|
167 | drv_obj_incl.extend(drv_incl) |
---|
168 | drv_obj_incl.extend(common_includes) |
---|
169 | |
---|
170 | bld(features='c', |
---|
171 | target='driver_obj', |
---|
172 | cflags='-g -Wall -O0', |
---|
173 | includes=' '.join(drv_obj_incl), |
---|
174 | source=driver_source, |
---|
175 | ) |
---|
176 | bld(features='c cstlib', |
---|
177 | target='lwip', |
---|
178 | cflags='-g -Wall -O0', |
---|
179 | use=['lwip_obj', 'driver_obj']) |
---|
180 | bld.install_files("${PREFIX}/" + arch_lib_path, ["liblwip.a"]) |
---|
181 | |
---|
182 | def install_headers(root_path): |
---|
183 | for root, dirs, files in os.walk(root_path): |
---|
184 | for name in files: |
---|
185 | ext = os.path.splitext(name)[1] |
---|
186 | src_root = os.path.split(root) |
---|
187 | path = os.path.join(src_root[0], src_root[1]) |
---|
188 | if ext == '.h': |
---|
189 | subpath = removeprefix(removeprefix(path, root_path), "/") |
---|
190 | bld.install_files( |
---|
191 | "${PREFIX}/" + arch_lib_path + "/include/" + subpath, |
---|
192 | os.path.join(path, name) |
---|
193 | ) |
---|
194 | |
---|
195 | [install_headers(path) for path in common_includes] |
---|
196 | [install_headers(path) for path in drv_incl] |
---|
197 | [install_headers(path) for path in bsd_compat_incl] |
---|
198 | |
---|
199 | test_app_incl = [] |
---|
200 | test_app_incl.extend(drv_incl) |
---|
201 | test_app_incl.extend(common_includes) |
---|
202 | test_app_incl.append('rtemslwip/test/') |
---|
203 | bld.program(features='c', |
---|
204 | target='networking01.exe', |
---|
205 | source='rtemslwip/test/networking01/sample_app.c', |
---|
206 | cflags='-g -Wall -O0', |
---|
207 | use='lwip', |
---|
208 | lib=['rtemscpu', 'rtemsbsp', 'rtemstest', 'lwip'], |
---|
209 | includes=' '.join(test_app_incl)) |
---|
210 | |
---|
211 | lib_path = os.path.join(bld.env.PREFIX, arch_lib_path) |
---|
212 | bld.read_stlib('telnetd', paths=[lib_path]) |
---|
213 | bld.read_stlib('rtemstest', paths=[lib_path]) |
---|
214 | bld.read_stlib('ftpd', paths=[lib_path]) |
---|
215 | |
---|
216 | bld.program(features='c', |
---|
217 | target='telnetd01.exe', |
---|
218 | source='rtemslwip/test/telnetd01/init.c', |
---|
219 | use='telnetd lwip rtemstest ftpd', |
---|
220 | cflags='-g -Wall -O0', |
---|
221 | includes=' '.join(test_app_incl)) |
---|
222 | |
---|
223 | |
---|
224 | def add_flags(flags, new_flags): |
---|
225 | for flag in new_flags: |
---|
226 | if flag not in flags: |
---|
227 | flags.append(flag) |
---|
228 | |
---|
229 | |
---|
230 | def bsp_configure(conf, arch_bsp): |
---|
231 | conf.env.LIB += ['m'] |
---|
232 | section_flags = ["-fdata-sections", "-ffunction-sections"] |
---|
233 | add_flags(conf.env.CFLAGS, section_flags) |
---|
234 | add_flags(conf.env.CXXFLAGS, section_flags) |
---|