blob: 2b40d52849895469657c0ceafbd537a02cf80e54 [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 Huber48d4a042026-03-08 16:07:28 +010063 'libflashprog/chips.c',
Nico Hubere7598392026-06-23 22:29:15 +020064 'm28f.c',
Nico Huber0e76d992023-01-12 20:22:55 +010065 'memory_bus.c',
Thomas Heijligen51208f32022-04-28 11:07:29 +020066 'opaque.c',
Edward O'Callaghan63f6a372022-08-12 12:56:43 +100067 'parallel.c',
Thomas Heijligen51208f32022-04-28 11:07:29 +020068 'print.c',
69 'programmer.c',
70 'programmer_table.c',
71 'sfdp.c',
72 'spi25.c',
Nico Huber8d0f4652024-05-04 18:52:51 +020073 'spi25_prepare.c',
Thomas Heijligen51208f32022-04-28 11:07:29 +020074 'spi25_statusreg.c',
75 'spi95.c',
76 'spi.c',
77 'sst28sf040.c',
78 'sst49lfxxxc.c',
79 'sst_fwhub.c',
80 'stm50.c',
81 'udelay.c',
82 'w29ee011.c',
83 'w39.c',
84 'writeprotect.c',
85 'writeprotect_ranges.c',
86)
Richard Hughescb973682018-12-19 11:44:22 +000087
Richard Hughescb973682018-12-19 11:44:22 +000088# check for required symbols
89if cc.has_function('clock_gettime')
90 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
91endif
92if cc.has_function('strnlen')
93 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
94endif
95if cc.check_header('sys/utsname.h')
96 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
97endif
Thomas Heijligenc02b1a92022-04-25 14:54:10 +020098if host_machine.system() in ['cygwin', 'windows']
99 add_project_arguments('-DIS_WINDOWS=1', language : 'c')
100else
101 add_project_arguments('-DIS_WINDOWS=0', language : 'c')
102endif
Richard Hughescb973682018-12-19 11:44:22 +0000103
Peter Stuge272b0732022-12-11 03:55:02 +0100104if host_machine.system() == 'linux'
105 custom_baud_c = 'custom_baud_linux.c'
Peter Stugeb8ee2d62022-12-11 16:20:16 +0100106elif host_machine.system() == 'darwin'
107 custom_baud_c = 'custom_baud_darwin.c'
Peter Stuge272b0732022-12-11 03:55:02 +0100108else
109 custom_baud_c = 'custom_baud.c'
110endif
111
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200112systems_hwaccess = [ 'linux', 'openbsd', 'freebsd', 'dragonfly', 'netbsd' ]
113systems_serial = [ 'linux', 'openbsd', 'freebsd', 'dragonfly', 'netbsd', 'darwin' ]
Richard Hughescb973682018-12-19 11:44:22 +0000114
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200115cpus_port_io = [ 'x86', 'x86_64' ]
Nico Huber72c9e402024-04-21 13:07:17 +0200116cpus_raw_mem = [ 'x86', 'x86_64', 'mips', 'mips64', 'ppc', 'ppc64', 'arm', 'aarch64', 'sparc', 'sparc64', 'arc', 'e2k' ]
Peter Marheine306c8b72022-01-21 02:07:30 +0000117
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200118group_ftdi = get_option('programmer').contains('group_ftdi')
119group_pci = get_option('programmer').contains('group_pci')
120group_usb = get_option('programmer').contains('group_usb')
121group_i2c = get_option('programmer').contains('group_i2c')
122group_serial = get_option('programmer').contains('group_serial')
123group_jlink = get_option('programmer').contains('group_jlink')
Steve Markgraf61899472023-01-09 23:06:52 +0100124group_gpiod = get_option('programmer').contains('group_gpiod')
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200125group_internal = get_option('programmer').contains('group_internal')
126group_external = get_option('programmer').contains('group_external')
Peter Marheine306c8b72022-01-21 02:07:30 +0000127
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200128libpci = 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
129libusb1 = dependency('libusb-1.0', required : group_usb)
130libftdi1 = dependency('libftdi1', required : group_ftdi)
131libjaylink = dependency('libjaylink', required : group_jlink)
Steve Markgraf61899472023-01-09 23:06:52 +0100132libgpiod = dependency('libgpiod', required : group_gpiod)
Richard Hughescb973682018-12-19 11:44:22 +0000133
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200134subdir('platform')
Richard Hughescb973682018-12-19 11:44:22 +0000135
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200136if systems_hwaccess.contains(host_machine.system())
Thomas Heijligen4bd966c2022-05-16 10:56:55 +0200137 srcs += files('hwaccess_physmap.c')
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200138 if ['x86', 'x86_64'].contains(host_machine.cpu_family())
Nico Huberc0f3f0f2026-03-14 21:18:52 +0100139 add_project_arguments('-DHAVE_OUTB=1', language : 'c')
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200140 srcs += files('hwaccess_x86_msr.c', 'hwaccess_x86_io.c')
Thomas Heijligen140c1262021-09-27 15:12:26 +0200141 endif
Richard Hughescb973682018-12-19 11:44:22 +0000142endif
143
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200144# Pseudo dependencies
145linux_headers = \
146 cc.has_header('linux/i2c.h') and \
147 cc.has_header('linux/i2c-dev.h') and \
148 cc.has_header('mtd/mtd-user.h') and \
149 cc.has_header('linux/spi/spidev.h') ? declare_dependency() : dependency('', required : false)
Thomas Heijligenb975da12022-08-13 12:10:05 +0200150
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200151# '<programmer_name>' : {
152# 'system' : list[string], # default: ['all']
153# 'cpu_families : list[string], # default: ['all']
154# 'deps' : list[dep], # default: []
155# 'groups : list[boolean], # default: []
156# 'srcs' : list[file], # default: []
157# 'flags' : list[string], # default: []
158# 'default' : boolean, # default: true
159# 'active' : boolean, # added on runtime
160# }
161programmer = {
162 'atahpt' : {
163 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200164 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200165 'deps' : [ libpci ],
166 'groups' : [ group_pci, group_internal ],
167 'srcs' : files('atahpt.c', 'pcidev.c'),
168 'flags' : [ '-DCONFIG_ATAHPT=1' ],
169 'default' : false, # not yet working
170 },
171 'atapromise' : {
172 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200173 'cpu_families' : [ cpus_port_io, cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200174 'deps' : [ libpci ],
175 'groups' : [ group_pci, group_internal ],
176 'srcs' : files('atapromise.c', 'pcidev.c'),
177 'flags' : [ '-DCONFIG_ATAPROMISE=1' ],
178 'default' : false,
179 },
180 'atavia' : {
181 'systems' : systems_hwaccess,
182 'deps' : [ libpci ],
183 'groups' : [ group_pci, group_internal ],
184 'srcs' : files('atavia.c', 'pcidev.c'),
185 'flags' : [ '-DCONFIG_ATAVIA=1' ],
186 },
187 'buspirate_spi' : {
188 'systems' : systems_serial,
189 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100190 'srcs' : files('buspirate_spi.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200191 'flags' : [ '-DCONFIG_BUSPIRATE_SPI=1' ],
192 },
193 'ch341a_spi' : {
194 'deps' : [ libusb1 ],
195 'groups' : [ group_usb, group_external ],
196 'srcs' : files('ch341a_spi.c'),
197 'flags' : [ '-DCONFIG_CH341A_SPI=1' ],
198 },
Nicholas Chin197b7c72022-10-23 13:10:31 -0600199 'ch347_spi' : {
200 'deps' : [ libusb1 ],
201 'groups' : [ group_usb, group_external ],
202 'srcs' : files('ch347_spi.c'),
203 'flags' : [ '-DCONFIG_CH347_SPI=1' ],
204 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200205 'dediprog' : {
206 'deps' : [ libusb1 ],
207 'groups' : [ group_usb, group_external ],
208 'srcs' : files('dediprog.c', 'usbdev.c'),
209 'flags' : [ '-DCONFIG_DEDIPROG=1' ],
210 },
211 'developerbox_spi' : {
212 'deps' : [ libusb1 ],
213 'groups' : [ group_usb, group_external ],
214 'srcs' : files('developerbox_spi.c', 'usbdev.c'),
215 'flags' : [ '-DCONFIG_DEVELOPERBOX_SPI=1' ],
216 },
217 'digilent_spi' : {
218 'deps' : [ libusb1 ],
219 'groups' : [ group_usb, group_external ],
220 'srcs' : files('digilent_spi.c'),
221 'flags' : [ '-DCONFIG_DIGILENT_SPI=1' ],
222 },
223 'dirtyjtag_spi' : {
224 'deps' : [ libusb1 ],
225 'groups' : [ group_usb, group_external ],
226 'srcs' : files('dirtyjtag_spi.c'),
227 'flags' : [ '-DCONFIG_DIRTYJTAG_SPI=1' ],
228 },
229 'drkaiser' : {
230 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200231 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200232 'deps' : [ libpci ],
233 'groups' : [ group_pci, group_internal ],
234 'srcs' : files('drkaiser.c', 'pcidev.c'),
235 'flags' : [ '-DCONFIG_DRKAISER=1' ],
236 },
237 'dummy' : {
238 'srcs' : files('dummyflasher.c'),
239 'flags' : [ '-DCONFIG_DUMMY=1' ],
240 },
241 'ft2232_spi' : {
242 'deps' : [ libftdi1 ],
243 'groups' : [ group_ftdi, group_external ],
244 'srcs' : files('ft2232_spi.c' ),
245 'flags' : [ '-DCONFIG_FT2232_SPI=1' ],
246 },
Nico Huber522160f2024-08-11 11:03:05 +0200247 'ft4222_spi' : {
248 'deps' : [ libusb1 ],
249 'groups' : [ group_usb, group_ftdi, group_external ],
250 'srcs' : files('ft4222_spi.c' ),
251 'flags' : [ '-DCONFIG_FT4222_SPI=1' ],
252 },
Nico Huber518350c2026-06-21 19:45:34 +0200253 'gfxmatrox' : {
254 'systems' : systems_hwaccess,
255 'cpu_families' : [ cpus_raw_mem ],
256 'deps' : [ libpci ],
257 'groups' : [ group_pci, group_internal ],
258 'srcs' : files('gfxmatrox.c', 'pcidev.c'),
259 'flags' : [ '-DCONFIG_GFXMATROX=1' ],
260 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200261 'gfxnvidia' : {
262 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200263 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200264 'deps' : [ libpci ],
265 'groups' : [ group_pci, group_internal ],
266 'srcs' : files('gfxnvidia.c', 'pcidev.c'),
267 'flags' : [ '-DCONFIG_GFXNVIDIA=1' ],
268 },
269 'internal' : {
270 'systems' : systems_hwaccess + ['linux'],
Nico Huber72c9e402024-04-21 13:07:17 +0200271 'cpu_families' : (host_machine.system() == 'linux' ? [ cpus_raw_mem ] : [ ['x86', 'x86_64'] ]),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200272 'deps' : [ libpci ],
273 'groups' : [ group_internal ],
274 'srcs' : (host_machine.cpu_family() in ['x86', 'x86_64'] ? files(
275 'processor_enable.c',
276 'chipset_enable.c',
277 'board_enable.c',
278 'cbtable.c',
279 'internal.c',
280 'it87spi.c',
281 'sb600spi.c',
282 'amd_imc.c',
Nico Hubera1939832025-10-07 21:58:02 +0000283 'amd_rom3read.c',
Nico Huber735b1862023-01-29 18:28:45 +0000284 'amd_spi100.c',
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200285 'wbsio_spi.c',
286 'mcp6x_spi.c',
287 'ichspi.c',
288 'dmi.c',
289 'pcidev.c',
290 'known_boards.c',
291 ) : files(
292 'board_enable.c',
293 'cbtable.c',
294 'chipset_enable.c',
295 'internal.c',
296 'processor_enable.c',
297 'pcidev.c',
298 'known_boards.c',
299 )),
300 'flags' : [
301 '-DCONFIG_INTERNAL=1',
302 '-DCONFIG_INTERNAL_DMI=' + (get_option('use_internal_dmi') ? '1' : '0'),
Nico Huber2f753792023-03-28 00:46:50 +0200303 '-DLINUX_MTD_AS_INTERNAL=' + (host_machine.cpu_family() in ['x86', 'x86_64'] ? '0' : '1'),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200304 ]
305 },
306 'it8212' : {
307 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200308 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200309 'deps' : [ libpci ],
310 'groups' : [ group_pci, group_internal ],
311 'srcs' : files('it8212.c', 'pcidev.c'),
312 'flags' : [ '-DCONFIG_IT8212=1' ],
313 },
314 'jlink_spi' : {
315 'deps' : [ libjaylink ],
316 'groups' : [ group_jlink, group_external ],
317 'srcs' : files('jlink_spi.c'),
318 'flags' : [ '-DCONFIG_JLINK_SPI=1' ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200319 },
Steve Markgraf61899472023-01-09 23:06:52 +0100320 'linux_gpio_spi' : {
321 'systems' : [ 'linux' ],
322 'deps' : [ libgpiod ],
323 'groups' : [ group_gpiod, group_external ],
Nico Huber8d2c0df2024-01-14 23:39:40 +0100324 'srcs' : libgpiod.version() < '2.0.0'
325 ? files('linux_gpio_spi.c')
326 : files('linux_gpio2_spi.c'),
Nico Huberaa5268d2023-03-09 17:15:23 +0100327 'flags' : [ '-DCONFIG_LINUX_GPIO_SPI=1' ],
Steve Markgraf61899472023-01-09 23:06:52 +0100328 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200329 'linux_mtd' : {
330 'systems' : [ 'linux' ],
331 'deps' : [ linux_headers ],
332 'groups' : [ group_internal ],
333 'srcs' : files('linux_mtd.c'),
334 'flags' : [ '-DCONFIG_LINUX_MTD=1' ],
335 },
336 'linux_spi' : {
337 'systems' : [ 'linux' ],
338 'deps' : [ linux_headers ],
339 # internal / external?
340 'srcs' : files('linux_spi.c'),
341 'flags' : [ '-DCONFIG_LINUX_SPI=1' ],
342 },
343 'mstarddc_spi' : {
344 'systems' : [ 'linux' ],
345 'deps' : [ linux_headers ],
346 'groups' : [ group_i2c ],
347 'srcs' : files('mstarddc_spi.c'),
348 'flags' : [ '-DCONFIG_MSTARDDC_SPI=1' ],
349 'default' : false
350 },
351 'nic3com' : {
352 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200353 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200354 'deps' : [ libpci ],
355 'groups' : [ group_pci, group_internal ],
356 'srcs' : files('nic3com.c', 'pcidev.c'),
357 'flags' : [ '-DCONFIG_NIC3COM=1' ],
358 },
Nico Huberdd4744e2026-03-22 15:47:25 +0100359 'nicamd' : {
360 'systems' : systems_hwaccess,
361 'cpu_families' : [ cpus_port_io ],
362 'deps' : [ libpci ],
363 'groups' : [ group_pci, group_internal ],
364 'srcs' : files('nicamd.c', 'pcidev.c'),
365 'flags' : [ '-DCONFIG_NICAMD=1' ],
366 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200367 'nicintel' : {
368 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200369 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200370 'deps' : [ libpci ],
371 'groups' : [ group_pci, group_internal ],
372 'srcs' : files('nicintel.c', 'pcidev.c'),
373 'flags' : [ '-DCONFIG_NICINTEL=1' ],
374 },
375 'nicintel_eeprom' : {
376 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200377 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200378 'deps' : [ libpci ],
379 'groups' : [ group_pci, group_internal ],
380 'srcs' : files('nicintel_eeprom.c', 'pcidev.c'),
381 'flags' : [ '-DCONFIG_NICINTEL_EEPROM=1' ],
382 },
383 'nicintel_spi' : {
384 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200385 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200386 'deps' : [ libpci ],
387 'groups' : [ group_pci, group_internal ],
388 'srcs' : files('nicintel_spi.c', 'pcidev.c'),
389 'flags' : [ '-DCONFIG_NICINTEL_SPI=1' ],
390 },
391 'nicnatsemi' : {
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('nicnatsemi.c', 'pcidev.c'),
397 'flags' : [ '-DCONFIG_NICNATSEMI=1' ],
398 'default' : false, # not complete nor tested
399 },
400 'nicrealtek' : {
401 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200402 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200403 'deps' : [ libpci ],
404 'groups' : [ group_pci, group_internal ],
405 'srcs' : files('nicrealtek.c', 'pcidev.c'),
406 'flags' : [ '-DCONFIG_NICREALTEK=1' ],
407 },
408 'ogp_spi' : {
409 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200410 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200411 'deps' : [ libpci ],
412 'groups' : [ group_pci, group_internal ],
413 'srcs' : files('ogp_spi.c', 'pcidev.c'),
414 'flags' : [ '-DCONFIG_OGP_SPI=1' ],
415 },
416 'pickit2_spi' : {
417 'deps' : [ libusb1 ],
418 'groups' : [ group_usb, group_external ],
419 'srcs' : files('pickit2_spi.c'),
420 'flags' : [ '-DCONFIG_PICKIT2_SPI=1' ],
421 },
422 'pony_spi' : {
423 'systems' : systems_serial,
424 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100425 'srcs' : files('pony_spi.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200426 'flags' : [ '-DCONFIG_PONY_SPI=1' ],
427 },
428 'rayer_spi' : {
429 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200430 'cpu_families' : [ cpus_port_io ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200431 'groups' : [ group_internal ],
432 'srcs' : files('rayer_spi.c'),
433 'flags' : [ '-DCONFIG_RAYER_SPI=1' ],
434 },
435 'satamv' : {
436 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200437 'cpu_families' : [ cpus_port_io, cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200438 'deps' : [ libpci ],
439 'groups' : [ group_pci, group_internal ],
440 'srcs' : files('satamv.c', 'pcidev.c'),
441 'flags' : ['-DCONFIG_SATAMV=1'],
442 },
443 'satasii' : {
444 'systems' : systems_hwaccess,
Nico Huber72c9e402024-04-21 13:07:17 +0200445 'cpu_families' : [ cpus_raw_mem ],
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200446 'deps' : [ libpci ],
447 'groups' : [ group_pci, group_internal ],
448 'srcs' : files('satasii.c', 'pcidev.c'),
449 'flags' : [ '-DCONFIG_SATASII=1' ],
450 },
Nico Huber47cea9a2026-06-30 21:42:23 +0200451 'scsilsi' : {
452 'systems' : systems_hwaccess,
453 'cpu_families' : [ cpus_raw_mem ],
454 'deps' : [ libpci ],
455 'groups' : [ group_pci, group_internal ],
456 'srcs' : files('scsilsi.c', 'pcidev.c'),
457 'flags' : [ '-DCONFIG_SCSILSI=1' ],
458 },
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200459 'serprog' : {
460 'systems' : systems_serial,
461 'groups' : [ group_serial, group_external ],
Peter Stuge272b0732022-12-11 03:55:02 +0100462 'srcs' : files('serprog.c', 'serial.c', custom_baud_c),
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200463 'flags' : [ '-DCONFIG_SERPROG=1' ],
464 },
465 'stlinkv3_spi' : {
466 'deps' : [ libusb1 ],
467 'groups' : [ group_usb, group_external ],
468 'srcs' : files('stlinkv3_spi.c', 'usbdev.c'),
469 'flags' : [ '-DCONFIG_STLINKV3_SPI=1' ],
470 },
471 'usbblaster_spi' : {
472 'deps' : [ libftdi1 ],
473 'groups' : [ group_ftdi, group_external ],
474 'srcs' : files('usbblaster_spi.c'),
475 'flags' : [ '-DCONFIG_USBBLASTER_SPI=1' ],
476 },
477}
478
479active_programmer_count = 0
480foreach p_name, p_data : programmer
481 p_data += {
482 'systems' : p_data.get('systems', ['all']),
483 'cpu_families' : p_data.get('cpu_families', ['all']),
484 'deps' : p_data.get('deps', []),
485 'groups' : p_data.get('groups', []),
486 'srcs' : p_data.get('srcs', []),
487 'flags' : p_data.get('flags', []),
488 'default' : p_data.get('default', true),
489 }
490
491 active = false
492 deps_found = true
493 not_found_dep = ''
494 not_active_message = ''
495 selected_hard = p_name in get_option('programmer')
496 selected_soft = p_data.get('groups').contains(true) or \
497 'all' in get_option('programmer') or \
498 'auto' in get_option('programmer') and p_data.get('default')
Nico Huber72c9e402024-04-21 13:07:17 +0200499
500 available = (p_data.get('systems') == ['all'] or p_data.get('systems').contains(host_machine.system()))
501 if p_data.get('cpu_families') != ['all']
502 foreach families_list : p_data.get('cpu_families')
503 available = available and families_list.contains(host_machine.cpu_family())
504 endforeach
505 endif
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200506
507 foreach dep : p_data.get('deps')
508 if not dep.found()
509 deps_found = false
510 not_found_dep = dep.name()
511 break
512 endif
513 endforeach
514
515 if selected_hard
516 if not available
517 error(p_name + ' selected but not supported on this platform')
518 elif not deps_found
519 error(p_name + ' selected but dependency ' + not_found_dep +'not found')
520 else
521 active = true
522 endif
523 elif selected_soft
524 if not available
525 not_active_message = 'Not available on platform'
526 elif not deps_found
527 not_active_message = 'dependency ' + not_found_dep + ' not found'
528 else
529 active = true
530 endif
531 else
532 not_active_message = 'not selected'
533 endif
534
535 p_data += {
536 'active' : active,
537 'summary' : not_active_message,
538 }
539 programmer += {p_name : p_data}
540 if active
541 active_programmer_count += 1
542 endif
543endforeach
544
545if active_programmer_count == 0
546 error('At least one programmer must be selected')
547endif
548
549# add srcs, cargs & deps from active programmer to global srcs, cargs & deps
550foreach p_name, p_data : programmer
551 if p_data.get('active')
552 srcs += p_data.get('srcs')
553 cargs += p_data.get('flags')
554 deps += p_data.get('deps')
555 endif
556endforeach
Thomas Heijligenb975da12022-08-13 12:10:05 +0200557
558if config_print_wiki.enabled()
559 if get_option('classic_cli').disabled()
560 error('`classic_cli_print_wiki` can not be enabled without `classic_cli`')
561 else
562 srcs += files('print_wiki.c')
563 cargs += '-DCONFIG_PRINT_WIKI=1'
564 endif
Thomas Heijligen2ae9bf22022-05-03 12:00:14 +0200565endif
566
Nico Hubere68b08b2023-02-11 00:00:54 +0100567cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME="' + config_default_programmer_name + '"'
Thomas Heijligen2ae9bf22022-05-03 12:00:14 +0200568cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
569
Richard Hughescb973682018-12-19 11:44:22 +0000570install_headers([
Nico Huberc3b02dc2023-08-12 01:13:45 +0200571 'include/libflashprog.h',
Richard Hughescb973682018-12-19 11:44:22 +0000572 ],
573)
574
Thomas Heijligen58015c22022-04-14 13:50:55 +0200575include_dir = include_directories('include')
576
Nico Huberc3b02dc2023-08-12 01:13:45 +0200577mapfile = 'libflashprog.map'
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200578if host_machine.system() == 'darwin'
579 vflag = ''
580else
581 vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
582endif
Nico Huberc3b02dc2023-08-12 01:13:45 +0200583libflashprog = both_libraries(
584 'flashprog',
Richard Hughescb973682018-12-19 11:44:22 +0000585 sources : [
586 srcs,
587 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200588 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000589 soversion : lt_current,
590 version : lt_version,
591 dependencies : [
592 deps,
593 ],
594 c_args : [
595 cargs,
596 ],
597 install : true,
598 link_args : vflag,
599 link_depends : mapfile,
600)
601
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500602version = meson.project_version()
603#strip leading characters
604if version.startswith('v')
605 version = version.split('v')[1]
606endif
607if version.startswith('p')
608 version = version.split('p')[1]
609endif
610
Richard Hughescb973682018-12-19 11:44:22 +0000611pkgg = import('pkgconfig')
612pkgg.generate(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200613 libraries : libflashprog,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500614 version : version,
Nico Huberc3b02dc2023-08-12 01:13:45 +0200615 name : 'flashprog',
616 filebase : 'flashprog',
617 description : 'library to interact with flashprog',
Richard Hughescb973682018-12-19 11:44:22 +0000618)
619
Nico Huber9d09e0f2025-03-02 22:55:10 +0100620config_data = configuration_data()
621config_data.set('VERSION', meson.project_version())
622config_data.set('MAN_DATE', run_command('util/getversion.sh', '--man-date', check : true).stdout().strip())
623
624configure_file(
625 input : 'include/version.h.in',
626 output : 'version.h',
627 configuration : config_data,
628)
629
Nico Huber8f7122c2023-02-11 18:28:33 +0100630foreach man : [ 'flashprog.8', 'flashprog-config.8', 'flashprog-write-protect.8' ]
Nico Huber1f693db2023-02-11 18:28:33 +0100631 configure_file(
632 input : man + '.tmpl',
633 output : man,
Nico Huber9d09e0f2025-03-02 22:55:10 +0100634 configuration : config_data,
Nico Huber1f693db2023-02-11 18:28:33 +0100635 install: true,
636 install_dir: join_paths(get_option('mandir'), 'man8'),
637 )
638endforeach
Richard Hughesdad3a162020-02-17 09:57:01 +0000639
Thomas Heijligena12e0102022-08-13 12:42:05 +0200640if get_option('classic_cli').auto() or get_option('classic_cli').enabled()
641 executable(
Nico Huberc3b02dc2023-08-12 01:13:45 +0200642 'flashprog',
Thomas Heijligena12e0102022-08-13 12:42:05 +0200643 files(
Nico Hubera7050432023-02-11 18:01:26 +0100644 'cli.c',
Nico Huber1f693db2023-02-11 18:28:33 +0100645 'cli_config.c',
Nico Huber8f7122c2023-02-11 18:28:33 +0100646 'cli_wp.c',
Thomas Heijligena12e0102022-08-13 12:42:05 +0200647 'cli_classic.c',
648 'cli_common.c',
649 'cli_output.c',
650 ),
651 c_args : cargs,
652 include_directories : include_dir,
653 install : true,
Nico Huber63d30a22024-11-01 14:18:30 +0100654 install_dir : get_option('bindir'),
Nico Huberc3b02dc2023-08-12 01:13:45 +0200655 link_with : libflashprog.get_static_lib(), # flashprog needs internal symbols of libflashprog
Thomas Heijligena12e0102022-08-13 12:42:05 +0200656 )
657endif
Richard Hughescb973682018-12-19 11:44:22 +0000658
Thomas Heijligenb7341b12022-08-13 12:21:44 +0200659if get_option('ich_descriptors_tool').auto() or get_option('ich_descriptors_tool').enabled()
660 subdir('util/ich_descriptors_tool')
661endif
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200662
663programmer_names_active = []
664programmer_names_not_active = []
665foreach p_name, p_data : programmer
666 if p_data.get('active')
667 programmer_names_active += p_name
668 else
669 programmer_names_not_active += p_name + ' (' + p_data.get('summary', '') + ')'
670 endif
671endforeach
672
Jakob Haufefbba4542024-10-23 20:45:08 +0200673subdir('util')
674
Thomas Heijligen3ecf0b62022-08-18 12:16:29 +0200675summary({
676 'active' : [programmer_names_active],
677 'non active' : [programmer_names_not_active],
678}, section : 'Programmer')