blob: 5365d2ced618cc862c97cc8f6149957f6a3b4e48 [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',
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',
10 'debug=false'],
Richard Hughescb973682018-12-19 11:44:22 +000011)
12
13# libtool versioning
14lt_current = '1'
15lt_revision = '0'
16lt_age = '0'
17lt_version = '@0@.@1@.@2@'.format(lt_current, lt_age, lt_revision)
18
Jacob Garber4a84ec22019-07-25 19:12:31 -060019# hide/enable some warnings
Richard Hughescb973682018-12-19 11:44:22 +000020warning_flags = [
Anastasia Klimchukcde70112021-10-25 13:20:26 +110021 '-Wshadow',
22 '-Wmissing-prototypes',
Jacob Garber4a84ec22019-07-25 19:12:31 -060023 '-Wwrite-strings',
Richard Hughescb973682018-12-19 11:44:22 +000024 '-Wno-unused-parameter',
Richard Hughescb973682018-12-19 11:44:22 +000025 '-Wno-address-of-packed-member',
26 '-Wno-enum-conversion',
Richard Hughescb973682018-12-19 11:44:22 +000027 '-Wno-missing-braces',
28]
29
30conf = configuration_data()
31
32cc = meson.get_compiler('c')
33add_project_arguments(cc.get_supported_arguments(warning_flags), language : 'c')
34add_project_arguments('-D_DEFAULT_SOURCE', language : 'c')
Rosen Penev566193f2020-07-18 12:50:16 -070035add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c') # required for fileno, nanosleep, and strndup
Richard Hughescb973682018-12-19 11:44:22 +000036add_project_arguments('-D_BSD_SOURCE', language : 'c') # required for glibc < v2.19
37add_project_arguments('-DFLASHROM_VERSION="' + meson.project_version() + '"', language : 'c')
38
39# get defaults from configure
40config_atahpt = get_option('config_atahpt')
41config_atapromise = get_option('config_atapromise')
42config_atavia = get_option('config_atavia')
43config_buspirate_spi = get_option('config_buspirate_spi')
44config_ch341a_spi = get_option('config_ch341a_spi')
45config_dediprog = get_option('config_dediprog')
46config_developerbox_spi = get_option('config_developerbox_spi')
47config_digilent_spi = get_option('config_digilent_spi')
Jean THOMASe28d8e42022-10-11 17:54:30 +020048config_dirtyjtag_spi = get_option('config_dirtyjtag_spi')
Richard Hughescb973682018-12-19 11:44:22 +000049config_drkaiser = get_option('config_drkaiser')
50config_dummy = get_option('config_dummy')
51config_ft2232_spi = get_option('config_ft2232_spi')
52config_gfxnvidia = get_option('config_gfxnvidia')
53config_internal = get_option('config_internal')
54config_it8212 = get_option('config_it8212')
Marc Schink7ec2d632020-12-08 22:20:50 +010055config_jlink_spi = get_option('config_jlink_spi')
Richard Hughescb973682018-12-19 11:44:22 +000056config_linux_mtd = get_option('config_linux_mtd')
57config_linux_spi = get_option('config_linux_spi')
58config_mstarddc_spi = get_option('config_mstarddc_spi')
59config_nic3com = get_option('config_nic3com')
60config_nicintel_eeprom = get_option('config_nicintel_eeprom')
61config_nicintel = get_option('config_nicintel')
62config_nicintel_spi = get_option('config_nicintel_spi')
63config_nicnatsemi = get_option('config_nicnatsemi')
64config_nicrealtek = get_option('config_nicrealtek')
65config_ogp_spi = get_option('config_ogp_spi')
66config_pickit2_spi = get_option('config_pickit2_spi')
67config_pony_spi = get_option('config_pony_spi')
68config_rayer_spi = get_option('config_rayer_spi')
69config_satamv = get_option('config_satamv')
70config_satasii = get_option('config_satasii')
71config_serprog = get_option('config_serprog')
72config_usbblaster_spi = get_option('config_usbblaster_spi')
Miklós Márton324929c2019-08-01 19:14:10 +020073config_stlinkv3_spi = get_option('config_stlinkv3_spi')
Thomas Heijligen84e9c912021-06-01 16:22:14 +020074config_default_programmer_name = get_option('default_programmer_name')
75config_default_programmer_args = get_option('default_programmer_args')
Daniel Campellof7a84fd2021-03-16 17:17:14 -060076config_print_wiki= get_option('print_wiki')
Richard Hughescb973682018-12-19 11:44:22 +000077
78cargs = []
79deps = []
Thomas Heijligen51208f32022-04-28 11:07:29 +020080srcs = files(
81 '82802ab.c',
82 'at45db.c',
83 'bitbang_spi.c',
84 'edi.c',
85 'en29lv640b.c',
86 'flashchips.c',
87 'flashrom.c',
88 'fmap.c',
89 'helpers.c',
90 'ich_descriptors.c',
91 'jedec.c',
92 'layout.c',
93 'libflashrom.c',
94 'opaque.c',
95 'print.c',
96 'programmer.c',
97 'programmer_table.c',
98 'sfdp.c',
99 'spi25.c',
100 'spi25_statusreg.c',
101 'spi95.c',
102 'spi.c',
103 'sst28sf040.c',
104 'sst49lfxxxc.c',
105 'sst_fwhub.c',
106 'stm50.c',
107 'udelay.c',
108 'w29ee011.c',
109 'w39.c',
110 'writeprotect.c',
111 'writeprotect_ranges.c',
112)
Richard Hughescb973682018-12-19 11:44:22 +0000113
Peter Marheine306c8b72022-01-21 02:07:30 +0000114host_is_x86 = ['x86', 'x86_64'].contains(host_machine.cpu_family())
115
116need_serial = [
117 config_buspirate_spi, config_pony_spi, config_serprog,
118].contains(true)
119need_bitbang_spi = [
120 config_internal, config_nicintel_spi, config_ogp_spi,
121 config_pony_spi, config_rayer_spi,
122].contains(true)
123need_raw_mem_access = [
124 config_atapromise, config_drkaiser, config_gfxnvidia, config_internal,
125 config_it8212, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
126 config_ogp_spi, config_satamv, config_satasii,
127].contains(true)
128# Internal programmer uses x86 features if the system is x86
129need_x86_msr = config_internal and host_is_x86
130need_x86_port_io = [
131 config_atahpt, config_atapromise, config_internal and host_is_x86,
132 config_nic3com, config_nicnatsemi, config_nicrealtek, config_rayer_spi,
133 config_satamv,
134].contains(true)
135need_libpci = [
136 config_atahpt, config_atapromise, config_atavia,
137 config_drkaiser, config_gfxnvidia, config_internal, config_it8212,
138 config_nic3com, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
139 config_nicnatsemi, config_nicrealtek, config_ogp_spi, config_satamv,
140 config_satasii,
141].contains(true)
142need_libusb1 = [
143 config_ch341a_spi, config_dediprog, config_developerbox_spi,
144 config_digilent_spi, config_dirtyjtag_spi, config_pickit2_spi,
145 config_stlinkv3_spi,
146].contains(true)
147need_libftdi1 = [
148 config_ft2232_spi, config_usbblaster_spi,
149].contains(true)
150need_libjaylink = config_jlink_spi
151
152if (need_x86_port_io or need_x86_msr) and not host_is_x86
153 error('one or more enabled programmer only supports x86 and target is not')
154endif
155
Richard Hughescb973682018-12-19 11:44:22 +0000156
157# check for required symbols
158if cc.has_function('clock_gettime')
159 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
160endif
161if cc.has_function('strnlen')
162 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
163endif
164if cc.check_header('sys/utsname.h')
165 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
166endif
Thomas Heijligenc02b1a92022-04-25 14:54:10 +0200167if host_machine.system() in ['cygwin', 'windows']
168 add_project_arguments('-DIS_WINDOWS=1', language : 'c')
169else
170 add_project_arguments('-DIS_WINDOWS=0', language : 'c')
171endif
Richard Hughescb973682018-12-19 11:44:22 +0000172
Thomas Heijligen5194d582022-02-19 22:31:32 +0100173srcs += 'platform/memaccess.c'
174
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100175if host_machine.endian() == 'little'
Thomas Heijligenc92f94b2022-03-17 13:41:17 +0100176 srcs += 'platform/endian_little.c'
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100177 add_project_arguments('-D__FLASHROM_LITTLE_ENDIAN__=1', language : 'c')
178endif
179if host_machine.endian() == 'big'
Thomas Heijligenc92f94b2022-03-17 13:41:17 +0100180 srcs += 'platform/endian_big.c'
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100181 add_project_arguments('-D__FLASHROM_BIG_ENDIAN__=1', language : 'c')
182endif
183
Richard Hughescb973682018-12-19 11:44:22 +0000184# some programmers require libusb
185if get_option('usb')
186 srcs += 'usbdev.c'
187 deps += dependency('libusb-1.0')
Peter Marheine306c8b72022-01-21 02:07:30 +0000188elif need_libusb1
189 error('usb is disabled but one or more enabled programmer requires USB access')
Richard Hughescb973682018-12-19 11:44:22 +0000190endif
191
192# some programmers require libpci
193if get_option('pciutils')
194 srcs += 'pcidev.c'
195 deps += dependency('libpci')
Peter Marheine306c8b72022-01-21 02:07:30 +0000196elif need_libpci
197 error('pciutils is disabled but one or more enabled programmer requires PCI access')
198endif
199
200if need_libftdi1
201 deps += dependency('libftdi1')
202endif
203
204if need_libjaylink
205 deps += dependency('libjaylink')
Richard Hughescb973682018-12-19 11:44:22 +0000206endif
207
208# set defines for configured programmers
209if config_atahpt
210 srcs += 'atahpt.c'
211 cargs += '-DCONFIG_ATAHPT=1'
212endif
213if config_atapromise
214 srcs += 'atapromise.c'
215 cargs += '-DCONFIG_ATAPROMISE=1'
216endif
217if config_atavia
218 srcs += 'atavia.c'
219 cargs += '-DCONFIG_ATAVIA=1'
220endif
221if config_buspirate_spi
222 srcs += 'buspirate_spi.c'
223 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000224endif
225if config_ch341a_spi
226 srcs += 'ch341a_spi.c'
227 cargs += '-DCONFIG_CH341A_SPI=1'
228endif
229if config_dediprog
230 srcs += 'dediprog.c'
231 cargs += '-DCONFIG_DEDIPROG=1'
232endif
233if config_developerbox_spi
234 srcs += 'developerbox_spi.c'
235 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
236endif
237if config_digilent_spi
238 srcs += 'digilent_spi.c'
239 cargs += '-DCONFIG_DIGILENT_SPI=1'
240endif
Jean THOMASe28d8e42022-10-11 17:54:30 +0200241if config_dirtyjtag_spi
242 srcs += 'dirtyjtag_spi.c'
243 cargs += '-DCONFIG_DIRTYJTAG_SPI=1'
244endif
Richard Hughescb973682018-12-19 11:44:22 +0000245if config_drkaiser
246 srcs += 'drkaiser.c'
247 cargs += '-DCONFIG_DRKAISER=1'
248endif
249if config_dummy
250 srcs += 'dummyflasher.c'
251 cargs += '-DCONFIG_DUMMY=1'
252endif
253if config_ft2232_spi
254 srcs += 'ft2232_spi.c'
255 cargs += '-DCONFIG_FT2232_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000256 cargs += '-DHAVE_FT232H=1'
257endif
258if config_gfxnvidia
259 srcs += 'gfxnvidia.c'
260 cargs += '-DCONFIG_GFXNVIDIA=1'
261endif
262if config_internal
263 srcs += 'board_enable.c'
264 srcs += 'cbtable.c'
265 srcs += 'chipset_enable.c'
266 srcs += 'internal.c'
267 srcs += 'processor_enable.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000268 if host_is_x86
Richard Hughescb973682018-12-19 11:44:22 +0000269 srcs += 'amd_imc.c'
270 srcs += 'dmi.c'
271 srcs += 'ichspi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000272 srcs += 'it87spi.c'
273 srcs += 'mcp6x_spi.c'
274 srcs += 'sb600spi.c'
275 srcs += 'wbsio_spi.c'
276 endif
Richard Hughescb973682018-12-19 11:44:22 +0000277 cargs += '-DCONFIG_INTERNAL=1'
278 if get_option('config_internal_dmi')
279 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
280 cargs += '-DCONFIG_INTERNAL_DMI=1'
281 endif
282endif
283if config_it8212
284 srcs += 'it8212.c'
285 cargs += '-DCONFIG_IT8212=1'
286endif
Marc Schink7ec2d632020-12-08 22:20:50 +0100287if config_jlink_spi
288 srcs += 'jlink_spi.c'
289 cargs += '-DCONFIG_JLINK_SPI=1'
Marc Schink7ec2d632020-12-08 22:20:50 +0100290endif
Richard Hughescb973682018-12-19 11:44:22 +0000291if config_linux_mtd
292 srcs += 'linux_mtd.c'
293 cargs += '-DCONFIG_LINUX_MTD=1'
294endif
295if config_linux_spi
296 srcs += 'linux_spi.c'
297 cargs += '-DCONFIG_LINUX_SPI=1'
298endif
299if config_mstarddc_spi
300 srcs += 'mstarddc_spi.c'
301 cargs += '-DCONFIG_MSTARDDC_SPI=1'
302endif
303if config_nic3com
304 srcs += 'nic3com.c'
305 cargs += '-DCONFIG_NIC3COM=1'
306endif
307if config_nicintel
308 srcs += 'nicintel.c'
309 cargs += '-DCONFIG_NICINTEL=1'
310endif
311if config_nicintel_eeprom
312 srcs += 'nicintel_eeprom.c'
313 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
314endif
315if config_nicintel_spi
316 srcs += 'nicintel_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000317 cargs += '-DCONFIG_NICINTEL_SPI=1'
318endif
319if config_nicnatsemi
320 srcs += 'nicnatsemi.c'
321 cargs += '-DCONFIG_NICNATSEMI=1'
322endif
323if config_nicrealtek
324 srcs += 'nicrealtek.c'
325 cargs += '-DCONFIG_NICREALTEK=1'
326endif
327if config_ogp_spi
Richard Hughescb973682018-12-19 11:44:22 +0000328 srcs += 'ogp_spi.c'
329 cargs += '-DCONFIG_OGP_SPI=1'
330endif
331if config_pickit2_spi
332 srcs += 'pickit2_spi.c'
333 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000334endif
335if config_pony_spi
336 srcs += 'pony_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000337 cargs += '-DCONFIG_PONY_SPI=1'
338endif
339if config_rayer_spi
340 srcs += 'rayer_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000341 cargs += '-DCONFIG_RAYER_SPI=1'
342endif
343if config_satamv
344 srcs += 'satamv.c'
345 cargs += '-DCONFIG_SATAMV=1'
346endif
347if config_satasii
348 srcs += 'satasii.c'
349 cargs += '-DCONFIG_SATASII=1'
350endif
351if config_serprog
352 srcs += 'serprog.c'
353 cargs += '-DCONFIG_SERPROG=1'
Richard Hughescb973682018-12-19 11:44:22 +0000354endif
355if config_usbblaster_spi
356 srcs += 'usbblaster_spi.c'
357 cargs += '-DCONFIG_USBBLASTER_SPI=1'
358endif
Miklós Márton324929c2019-08-01 19:14:10 +0200359if config_stlinkv3_spi
360 srcs += 'stlinkv3_spi.c'
361 cargs += '-DCONFIG_STLINKV3_SPI=1'
362endif
Richard Hughescb973682018-12-19 11:44:22 +0000363
364# bitbanging SPI infrastructure
Peter Marheine306c8b72022-01-21 02:07:30 +0000365if need_bitbang_spi
Richard Hughescb973682018-12-19 11:44:22 +0000366 srcs += 'bitbang_spi.c'
367 cargs += '-DCONFIG_BITBANG_SPI=1'
368endif
369
Peter Marheine306c8b72022-01-21 02:07:30 +0000370if need_raw_mem_access
Thomas Heijligen74b4aa02021-12-14 17:52:30 +0100371 srcs += 'hwaccess_physmap.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000372endif
373
374if need_x86_port_io
375 srcs += 'hwaccess_x86_io.c'
Thomas Heijligena0655202021-12-14 16:36:05 +0100376 cargs += '-D__FLASHROM_HAVE_OUTB__=1'
Richard Hughescb973682018-12-19 11:44:22 +0000377endif
378
Peter Marheine306c8b72022-01-21 02:07:30 +0000379if need_x86_msr
380 srcs += 'hwaccess_x86_msr.c'
381endif
382
Richard Hughescb973682018-12-19 11:44:22 +0000383# raw serial IO
384if need_serial
Richard Hughescb973682018-12-19 11:44:22 +0000385 srcs += 'serial.c'
Thomas Heijligen140c1262021-09-27 15:12:26 +0200386 if host_machine.system() == 'linux'
387 srcs += 'custom_baud_linux.c'
388 else
389 srcs += 'custom_baud.c'
390 endif
Richard Hughescb973682018-12-19 11:44:22 +0000391endif
392
Richard Hughescb973682018-12-19 11:44:22 +0000393prefix = get_option('prefix')
394sbindir = join_paths(prefix, get_option('sbindir'))
395libdir = join_paths(prefix, get_option('libdir'))
Richard Hughesdad3a162020-02-17 09:57:01 +0000396mandir = join_paths(prefix, get_option('mandir'))
Richard Hughescb973682018-12-19 11:44:22 +0000397
398install_headers([
Thomas Heijligen58015c22022-04-14 13:50:55 +0200399 'include/libflashrom.h',
Richard Hughescb973682018-12-19 11:44:22 +0000400 ],
401)
402
Thomas Heijligen58015c22022-04-14 13:50:55 +0200403include_dir = include_directories('include')
404
Richard Hughescb973682018-12-19 11:44:22 +0000405mapfile = 'libflashrom.map'
406vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
Daniel Campello4bcc9a32021-03-17 18:03:28 -0600407flashrom = library(
Richard Hughescb973682018-12-19 11:44:22 +0000408 'flashrom',
409 sources : [
410 srcs,
411 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200412 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000413 soversion : lt_current,
414 version : lt_version,
415 dependencies : [
416 deps,
417 ],
418 c_args : [
419 cargs,
420 ],
421 install : true,
422 link_args : vflag,
423 link_depends : mapfile,
424)
425
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500426version = meson.project_version()
427#strip leading characters
428if version.startswith('v')
429 version = version.split('v')[1]
430endif
431if version.startswith('p')
432 version = version.split('p')[1]
433endif
434
Richard Hughescb973682018-12-19 11:44:22 +0000435pkgg = import('pkgconfig')
436pkgg.generate(
437 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500438 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500439 name : 'flashrom',
440 filebase : 'flashrom',
441 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000442)
443
Richard Hughesdad3a162020-02-17 09:57:01 +0000444conf.set('VERSION', version)
Samuel R. Messner21bcfa92022-02-17 06:17:31 +0100445conf.set('MAN_DATE', run_command('util/getversion.sh', '--man-date').stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000446configure_file(
447 input : 'flashrom.8.tmpl',
448 output : 'flashrom.8',
449 configuration : conf,
450 install: true,
451 install_dir: join_paths(mandir, 'man8'),
452)
453
Richard Hughescb973682018-12-19 11:44:22 +0000454flashrom_dep = declare_dependency(
455 link_with : flashrom,
Thomas Heijligen58015c22022-04-14 13:50:55 +0200456 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000457 dependencies : deps
458)
459
Thomas Heijligen84e9c912021-06-01 16:22:14 +0200460if config_default_programmer_name != ''
461 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
462else
463 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
464endif
465
466cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
467
Daniel Campellof7a84fd2021-03-16 17:17:14 -0600468if config_print_wiki
469 srcs += 'print_wiki.c'
470 cargs += '-DCONFIG_PRINT_WIKI=1'
471endif
472
Richard Hughescb973682018-12-19 11:44:22 +0000473# we can't just link_with libflashrom as we require all the internal symbols...
474executable(
475 'flashrom',
476 sources : [
477 srcs,
478 'cli_classic.c',
479 'cli_common.c',
480 'cli_output.c',
481 'flashrom.c',
482 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200483 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000484 dependencies : [
485 deps,
486 ],
487 c_args : [
488 cargs,
Richard Hughescb973682018-12-19 11:44:22 +0000489 ],
490 install : true,
491 install_dir : sbindir,
492)
493
494subdir('util')