blob: b94d9512272a490ea24982278324cfa9bd6798b0 [file] [log] [blame]
Nico Huberc3b02dc2023-08-12 01:13:45 +02001project('flashprogutils', 'c',
Nikolai Artemiev47cb6fc2022-07-22 09:58:14 +10002 version : run_command('util/getversion.sh', '--version', check : true).stdout().strip(),
Nico Huberb417c0c2019-09-24 22:12:40 +02003 license : 'GPL-2.0',
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +02004 meson_version : '>=0.53.0',
Anastasia Klimchuk3c508432022-04-13 15:15:24 +10005 default_options : [
6 'warning_level=2',
7 'c_std=c99',
Anastasia Klimchukc676be92022-04-26 14:53:18 +10008 'werror=true',
Anastasia Klimchuk3c508432022-04-13 15:15:24 +10009 'optimization=s',
Nikolai Artemiev47cb6fc2022-07-22 09:58:14 +100010 'debug=false',
11 ],
Richard Hughescb973682018-12-19 11:44:22 +000012)
13
14# libtool versioning
15lt_current = '1'
16lt_revision = '0'
17lt_age = '0'
18lt_version = '@0@.@1@.@2@'.format(lt_current, lt_age, lt_revision)
19
Jacob Garber4a84ec22019-07-25 19:12:31 -060020# hide/enable some warnings
Richard Hughescb973682018-12-19 11:44:22 +000021warning_flags = [
Anastasia Klimchukcde70112021-10-25 13:20:26 +110022 '-Wshadow',
23 '-Wmissing-prototypes',
Jacob Garber4a84ec22019-07-25 19:12:31 -060024 '-Wwrite-strings',
Richard Hughescb973682018-12-19 11:44:22 +000025 '-Wno-unused-parameter',
Richard Hughescb973682018-12-19 11:44:22 +000026 '-Wno-address-of-packed-member',
27 '-Wno-enum-conversion',
Richard Hughescb973682018-12-19 11:44:22 +000028 '-Wno-missing-braces',
29]
30
Richard Hughescb973682018-12-19 11:44:22 +000031cc = meson.get_compiler('c')
32add_project_arguments(cc.get_supported_arguments(warning_flags), language : 'c')
33add_project_arguments('-D_DEFAULT_SOURCE', language : 'c')
Rosen Penev566193f2020-07-18 12:50:16 -070034add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c') # required for fileno, nanosleep, and strndup
Richard Hughescb973682018-12-19 11:44:22 +000035add_project_arguments('-D_BSD_SOURCE', language : 'c') # required for glibc < v2.19
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +020036add_project_arguments('-D__BSD_VISIBLE', language : 'c') # required for u_char, u_int, u_long on FreeBSD
37add_project_arguments('-D__XSI_VISIBLE', language : 'c') # required for gettimeofday() on FreeBSD
38add_project_arguments('-D_NETBSD_SOURCE', language : 'c') # required for indirect include of strings.h on NetBSD
39add_project_arguments('-D_DARWIN_C_SOURCE', language : 'c') # required for indirect include of strings.h on MacOS
Richard Hughescb973682018-12-19 11:44:22 +000040
41# get defaults from configure
Thomas Heijligenb975da12022-08-13 12:10:05 +020042config_print_wiki = get_option('classic_cli_print_wiki')
Thomas Heijligen84e9c912021-06-01 16:22:14 +020043config_default_programmer_name = get_option('default_programmer_name')
44config_default_programmer_args = get_option('default_programmer_args')
Richard Hughescb973682018-12-19 11:44:22 +000045
46cargs = []
47deps = []
Thomas Heijligen51208f32022-04-28 11:07:29 +020048srcs = files(
49 '82802ab.c',
50 'at45db.c',
51 'bitbang_spi.c',
52 'edi.c',
53 'en29lv640b.c',
54 'flashchips.c',
Nico Huberc3b02dc2023-08-12 01:13:45 +020055 'flashprog.c',
Thomas Heijligen51208f32022-04-28 11:07:29 +020056 'fmap.c',
57 'helpers.c',
Edward O'Callaghan4c76c732022-08-12 11:03:00 +100058 'helpers_fileio.c',
Thomas Heijligen51208f32022-04-28 11:07:29 +020059 'ich_descriptors.c',
60 'jedec.c',
61 'layout.c',
Nico Huberc3b02dc2023-08-12 01:13:45 +020062 'libflashprog.c',
Nico Hubere7598392026-06-23 22:29:15 +020063 'm28f.c',
Nico Huber0e76d992023-01-12 20:22:55 +010064 'memory_bus.c',
Thomas Heijligen51208f32022-04-28 11:07:29 +020065 'opaque.c',
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100066 'parallel.c',
Thomas Heijligen51208f32022-04-28 11:07:29 +020067 'print.c',
68 'programmer.c',
69 'programmer_table.c',
70 'sfdp.c',
71 'spi25.c',
Nico Huber8d0f4652024-05-04 18:52:51 +020072 'spi25_prepare.c',
Thomas Heijligen51208f32022-04-28 11:07:29 +020073 'spi25_statusreg.c',
74 'spi95.c',
75 'spi.c',
76 'sst28sf040.c',
77 'sst49lfxxxc.c',
78 'sst_fwhub.c',
79 'stm50.c',
80 'udelay.c',
81 'w29ee011.c',
82 'w39.c',
83 'writeprotect.c',
84 'writeprotect_ranges.c',
85)
Richard Hughescb973682018-12-19 11:44:22 +000086
Richard Hughescb973682018-12-19 11:44:22 +000087# check for required symbols
88if cc.has_function('clock_gettime')
89 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
90endif
91if cc.has_function('strnlen')
92 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
93endif
94if cc.check_header('sys/utsname.h')
95 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
96endif
Thomas Heijligenc02b1a92022-04-25 14:54:10 +020097if host_machine.system() in ['cygwin', 'windows']
98 add_project_arguments('-DIS_WINDOWS=1', language : 'c')
99else
100 add_project_arguments('-DIS_WINDOWS=0', language : 'c')
101endif
Richard Hughescb973682018-12-19 11:44:22 +0000102
Peter Stuge272b0732022-12-11 03:55:02 +0100103if host_machine.system() == 'linux'
104 custom_baud_c = 'custom_baud_linux.c'
Peter Stugeb8ee2d62022-12-11 16:20:16 +0100105elif host_machine.system() == 'darwin'
106 custom_baud_c = 'custom_baud_darwin.c'
Peter Stuge272b0732022-12-11 03:55:02 +0100107else
108 custom_baud_c = 'custom_baud.c'
109endif
110
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200111systems_hwaccess = [ 'linux', 'openbsd', 'freebsd', 'dragonfly', 'netbsd' ]
112systems_serial = [ 'linux', 'openbsd', 'freebsd', 'dragonfly', 'netbsd', 'darwin' ]
Richard Hughescb973682018-12-19 11:44:22 +0000113
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200114cpus_port_io = [ 'x86', 'x86_64' ]
Nico Huber72c9e402024-04-21 13:07:17 +0200115cpus_raw_mem = [ 'x86', 'x86_64', 'mips', 'mips64', 'ppc', 'ppc64', 'arm', 'aarch64', 'sparc', 'sparc64', 'arc', 'e2k' ]
Peter Marheine306c8b72022-01-21 02:07:30 +0000116
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200117group_ftdi = get_option('programmer').contains('group_ftdi')
118group_pci = get_option('programmer').contains('group_pci')
119group_usb = get_option('programmer').contains('group_usb')
120group_i2c = get_option('programmer').contains('group_i2c')
121group_serial = get_option('programmer').contains('group_serial')
122group_jlink = get_option('programmer').contains('group_jlink')
Steve Markgraf61899472023-01-09 23:06:52 +0100123group_gpiod = get_option('programmer').contains('group_gpiod')
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200124group_internal = get_option('programmer').contains('group_internal')
125group_external = get_option('programmer').contains('group_external')
Peter Marheine306c8b72022-01-21 02:07:30 +0000126
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200127libpci = dependency('libpci', required : group_pci, static : (host_machine.system() == 'openbsd' ? true : false)) # On openbsd a static version of libpci is needed to get also -libz
128libusb1 = dependency('libusb-1.0', required : group_usb)
129libftdi1 = dependency('libftdi1', required : group_ftdi)
130libjaylink = dependency('libjaylink', required : group_jlink)
Steve Markgraf61899472023-01-09 23:06:52 +0100131libgpiod = dependency('libgpiod', required : group_gpiod)
Richard Hughescb973682018-12-19 11:44:22 +0000132
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200133subdir('platform')
Richard Hughescb973682018-12-19 11:44:22 +0000134
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200135if systems_hwaccess.contains(host_machine.system())
Thomas Heijligen4bd966c2022-05-16 10:56:55 +0200136 srcs += files('hwaccess_physmap.c')
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200137 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
Nico Huberc0f3f0f2026-03-14 21:18:52 +0100138 add_project_arguments('-DHAVE_OUTB=1', language : 'c')
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200139 srcs += files('hwaccess_x86_msr.c', 'hwaccess_x86_io.c')
Thomas Heijligen140c1262021-09-27 15:12:26 +0200140 endif
Richard Hughescb973682018-12-19 11:44:22 +0000141endif
142
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200143# Pseudo dependencies
144linux_headers = \
145 cc.has_header('linux/i2c.h') and \
146 cc.has_header('linux/i2c-dev.h') and \
147 cc.has_header('mtd/mtd-user.h') and \
148 cc.has_header('linux/spi/spidev.h') ? declare_dependency() : dependency('', required : false)
Thomas Heijligenb975da12022-08-13 12:10:05 +0200149
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200150# '<programmer_name>' : {
151# 'system' : list[string], # default: ['all']
152# 'cpu_families : list[string], # default: ['all']
153# 'deps' : list[dep], # default: []
154# 'groups : list[boolean], # default: []
155# 'srcs' : list[file], # default: []
156# 'flags' : list[string], # default: []
157# 'default' : boolean, # default: true
158# 'active' : boolean, # added on runtime
159# }
160programmer = {
161 'atahpt' : {
162 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200163 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200164 'deps' : [ libpci ],
165 'groups' : [ group_pci, group_internal ],
166 'srcs' : files('atahpt.c', 'pcidev.c'),
167 'flags' : [ '-DCONFIG_ATAHPT=1' ],
168 'default' : false, # not yet working
169 },
170 'atapromise' : {
171 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200172 'cpu_families' : [ cpus_port_io, cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200173 'deps' : [ libpci ],
174 'groups' : [ group_pci, group_internal ],
175 'srcs' : files('atapromise.c', 'pcidev.c'),
176 'flags' : [ '-DCONFIG_ATAPROMISE=1' ],
177 'default' : false,
178 },
179 'atavia' : {
180 'systems' : systems_hwaccess,
181 'deps' : [ libpci ],
182 'groups' : [ group_pci, group_internal ],
183 'srcs' : files('atavia.c', 'pcidev.c'),
184 'flags' : [ '-DCONFIG_ATAVIA=1' ],
185 },
186 'buspirate_spi' : {
187 'systems' : systems_serial,
188 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100189 'srcs' : files('buspirate_spi.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200190 'flags' : [ '-DCONFIG_BUSPIRATE_SPI=1' ],
191 },
192 'ch341a_spi' : {
193 'deps' : [ libusb1 ],
194 'groups' : [ group_usb, group_external ],
195 'srcs' : files('ch341a_spi.c'),
196 'flags' : [ '-DCONFIG_CH341A_SPI=1' ],
197 },
Nicholas Chin197b7c72022-10-23 13:10:31 -0600198 'ch347_spi' : {
199 'deps' : [ libusb1 ],
200 'groups' : [ group_usb, group_external ],
201 'srcs' : files('ch347_spi.c'),
202 'flags' : [ '-DCONFIG_CH347_SPI=1' ],
203 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200204 'dediprog' : {
205 'deps' : [ libusb1 ],
206 'groups' : [ group_usb, group_external ],
207 'srcs' : files('dediprog.c', 'usbdev.c'),
208 'flags' : [ '-DCONFIG_DEDIPROG=1' ],
209 },
210 'developerbox_spi' : {
211 'deps' : [ libusb1 ],
212 'groups' : [ group_usb, group_external ],
213 'srcs' : files('developerbox_spi.c', 'usbdev.c'),
214 'flags' : [ '-DCONFIG_DEVELOPERBOX_SPI=1' ],
215 },
216 'digilent_spi' : {
217 'deps' : [ libusb1 ],
218 'groups' : [ group_usb, group_external ],
219 'srcs' : files('digilent_spi.c'),
220 'flags' : [ '-DCONFIG_DIGILENT_SPI=1' ],
221 },
222 'dirtyjtag_spi' : {
223 'deps' : [ libusb1 ],
224 'groups' : [ group_usb, group_external ],
225 'srcs' : files('dirtyjtag_spi.c'),
226 'flags' : [ '-DCONFIG_DIRTYJTAG_SPI=1' ],
227 },
228 'drkaiser' : {
229 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200230 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200231 'deps' : [ libpci ],
232 'groups' : [ group_pci, group_internal ],
233 'srcs' : files('drkaiser.c', 'pcidev.c'),
234 'flags' : [ '-DCONFIG_DRKAISER=1' ],
235 },
236 'dummy' : {
237 'srcs' : files('dummyflasher.c'),
238 'flags' : [ '-DCONFIG_DUMMY=1' ],
239 },
240 'ft2232_spi' : {
241 'deps' : [ libftdi1 ],
242 'groups' : [ group_ftdi, group_external ],
243 'srcs' : files('ft2232_spi.c' ),
244 'flags' : [ '-DCONFIG_FT2232_SPI=1' ],
245 },
Nico Huber522160f2024-08-11 11:03:05 +0200246 'ft4222_spi' : {
247 'deps' : [ libusb1 ],
248 'groups' : [ group_usb, group_ftdi, group_external ],
249 'srcs' : files('ft4222_spi.c' ),
250 'flags' : [ '-DCONFIG_FT4222_SPI=1' ],
251 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200252 'gfxnvidia' : {
253 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200254 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200255 'deps' : [ libpci ],
256 'groups' : [ group_pci, group_internal ],
257 'srcs' : files('gfxnvidia.c', 'pcidev.c'),
258 'flags' : [ '-DCONFIG_GFXNVIDIA=1' ],
259 },
260 'internal' : {
261 'systems' : systems_hwaccess + ['linux'],
Nico Huber72c9e402024-04-21 13:07:17 +0200262 'cpu_families' : (host_machine.system() == 'linux' ? [ cpus_raw_mem ] : [ ['x86', 'x86_64'] ]),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200263 'deps' : [ libpci ],
264 'groups' : [ group_internal ],
265 'srcs' : (host_machine.cpu_family() in ['x86', 'x86_64'] ? files(
266 'processor_enable.c',
267 'chipset_enable.c',
268 'board_enable.c',
269 'cbtable.c',
270 'internal.c',
271 'it87spi.c',
272 'sb600spi.c',
273 'amd_imc.c',
Nico Hubera1939832025-10-07 21:58:02 +0000274 'amd_rom3read.c',
Nico Huber735b1862023-01-29 18:28:45 +0000275 'amd_spi100.c',
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200276 'wbsio_spi.c',
277 'mcp6x_spi.c',
278 'ichspi.c',
279 'dmi.c',
280 'pcidev.c',
281 'known_boards.c',
282 ) : files(
283 'board_enable.c',
284 'cbtable.c',
285 'chipset_enable.c',
286 'internal.c',
287 'processor_enable.c',
288 'pcidev.c',
289 'known_boards.c',
290 )),
291 'flags' : [
292 '-DCONFIG_INTERNAL=1',
293 '-DCONFIG_INTERNAL_DMI=' + (get_option('use_internal_dmi') ? '1' : '0'),
Nico Huber2f753792023-03-28 00:46:50 +0200294 '-DLINUX_MTD_AS_INTERNAL=' + (host_machine.cpu_family() in ['x86', 'x86_64'] ? '0' : '1'),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200295 ]
296 },
297 'it8212' : {
298 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200299 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200300 'deps' : [ libpci ],
301 'groups' : [ group_pci, group_internal ],
302 'srcs' : files('it8212.c', 'pcidev.c'),
303 'flags' : [ '-DCONFIG_IT8212=1' ],
304 },
305 'jlink_spi' : {
306 'deps' : [ libjaylink ],
307 'groups' : [ group_jlink, group_external ],
308 'srcs' : files('jlink_spi.c'),
309 'flags' : [ '-DCONFIG_JLINK_SPI=1' ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200310 },
Steve Markgraf61899472023-01-09 23:06:52 +0100311 'linux_gpio_spi' : {
312 'systems' : [ 'linux' ],
313 'deps' : [ libgpiod ],
314 'groups' : [ group_gpiod, group_external ],
Nico Huber8d2c0df2024-01-14 23:39:40 +0100315 'srcs' : libgpiod.version() < '2.0.0'
316 ? files('linux_gpio_spi.c')
317 : files('linux_gpio2_spi.c'),
Nico Huberaa5268d2023-03-09 17:15:23 +0100318 'flags' : [ '-DCONFIG_LINUX_GPIO_SPI=1' ],
Steve Markgraf61899472023-01-09 23:06:52 +0100319 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200320 'linux_mtd' : {
321 'systems' : [ 'linux' ],
322 'deps' : [ linux_headers ],
323 'groups' : [ group_internal ],
324 'srcs' : files('linux_mtd.c'),
325 'flags' : [ '-DCONFIG_LINUX_MTD=1' ],
326 },
327 'linux_spi' : {
328 'systems' : [ 'linux' ],
329 'deps' : [ linux_headers ],
330 # internal / external?
331 'srcs' : files('linux_spi.c'),
332 'flags' : [ '-DCONFIG_LINUX_SPI=1' ],
333 },
334 'mstarddc_spi' : {
335 'systems' : [ 'linux' ],
336 'deps' : [ linux_headers ],
337 'groups' : [ group_i2c ],
338 'srcs' : files('mstarddc_spi.c'),
339 'flags' : [ '-DCONFIG_MSTARDDC_SPI=1' ],
340 'default' : false
341 },
342 'nic3com' : {
343 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200344 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200345 'deps' : [ libpci ],
346 'groups' : [ group_pci, group_internal ],
347 'srcs' : files('nic3com.c', 'pcidev.c'),
348 'flags' : [ '-DCONFIG_NIC3COM=1' ],
349 },
Nico Huberdd4744e2026-03-22 15:47:25 +0100350 'nicamd' : {
351 'systems' : systems_hwaccess,
352 'cpu_families' : [ cpus_port_io ],
353 'deps' : [ libpci ],
354 'groups' : [ group_pci, group_internal ],
355 'srcs' : files('nicamd.c', 'pcidev.c'),
356 'flags' : [ '-DCONFIG_NICAMD=1' ],
357 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200358 'nicintel' : {
359 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200360 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200361 'deps' : [ libpci ],
362 'groups' : [ group_pci, group_internal ],
363 'srcs' : files('nicintel.c', 'pcidev.c'),
364 'flags' : [ '-DCONFIG_NICINTEL=1' ],
365 },
366 'nicintel_eeprom' : {
367 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200368 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200369 'deps' : [ libpci ],
370 'groups' : [ group_pci, group_internal ],
371 'srcs' : files('nicintel_eeprom.c', 'pcidev.c'),
372 'flags' : [ '-DCONFIG_NICINTEL_EEPROM=1' ],
373 },
374 'nicintel_spi' : {
375 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200376 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200377 'deps' : [ libpci ],
378 'groups' : [ group_pci, group_internal ],
379 'srcs' : files('nicintel_spi.c', 'pcidev.c'),
380 'flags' : [ '-DCONFIG_NICINTEL_SPI=1' ],
381 },
382 'nicnatsemi' : {
383 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200384 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200385 'deps' : [ libpci ],
386 'groups' : [ group_pci, group_internal ],
387 'srcs' : files('nicnatsemi.c', 'pcidev.c'),
388 'flags' : [ '-DCONFIG_NICNATSEMI=1' ],
389 'default' : false, # not complete nor tested
390 },
391 'nicrealtek' : {
392 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200393 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200394 'deps' : [ libpci ],
395 'groups' : [ group_pci, group_internal ],
396 'srcs' : files('nicrealtek.c', 'pcidev.c'),
397 'flags' : [ '-DCONFIG_NICREALTEK=1' ],
398 },
399 'ogp_spi' : {
400 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200401 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200402 'deps' : [ libpci ],
403 'groups' : [ group_pci, group_internal ],
404 'srcs' : files('ogp_spi.c', 'pcidev.c'),
405 'flags' : [ '-DCONFIG_OGP_SPI=1' ],
406 },
407 'pickit2_spi' : {
408 'deps' : [ libusb1 ],
409 'groups' : [ group_usb, group_external ],
410 'srcs' : files('pickit2_spi.c'),
411 'flags' : [ '-DCONFIG_PICKIT2_SPI=1' ],
412 },
413 'pony_spi' : {
414 'systems' : systems_serial,
415 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100416 'srcs' : files('pony_spi.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200417 'flags' : [ '-DCONFIG_PONY_SPI=1' ],
418 },
419 'rayer_spi' : {
420 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200421 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200422 'groups' : [ group_internal ],
423 'srcs' : files('rayer_spi.c'),
424 'flags' : [ '-DCONFIG_RAYER_SPI=1' ],
425 },
426 'satamv' : {
427 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200428 'cpu_families' : [ cpus_port_io, cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200429 'deps' : [ libpci ],
430 'groups' : [ group_pci, group_internal ],
431 'srcs' : files('satamv.c', 'pcidev.c'),
432 'flags' : ['-DCONFIG_SATAMV=1'],
433 },
434 'satasii' : {
435 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200436 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200437 'deps' : [ libpci ],
438 'groups' : [ group_pci, group_internal ],
439 'srcs' : files('satasii.c', 'pcidev.c'),
440 'flags' : [ '-DCONFIG_SATASII=1' ],
441 },
Nico Huber47cea9a2026-06-30 21:42:23 +0200442 'scsilsi' : {
443 'systems' : systems_hwaccess,
444 'cpu_families' : [ cpus_raw_mem ],
445 'deps' : [ libpci ],
446 'groups' : [ group_pci, group_internal ],
447 'srcs' : files('scsilsi.c', 'pcidev.c'),
448 'flags' : [ '-DCONFIG_SCSILSI=1' ],
449 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200450 'serprog' : {
451 'systems' : systems_serial,
452 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100453 'srcs' : files('serprog.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200454 'flags' : [ '-DCONFIG_SERPROG=1' ],
455 },
456 'stlinkv3_spi' : {
457 'deps' : [ libusb1 ],
458 'groups' : [ group_usb, group_external ],
459 'srcs' : files('stlinkv3_spi.c', 'usbdev.c'),
460 'flags' : [ '-DCONFIG_STLINKV3_SPI=1' ],
461 },
462 'usbblaster_spi' : {
463 'deps' : [ libftdi1 ],
464 'groups' : [ group_ftdi, group_external ],
465 'srcs' : files('usbblaster_spi.c'),
466 'flags' : [ '-DCONFIG_USBBLASTER_SPI=1' ],
467 },
468}
469
470active_programmer_count = 0
471foreach p_name, p_data : programmer
472 p_data += {
473 'systems' : p_data.get('systems', ['all']),
474 'cpu_families' : p_data.get('cpu_families', ['all']),
475 'deps' : p_data.get('deps', []),
476 'groups' : p_data.get('groups', []),
477 'srcs' : p_data.get('srcs', []),
478 'flags' : p_data.get('flags', []),
479 'default' : p_data.get('default', true),
480 }
481
482 active = false
483 deps_found = true
484 not_found_dep = ''
485 not_active_message = ''
486 selected_hard = p_name in get_option('programmer')
487 selected_soft = p_data.get('groups').contains(true) or \
488 'all' in get_option('programmer') or \
489 'auto' in get_option('programmer') and p_data.get('default')
Nico Huber72c9e402024-04-21 13:07:17 +0200490
491 available = (p_data.get('systems') == ['all'] or p_data.get('systems').contains(host_machine.system()))
492 if p_data.get('cpu_families') != ['all']
493 foreach families_list : p_data.get('cpu_families')
494 available = available and families_list.contains(host_machine.cpu_family())
495 endforeach
496 endif
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200497
498 foreach dep : p_data.get('deps')
499 if not dep.found()
500 deps_found = false
501 not_found_dep = dep.name()
502 break
503 endif
504 endforeach
505
506 if selected_hard
507 if not available
508 error(p_name + ' selected but not supported on this platform')
509 elif not deps_found
510 error(p_name + ' selected but dependency ' + not_found_dep +'not found')
511 else
512 active = true
513 endif
514 elif selected_soft
515 if not available
516 not_active_message = 'Not available on platform'
517 elif not deps_found
518 not_active_message = 'dependency ' + not_found_dep + ' not found'
519 else
520 active = true
521 endif
522 else
523 not_active_message = 'not selected'
524 endif
525
526 p_data += {
527 'active' : active,
528 'summary' : not_active_message,
529 }
530 programmer += {p_name : p_data}
531 if active
532 active_programmer_count += 1
533 endif
534endforeach
535
536if active_programmer_count == 0
537 error('At least one programmer must be selected')
538endif
539
540# add srcs, cargs & deps from active programmer to global srcs, cargs & deps
541foreach p_name, p_data : programmer
542 if p_data.get('active')
543 srcs += p_data.get('srcs')
544 cargs += p_data.get('flags')
545 deps += p_data.get('deps')
546 endif
547endforeach
Thomas Heijligenb975da12022-08-13 12:10:05 +0200548
549if config_print_wiki.enabled()
550 if get_option('classic_cli').disabled()
551 error('`classic_cli_print_wiki` can not be enabled without `classic_cli`')
552 else
553 srcs += files('print_wiki.c')
554 cargs += '-DCONFIG_PRINT_WIKI=1'
555 endif
Thomas Heijligen2ae9bf22022-05-03 12:00:14 +0200556endif
557
Nico Hubere68b08b2023-02-11 00:00:54 +0100558cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME="' + config_default_programmer_name + '"'
Thomas Heijligen2ae9bf22022-05-03 12:00:14 +0200559cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
560
Richard Hughescb973682018-12-19 11:44:22 +0000561install_headers([
Nico Huberc3b02dc2023-08-12 01:13:45 +0200562 'include/libflashprog.h',
Richard Hughescb973682018-12-19 11:44:22 +0000563 ],
564)
565
Thomas Heijligen58015c22022-04-14 13:50:55 +0200566include_dir = include_directories('include')
567
Nico Huberc3b02dc2023-08-12 01:13:45 +0200568mapfile = 'libflashprog.map'
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200569if host_machine.system() == 'darwin'
570 vflag = ''
571else
572 vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
573endif
Nico Huberc3b02dc2023-08-12 01:13:45 +0200574libflashprog = both_libraries(
575 'flashprog',
Richard Hughescb973682018-12-19 11:44:22 +0000576 sources : [
577 srcs,
578 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200579 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000580 soversion : lt_current,
581 version : lt_version,
582 dependencies : [
583 deps,
584 ],
585 c_args : [
586 cargs,
587 ],
588 install : true,
589 link_args : vflag,
590 link_depends : mapfile,
591)
592
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500593version = meson.project_version()
594#strip leading characters
595if version.startswith('v')
596 version = version.split('v')[1]
597endif
598if version.startswith('p')
599 version = version.split('p')[1]
600endif
601
Richard Hughescb973682018-12-19 11:44:22 +0000602pkgg = import('pkgconfig')
603pkgg.generate(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200604 libraries : libflashprog,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500605 version : version,
Nico Huberc3b02dc2023-08-12 01:13:45 +0200606 name : 'flashprog',
607 filebase : 'flashprog',
608 description : 'library to interact with flashprog',
Richard Hughescb973682018-12-19 11:44:22 +0000609)
610
Nico Huber9d09e0f2025-03-02 22:55:10 +0100611config_data = configuration_data()
612config_data.set('VERSION', meson.project_version())
613config_data.set('MAN_DATE', run_command('util/getversion.sh', '--man-date', check : true).stdout().strip())
614
615configure_file(
616 input : 'include/version.h.in',
617 output : 'version.h',
618 configuration : config_data,
619)
620
Nico Huber8f7122c2023-02-11 18:28:33 +0100621foreach man : [ 'flashprog.8', 'flashprog-config.8', 'flashprog-write-protect.8' ]
Nico Huber1f693db2023-02-11 18:28:33 +0100622 configure_file(
623 input : man + '.tmpl',
624 output : man,
Nico Huber9d09e0f2025-03-02 22:55:10 +0100625 configuration : config_data,
Nico Huber1f693db2023-02-11 18:28:33 +0100626 install: true,
627 install_dir: join_paths(get_option('mandir'), 'man8'),
628 )
629endforeach
Richard Hughesdad3a162020-02-17 09:57:01 +0000630
Thomas Heijligena12e0102022-08-13 12:42:05 +0200631if get_option('classic_cli').auto() or get_option('classic_cli').enabled()
632 executable(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200633 'flashprog',
Thomas Heijligena12e0102022-08-13 12:42:05 +0200634 files(
Nico Hubera7050432023-02-11 18:01:26 +0100635 'cli.c',
Nico Huber1f693db2023-02-11 18:28:33 +0100636 'cli_config.c',
Nico Huber8f7122c2023-02-11 18:28:33 +0100637 'cli_wp.c',
Thomas Heijligena12e0102022-08-13 12:42:05 +0200638 'cli_classic.c',
639 'cli_common.c',
640 'cli_output.c',
641 ),
642 c_args : cargs,
643 include_directories : include_dir,
644 install : true,
Nico Huber63d30a22024-11-01 14:18:30 +0100645 install_dir : get_option('bindir'),
Nico Huberc3b02dc2023-08-12 01:13:45 +0200646 link_with : libflashprog.get_static_lib(), # flashprog needs internal symbols of libflashprog
Thomas Heijligena12e0102022-08-13 12:42:05 +0200647 )
648endif
Richard Hughescb973682018-12-19 11:44:22 +0000649
Thomas Heijligenb7341b12022-08-13 12:21:44 +0200650if get_option('ich_descriptors_tool').auto() or get_option('ich_descriptors_tool').enabled()
651 subdir('util/ich_descriptors_tool')
652endif
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200653
654programmer_names_active = []
655programmer_names_not_active = []
656foreach p_name, p_data : programmer
657 if p_data.get('active')
658 programmer_names_active += p_name
659 else
660 programmer_names_not_active += p_name + ' (' + p_data.get('summary', '') + ')'
661 endif
662endforeach
663
Jakob Haufefbba4542024-10-23 20:45:08 +0200664subdir('util')
665
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200666summary({
667 'active' : [programmer_names_active],
668 'non active' : [programmer_names_not_active],
669}, section : 'Programmer')