blob: 2db7299c20e478ffc4ff6a000f9dfbf4bf2792ce [file] [log] [blame]
Richard Hughescb973682018-12-19 11:44:22 +00001project('flashromutils', 'c',
Samuel R. Messner21bcfa92022-02-17 06:17:31 +01002 version : run_command('util/getversion.sh', '--version').stdout().strip(),
Nico Huberb417c0c2019-09-24 22:12:40 +02003 license : 'GPL-2.0',
Angel Pons30649432021-01-26 10:21:46 +01004 meson_version : '>=0.50.0',
Richard Hughescb973682018-12-19 11:44:22 +00005 default_options : ['warning_level=2', 'c_std=c99'],
6)
7
8# libtool versioning
9lt_current = '1'
10lt_revision = '0'
11lt_age = '0'
12lt_version = '@0@.@1@.@2@'.format(lt_current, lt_age, lt_revision)
13
Jacob Garber4a84ec22019-07-25 19:12:31 -060014# hide/enable some warnings
Richard Hughescb973682018-12-19 11:44:22 +000015warning_flags = [
Anastasia Klimchukcde70112021-10-25 13:20:26 +110016 '-Wshadow',
17 '-Wmissing-prototypes',
Jacob Garber4a84ec22019-07-25 19:12:31 -060018 '-Wwrite-strings',
Richard Hughescb973682018-12-19 11:44:22 +000019 '-Wno-unused-parameter',
Richard Hughescb973682018-12-19 11:44:22 +000020 '-Wno-address-of-packed-member',
21 '-Wno-enum-conversion',
Richard Hughescb973682018-12-19 11:44:22 +000022 '-Wno-missing-braces',
23]
24
25conf = configuration_data()
26
27cc = meson.get_compiler('c')
28add_project_arguments(cc.get_supported_arguments(warning_flags), language : 'c')
29add_project_arguments('-D_DEFAULT_SOURCE', language : 'c')
Rosen Penev566193f2020-07-18 12:50:16 -070030add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c') # required for fileno, nanosleep, and strndup
Richard Hughescb973682018-12-19 11:44:22 +000031add_project_arguments('-D_BSD_SOURCE', language : 'c') # required for glibc < v2.19
32add_project_arguments('-DFLASHROM_VERSION="' + meson.project_version() + '"', language : 'c')
33
Thomas Heijligen847d94b2021-10-12 17:38:01 +020034if host_machine.system() in ['cygwin', 'windows']
35 add_project_arguments('-DIS_WINDOWS=1', language : 'c')
36else
37 add_project_arguments('-DIS_WINDOWS=0', language : 'c')
38endif
39
Richard Hughescb973682018-12-19 11:44:22 +000040# get defaults from configure
41config_atahpt = get_option('config_atahpt')
42config_atapromise = get_option('config_atapromise')
43config_atavia = get_option('config_atavia')
44config_buspirate_spi = get_option('config_buspirate_spi')
45config_ch341a_spi = get_option('config_ch341a_spi')
46config_dediprog = get_option('config_dediprog')
47config_developerbox_spi = get_option('config_developerbox_spi')
48config_digilent_spi = get_option('config_digilent_spi')
Jean THOMASe28d8e42022-10-11 17:54:30 +020049config_dirtyjtag_spi = get_option('config_dirtyjtag_spi')
Richard Hughescb973682018-12-19 11:44:22 +000050config_drkaiser = get_option('config_drkaiser')
51config_dummy = get_option('config_dummy')
52config_ft2232_spi = get_option('config_ft2232_spi')
53config_gfxnvidia = get_option('config_gfxnvidia')
54config_internal = get_option('config_internal')
55config_it8212 = get_option('config_it8212')
Marc Schink7ec2d632020-12-08 22:20:50 +010056config_jlink_spi = get_option('config_jlink_spi')
Richard Hughescb973682018-12-19 11:44:22 +000057config_linux_mtd = get_option('config_linux_mtd')
58config_linux_spi = get_option('config_linux_spi')
59config_mstarddc_spi = get_option('config_mstarddc_spi')
60config_nic3com = get_option('config_nic3com')
61config_nicintel_eeprom = get_option('config_nicintel_eeprom')
62config_nicintel = get_option('config_nicintel')
63config_nicintel_spi = get_option('config_nicintel_spi')
64config_nicnatsemi = get_option('config_nicnatsemi')
65config_nicrealtek = get_option('config_nicrealtek')
66config_ogp_spi = get_option('config_ogp_spi')
67config_pickit2_spi = get_option('config_pickit2_spi')
68config_pony_spi = get_option('config_pony_spi')
69config_rayer_spi = get_option('config_rayer_spi')
70config_satamv = get_option('config_satamv')
71config_satasii = get_option('config_satasii')
72config_serprog = get_option('config_serprog')
73config_usbblaster_spi = get_option('config_usbblaster_spi')
Miklós Márton324929c2019-08-01 19:14:10 +020074config_stlinkv3_spi = get_option('config_stlinkv3_spi')
Thomas Heijligen84e9c912021-06-01 16:22:14 +020075config_default_programmer_name = get_option('default_programmer_name')
76config_default_programmer_args = get_option('default_programmer_args')
Daniel Campellof7a84fd2021-03-16 17:17:14 -060077config_print_wiki= get_option('print_wiki')
Richard Hughescb973682018-12-19 11:44:22 +000078
79cargs = []
80deps = []
81srcs = []
82
Peter Marheine306c8b72022-01-21 02:07:30 +000083host_is_x86 = ['x86', 'x86_64'].contains(host_machine.cpu_family())
84
85need_serial = [
86 config_buspirate_spi, config_pony_spi, config_serprog,
87].contains(true)
88need_bitbang_spi = [
89 config_internal, config_nicintel_spi, config_ogp_spi,
90 config_pony_spi, config_rayer_spi,
91].contains(true)
92need_raw_mem_access = [
93 config_atapromise, config_drkaiser, config_gfxnvidia, config_internal,
94 config_it8212, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
95 config_ogp_spi, config_satamv, config_satasii,
96].contains(true)
97# Internal programmer uses x86 features if the system is x86
98need_x86_msr = config_internal and host_is_x86
99need_x86_port_io = [
100 config_atahpt, config_atapromise, config_internal and host_is_x86,
101 config_nic3com, config_nicnatsemi, config_nicrealtek, config_rayer_spi,
102 config_satamv,
103].contains(true)
104need_libpci = [
105 config_atahpt, config_atapromise, config_atavia,
106 config_drkaiser, config_gfxnvidia, config_internal, config_it8212,
107 config_nic3com, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
108 config_nicnatsemi, config_nicrealtek, config_ogp_spi, config_satamv,
109 config_satasii,
110].contains(true)
111need_libusb1 = [
112 config_ch341a_spi, config_dediprog, config_developerbox_spi,
113 config_digilent_spi, config_dirtyjtag_spi, config_pickit2_spi,
114 config_stlinkv3_spi,
115].contains(true)
116need_libftdi1 = [
117 config_ft2232_spi, config_usbblaster_spi,
118].contains(true)
119need_libjaylink = config_jlink_spi
120
121if (need_x86_port_io or need_x86_msr) and not host_is_x86
122 error('one or more enabled programmer only supports x86 and target is not')
123endif
124
Richard Hughescb973682018-12-19 11:44:22 +0000125
126# check for required symbols
127if cc.has_function('clock_gettime')
128 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
129endif
130if cc.has_function('strnlen')
131 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
132endif
133if cc.check_header('sys/utsname.h')
134 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
135endif
136
Thomas Heijligen5194d582022-02-19 22:31:32 +0100137srcs += 'platform/memaccess.c'
138
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100139if host_machine.endian() == 'little'
Thomas Heijligenc92f94b2022-03-17 13:41:17 +0100140 srcs += 'platform/endian_little.c'
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100141 add_project_arguments('-D__FLASHROM_LITTLE_ENDIAN__=1', language : 'c')
142endif
143if host_machine.endian() == 'big'
Thomas Heijligenc92f94b2022-03-17 13:41:17 +0100144 srcs += 'platform/endian_big.c'
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100145 add_project_arguments('-D__FLASHROM_BIG_ENDIAN__=1', language : 'c')
146endif
147
Richard Hughescb973682018-12-19 11:44:22 +0000148# some programmers require libusb
149if get_option('usb')
150 srcs += 'usbdev.c'
151 deps += dependency('libusb-1.0')
Peter Marheine306c8b72022-01-21 02:07:30 +0000152elif need_libusb1
153 error('usb is disabled but one or more enabled programmer requires USB access')
Richard Hughescb973682018-12-19 11:44:22 +0000154endif
155
156# some programmers require libpci
157if get_option('pciutils')
158 srcs += 'pcidev.c'
159 deps += dependency('libpci')
Peter Marheine306c8b72022-01-21 02:07:30 +0000160elif need_libpci
161 error('pciutils is disabled but one or more enabled programmer requires PCI access')
162endif
163
164if need_libftdi1
165 deps += dependency('libftdi1')
166endif
167
168if need_libjaylink
169 deps += dependency('libjaylink')
Richard Hughescb973682018-12-19 11:44:22 +0000170endif
171
172# set defines for configured programmers
173if config_atahpt
174 srcs += 'atahpt.c'
175 cargs += '-DCONFIG_ATAHPT=1'
176endif
177if config_atapromise
178 srcs += 'atapromise.c'
179 cargs += '-DCONFIG_ATAPROMISE=1'
180endif
181if config_atavia
182 srcs += 'atavia.c'
183 cargs += '-DCONFIG_ATAVIA=1'
184endif
185if config_buspirate_spi
186 srcs += 'buspirate_spi.c'
187 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000188endif
189if config_ch341a_spi
190 srcs += 'ch341a_spi.c'
191 cargs += '-DCONFIG_CH341A_SPI=1'
192endif
193if config_dediprog
194 srcs += 'dediprog.c'
195 cargs += '-DCONFIG_DEDIPROG=1'
196endif
197if config_developerbox_spi
198 srcs += 'developerbox_spi.c'
199 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
200endif
201if config_digilent_spi
202 srcs += 'digilent_spi.c'
203 cargs += '-DCONFIG_DIGILENT_SPI=1'
204endif
Jean THOMASe28d8e42022-10-11 17:54:30 +0200205if config_dirtyjtag_spi
206 srcs += 'dirtyjtag_spi.c'
207 cargs += '-DCONFIG_DIRTYJTAG_SPI=1'
208endif
Richard Hughescb973682018-12-19 11:44:22 +0000209if config_drkaiser
210 srcs += 'drkaiser.c'
211 cargs += '-DCONFIG_DRKAISER=1'
212endif
213if config_dummy
214 srcs += 'dummyflasher.c'
215 cargs += '-DCONFIG_DUMMY=1'
216endif
217if config_ft2232_spi
218 srcs += 'ft2232_spi.c'
219 cargs += '-DCONFIG_FT2232_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000220 cargs += '-DHAVE_FT232H=1'
221endif
222if config_gfxnvidia
223 srcs += 'gfxnvidia.c'
224 cargs += '-DCONFIG_GFXNVIDIA=1'
225endif
226if config_internal
227 srcs += 'board_enable.c'
228 srcs += 'cbtable.c'
229 srcs += 'chipset_enable.c'
230 srcs += 'internal.c'
231 srcs += 'processor_enable.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000232 if host_is_x86
Richard Hughescb973682018-12-19 11:44:22 +0000233 srcs += 'amd_imc.c'
234 srcs += 'dmi.c'
235 srcs += 'ichspi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000236 srcs += 'it87spi.c'
237 srcs += 'mcp6x_spi.c'
238 srcs += 'sb600spi.c'
239 srcs += 'wbsio_spi.c'
240 endif
Richard Hughescb973682018-12-19 11:44:22 +0000241 cargs += '-DCONFIG_INTERNAL=1'
242 if get_option('config_internal_dmi')
243 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
244 cargs += '-DCONFIG_INTERNAL_DMI=1'
245 endif
246endif
247if config_it8212
248 srcs += 'it8212.c'
249 cargs += '-DCONFIG_IT8212=1'
250endif
Marc Schink7ec2d632020-12-08 22:20:50 +0100251if config_jlink_spi
252 srcs += 'jlink_spi.c'
253 cargs += '-DCONFIG_JLINK_SPI=1'
Marc Schink7ec2d632020-12-08 22:20:50 +0100254endif
Richard Hughescb973682018-12-19 11:44:22 +0000255if config_linux_mtd
256 srcs += 'linux_mtd.c'
257 cargs += '-DCONFIG_LINUX_MTD=1'
258endif
259if config_linux_spi
260 srcs += 'linux_spi.c'
261 cargs += '-DCONFIG_LINUX_SPI=1'
262endif
263if config_mstarddc_spi
264 srcs += 'mstarddc_spi.c'
265 cargs += '-DCONFIG_MSTARDDC_SPI=1'
266endif
267if config_nic3com
268 srcs += 'nic3com.c'
269 cargs += '-DCONFIG_NIC3COM=1'
270endif
271if config_nicintel
272 srcs += 'nicintel.c'
273 cargs += '-DCONFIG_NICINTEL=1'
274endif
275if config_nicintel_eeprom
276 srcs += 'nicintel_eeprom.c'
277 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
278endif
279if config_nicintel_spi
280 srcs += 'nicintel_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000281 cargs += '-DCONFIG_NICINTEL_SPI=1'
282endif
283if config_nicnatsemi
284 srcs += 'nicnatsemi.c'
285 cargs += '-DCONFIG_NICNATSEMI=1'
286endif
287if config_nicrealtek
288 srcs += 'nicrealtek.c'
289 cargs += '-DCONFIG_NICREALTEK=1'
290endif
291if config_ogp_spi
Richard Hughescb973682018-12-19 11:44:22 +0000292 srcs += 'ogp_spi.c'
293 cargs += '-DCONFIG_OGP_SPI=1'
294endif
295if config_pickit2_spi
296 srcs += 'pickit2_spi.c'
297 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000298endif
299if config_pony_spi
300 srcs += 'pony_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000301 cargs += '-DCONFIG_PONY_SPI=1'
302endif
303if config_rayer_spi
304 srcs += 'rayer_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000305 cargs += '-DCONFIG_RAYER_SPI=1'
306endif
307if config_satamv
308 srcs += 'satamv.c'
309 cargs += '-DCONFIG_SATAMV=1'
310endif
311if config_satasii
312 srcs += 'satasii.c'
313 cargs += '-DCONFIG_SATASII=1'
314endif
315if config_serprog
316 srcs += 'serprog.c'
317 cargs += '-DCONFIG_SERPROG=1'
Richard Hughescb973682018-12-19 11:44:22 +0000318endif
319if config_usbblaster_spi
320 srcs += 'usbblaster_spi.c'
321 cargs += '-DCONFIG_USBBLASTER_SPI=1'
322endif
Miklós Márton324929c2019-08-01 19:14:10 +0200323if config_stlinkv3_spi
324 srcs += 'stlinkv3_spi.c'
325 cargs += '-DCONFIG_STLINKV3_SPI=1'
326endif
Richard Hughescb973682018-12-19 11:44:22 +0000327
328# bitbanging SPI infrastructure
Peter Marheine306c8b72022-01-21 02:07:30 +0000329if need_bitbang_spi
Richard Hughescb973682018-12-19 11:44:22 +0000330 srcs += 'bitbang_spi.c'
331 cargs += '-DCONFIG_BITBANG_SPI=1'
332endif
333
Peter Marheine306c8b72022-01-21 02:07:30 +0000334if need_raw_mem_access
Thomas Heijligen74b4aa02021-12-14 17:52:30 +0100335 srcs += 'hwaccess_physmap.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000336endif
337
338if need_x86_port_io
339 srcs += 'hwaccess_x86_io.c'
Thomas Heijligena0655202021-12-14 16:36:05 +0100340 cargs += '-D__FLASHROM_HAVE_OUTB__=1'
Richard Hughescb973682018-12-19 11:44:22 +0000341endif
342
Peter Marheine306c8b72022-01-21 02:07:30 +0000343if need_x86_msr
344 srcs += 'hwaccess_x86_msr.c'
345endif
346
Richard Hughescb973682018-12-19 11:44:22 +0000347# raw serial IO
348if need_serial
Richard Hughescb973682018-12-19 11:44:22 +0000349 srcs += 'serial.c'
Thomas Heijligen140c1262021-09-27 15:12:26 +0200350 if host_machine.system() == 'linux'
351 srcs += 'custom_baud_linux.c'
352 else
353 srcs += 'custom_baud.c'
354 endif
Richard Hughescb973682018-12-19 11:44:22 +0000355endif
356
Richard Hughescb973682018-12-19 11:44:22 +0000357prefix = get_option('prefix')
358sbindir = join_paths(prefix, get_option('sbindir'))
359libdir = join_paths(prefix, get_option('libdir'))
Richard Hughesdad3a162020-02-17 09:57:01 +0000360mandir = join_paths(prefix, get_option('mandir'))
Richard Hughescb973682018-12-19 11:44:22 +0000361
362install_headers([
Thomas Heijligen58015c22022-04-14 13:50:55 +0200363 'include/libflashrom.h',
Richard Hughescb973682018-12-19 11:44:22 +0000364 ],
365)
366
Thomas Heijligen58015c22022-04-14 13:50:55 +0200367include_dir = include_directories('include')
368
Richard Hughescb973682018-12-19 11:44:22 +0000369# core modules needed by both the library and the CLI
370srcs += '82802ab.c'
371srcs += 'at45db.c'
372srcs += 'edi.c'
373srcs += 'en29lv640b.c'
374srcs += 'flashchips.c'
375srcs += 'flashrom.c'
376srcs += 'fmap.c'
377srcs += 'helpers.c'
378srcs += 'ich_descriptors.c'
379srcs += 'jedec.c'
380srcs += 'layout.c'
381srcs += 'libflashrom.c'
382srcs += 'opaque.c'
383srcs += 'print.c'
384srcs += 'programmer.c'
Thomas Heijligenbbfacff2021-03-31 20:40:01 +0200385srcs += 'programmer_table.c'
Richard Hughescb973682018-12-19 11:44:22 +0000386srcs += 'sfdp.c'
387srcs += 'spi25.c'
388srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700389srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000390srcs += 'spi.c'
391srcs += 'sst28sf040.c'
392srcs += 'sst49lfxxxc.c'
393srcs += 'sst_fwhub.c'
394srcs += 'stm50.c'
395srcs += 'udelay.c'
396srcs += 'w29ee011.c'
397srcs += 'w39.c'
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100398srcs += 'writeprotect.c'
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100399srcs += 'writeprotect_ranges.c'
Richard Hughescb973682018-12-19 11:44:22 +0000400
401mapfile = 'libflashrom.map'
402vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
Daniel Campello4bcc9a32021-03-17 18:03:28 -0600403flashrom = library(
Richard Hughescb973682018-12-19 11:44:22 +0000404 'flashrom',
405 sources : [
406 srcs,
407 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200408 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000409 soversion : lt_current,
410 version : lt_version,
411 dependencies : [
412 deps,
413 ],
414 c_args : [
415 cargs,
416 ],
417 install : true,
418 link_args : vflag,
419 link_depends : mapfile,
420)
421
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500422version = meson.project_version()
423#strip leading characters
424if version.startswith('v')
425 version = version.split('v')[1]
426endif
427if version.startswith('p')
428 version = version.split('p')[1]
429endif
430
Richard Hughescb973682018-12-19 11:44:22 +0000431pkgg = import('pkgconfig')
432pkgg.generate(
433 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500434 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500435 name : 'flashrom',
436 filebase : 'flashrom',
437 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000438)
439
Richard Hughesdad3a162020-02-17 09:57:01 +0000440conf.set('VERSION', version)
Samuel R. Messner21bcfa92022-02-17 06:17:31 +0100441conf.set('MAN_DATE', run_command('util/getversion.sh', '--man-date').stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000442configure_file(
443 input : 'flashrom.8.tmpl',
444 output : 'flashrom.8',
445 configuration : conf,
446 install: true,
447 install_dir: join_paths(mandir, 'man8'),
448)
449
Richard Hughescb973682018-12-19 11:44:22 +0000450flashrom_dep = declare_dependency(
451 link_with : flashrom,
Thomas Heijligen58015c22022-04-14 13:50:55 +0200452 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000453 dependencies : deps
454)
455
Thomas Heijligen84e9c912021-06-01 16:22:14 +0200456if config_default_programmer_name != ''
457 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
458else
459 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
460endif
461
462cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
463
Daniel Campellof7a84fd2021-03-16 17:17:14 -0600464if config_print_wiki
465 srcs += 'print_wiki.c'
466 cargs += '-DCONFIG_PRINT_WIKI=1'
467endif
468
Richard Hughescb973682018-12-19 11:44:22 +0000469# we can't just link_with libflashrom as we require all the internal symbols...
470executable(
471 'flashrom',
472 sources : [
473 srcs,
474 'cli_classic.c',
475 'cli_common.c',
476 'cli_output.c',
477 'flashrom.c',
478 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200479 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000480 dependencies : [
481 deps,
482 ],
483 c_args : [
484 cargs,
Richard Hughescb973682018-12-19 11:44:22 +0000485 ],
486 install : true,
487 install_dir : sbindir,
488)
489
490subdir('util')