blob: 5399e92434b97ee81df099f09e6a0b5327b6ab84 [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
Thomas Heijligen328a64a2022-04-25 14:42:17 +0200114subdir('platform')
115
Peter Marheine306c8b72022-01-21 02:07:30 +0000116host_is_x86 = ['x86', 'x86_64'].contains(host_machine.cpu_family())
117
118need_serial = [
119 config_buspirate_spi, config_pony_spi, config_serprog,
120].contains(true)
121need_bitbang_spi = [
122 config_internal, config_nicintel_spi, config_ogp_spi,
123 config_pony_spi, config_rayer_spi,
124].contains(true)
125need_raw_mem_access = [
126 config_atapromise, config_drkaiser, config_gfxnvidia, config_internal,
127 config_it8212, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
128 config_ogp_spi, config_satamv, config_satasii,
129].contains(true)
130# Internal programmer uses x86 features if the system is x86
131need_x86_msr = config_internal and host_is_x86
132need_x86_port_io = [
133 config_atahpt, config_atapromise, config_internal and host_is_x86,
134 config_nic3com, config_nicnatsemi, config_nicrealtek, config_rayer_spi,
135 config_satamv,
136].contains(true)
137need_libpci = [
138 config_atahpt, config_atapromise, config_atavia,
139 config_drkaiser, config_gfxnvidia, config_internal, config_it8212,
140 config_nic3com, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
141 config_nicnatsemi, config_nicrealtek, config_ogp_spi, config_satamv,
142 config_satasii,
143].contains(true)
144need_libusb1 = [
145 config_ch341a_spi, config_dediprog, config_developerbox_spi,
146 config_digilent_spi, config_dirtyjtag_spi, config_pickit2_spi,
147 config_stlinkv3_spi,
148].contains(true)
149need_libftdi1 = [
150 config_ft2232_spi, config_usbblaster_spi,
151].contains(true)
152need_libjaylink = config_jlink_spi
153
154if (need_x86_port_io or need_x86_msr) and not host_is_x86
155 error('one or more enabled programmer only supports x86 and target is not')
156endif
157
Richard Hughescb973682018-12-19 11:44:22 +0000158
159# check for required symbols
160if cc.has_function('clock_gettime')
161 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
162endif
163if cc.has_function('strnlen')
164 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
165endif
166if cc.check_header('sys/utsname.h')
167 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
168endif
Thomas Heijligenc02b1a92022-04-25 14:54:10 +0200169if host_machine.system() in ['cygwin', 'windows']
170 add_project_arguments('-DIS_WINDOWS=1', language : 'c')
171else
172 add_project_arguments('-DIS_WINDOWS=0', language : 'c')
173endif
Richard Hughescb973682018-12-19 11:44:22 +0000174
175# some programmers require libusb
176if get_option('usb')
177 srcs += 'usbdev.c'
178 deps += dependency('libusb-1.0')
Peter Marheine306c8b72022-01-21 02:07:30 +0000179elif need_libusb1
180 error('usb is disabled but one or more enabled programmer requires USB access')
Richard Hughescb973682018-12-19 11:44:22 +0000181endif
182
183# some programmers require libpci
184if get_option('pciutils')
185 srcs += 'pcidev.c'
186 deps += dependency('libpci')
Peter Marheine306c8b72022-01-21 02:07:30 +0000187elif need_libpci
188 error('pciutils is disabled but one or more enabled programmer requires PCI access')
189endif
190
191if need_libftdi1
192 deps += dependency('libftdi1')
193endif
194
195if need_libjaylink
196 deps += dependency('libjaylink')
Richard Hughescb973682018-12-19 11:44:22 +0000197endif
198
199# set defines for configured programmers
200if config_atahpt
201 srcs += 'atahpt.c'
202 cargs += '-DCONFIG_ATAHPT=1'
203endif
204if config_atapromise
205 srcs += 'atapromise.c'
206 cargs += '-DCONFIG_ATAPROMISE=1'
207endif
208if config_atavia
209 srcs += 'atavia.c'
210 cargs += '-DCONFIG_ATAVIA=1'
211endif
212if config_buspirate_spi
213 srcs += 'buspirate_spi.c'
214 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000215endif
216if config_ch341a_spi
217 srcs += 'ch341a_spi.c'
218 cargs += '-DCONFIG_CH341A_SPI=1'
219endif
220if config_dediprog
221 srcs += 'dediprog.c'
222 cargs += '-DCONFIG_DEDIPROG=1'
223endif
224if config_developerbox_spi
225 srcs += 'developerbox_spi.c'
226 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
227endif
228if config_digilent_spi
229 srcs += 'digilent_spi.c'
230 cargs += '-DCONFIG_DIGILENT_SPI=1'
231endif
Jean THOMASe28d8e42022-10-11 17:54:30 +0200232if config_dirtyjtag_spi
233 srcs += 'dirtyjtag_spi.c'
234 cargs += '-DCONFIG_DIRTYJTAG_SPI=1'
235endif
Richard Hughescb973682018-12-19 11:44:22 +0000236if config_drkaiser
237 srcs += 'drkaiser.c'
238 cargs += '-DCONFIG_DRKAISER=1'
239endif
240if config_dummy
241 srcs += 'dummyflasher.c'
242 cargs += '-DCONFIG_DUMMY=1'
243endif
244if config_ft2232_spi
245 srcs += 'ft2232_spi.c'
246 cargs += '-DCONFIG_FT2232_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000247 cargs += '-DHAVE_FT232H=1'
248endif
249if config_gfxnvidia
250 srcs += 'gfxnvidia.c'
251 cargs += '-DCONFIG_GFXNVIDIA=1'
252endif
253if config_internal
254 srcs += 'board_enable.c'
255 srcs += 'cbtable.c'
256 srcs += 'chipset_enable.c'
257 srcs += 'internal.c'
258 srcs += 'processor_enable.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000259 if host_is_x86
Richard Hughescb973682018-12-19 11:44:22 +0000260 srcs += 'amd_imc.c'
261 srcs += 'dmi.c'
262 srcs += 'ichspi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000263 srcs += 'it87spi.c'
264 srcs += 'mcp6x_spi.c'
265 srcs += 'sb600spi.c'
266 srcs += 'wbsio_spi.c'
267 endif
Richard Hughescb973682018-12-19 11:44:22 +0000268 cargs += '-DCONFIG_INTERNAL=1'
269 if get_option('config_internal_dmi')
270 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
271 cargs += '-DCONFIG_INTERNAL_DMI=1'
272 endif
273endif
274if config_it8212
275 srcs += 'it8212.c'
276 cargs += '-DCONFIG_IT8212=1'
277endif
Marc Schink7ec2d632020-12-08 22:20:50 +0100278if config_jlink_spi
279 srcs += 'jlink_spi.c'
280 cargs += '-DCONFIG_JLINK_SPI=1'
Marc Schink7ec2d632020-12-08 22:20:50 +0100281endif
Richard Hughescb973682018-12-19 11:44:22 +0000282if config_linux_mtd
283 srcs += 'linux_mtd.c'
284 cargs += '-DCONFIG_LINUX_MTD=1'
285endif
286if config_linux_spi
287 srcs += 'linux_spi.c'
288 cargs += '-DCONFIG_LINUX_SPI=1'
289endif
290if config_mstarddc_spi
291 srcs += 'mstarddc_spi.c'
292 cargs += '-DCONFIG_MSTARDDC_SPI=1'
293endif
294if config_nic3com
295 srcs += 'nic3com.c'
296 cargs += '-DCONFIG_NIC3COM=1'
297endif
298if config_nicintel
299 srcs += 'nicintel.c'
300 cargs += '-DCONFIG_NICINTEL=1'
301endif
302if config_nicintel_eeprom
303 srcs += 'nicintel_eeprom.c'
304 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
305endif
306if config_nicintel_spi
307 srcs += 'nicintel_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000308 cargs += '-DCONFIG_NICINTEL_SPI=1'
309endif
310if config_nicnatsemi
311 srcs += 'nicnatsemi.c'
312 cargs += '-DCONFIG_NICNATSEMI=1'
313endif
314if config_nicrealtek
315 srcs += 'nicrealtek.c'
316 cargs += '-DCONFIG_NICREALTEK=1'
317endif
318if config_ogp_spi
Richard Hughescb973682018-12-19 11:44:22 +0000319 srcs += 'ogp_spi.c'
320 cargs += '-DCONFIG_OGP_SPI=1'
321endif
322if config_pickit2_spi
323 srcs += 'pickit2_spi.c'
324 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000325endif
326if config_pony_spi
327 srcs += 'pony_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000328 cargs += '-DCONFIG_PONY_SPI=1'
329endif
330if config_rayer_spi
331 srcs += 'rayer_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000332 cargs += '-DCONFIG_RAYER_SPI=1'
333endif
334if config_satamv
335 srcs += 'satamv.c'
336 cargs += '-DCONFIG_SATAMV=1'
337endif
338if config_satasii
339 srcs += 'satasii.c'
340 cargs += '-DCONFIG_SATASII=1'
341endif
342if config_serprog
343 srcs += 'serprog.c'
344 cargs += '-DCONFIG_SERPROG=1'
Richard Hughescb973682018-12-19 11:44:22 +0000345endif
346if config_usbblaster_spi
347 srcs += 'usbblaster_spi.c'
348 cargs += '-DCONFIG_USBBLASTER_SPI=1'
349endif
Miklós Márton324929c2019-08-01 19:14:10 +0200350if config_stlinkv3_spi
351 srcs += 'stlinkv3_spi.c'
352 cargs += '-DCONFIG_STLINKV3_SPI=1'
353endif
Richard Hughescb973682018-12-19 11:44:22 +0000354
355# bitbanging SPI infrastructure
Peter Marheine306c8b72022-01-21 02:07:30 +0000356if need_bitbang_spi
Richard Hughescb973682018-12-19 11:44:22 +0000357 srcs += 'bitbang_spi.c'
358 cargs += '-DCONFIG_BITBANG_SPI=1'
359endif
360
Peter Marheine306c8b72022-01-21 02:07:30 +0000361if need_raw_mem_access
Thomas Heijligen74b4aa02021-12-14 17:52:30 +0100362 srcs += 'hwaccess_physmap.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000363endif
364
365if need_x86_port_io
366 srcs += 'hwaccess_x86_io.c'
Thomas Heijligena0655202021-12-14 16:36:05 +0100367 cargs += '-D__FLASHROM_HAVE_OUTB__=1'
Richard Hughescb973682018-12-19 11:44:22 +0000368endif
369
Peter Marheine306c8b72022-01-21 02:07:30 +0000370if need_x86_msr
371 srcs += 'hwaccess_x86_msr.c'
372endif
373
Richard Hughescb973682018-12-19 11:44:22 +0000374# raw serial IO
375if need_serial
Richard Hughescb973682018-12-19 11:44:22 +0000376 srcs += 'serial.c'
Thomas Heijligen140c1262021-09-27 15:12:26 +0200377 if host_machine.system() == 'linux'
378 srcs += 'custom_baud_linux.c'
379 else
380 srcs += 'custom_baud.c'
381 endif
Richard Hughescb973682018-12-19 11:44:22 +0000382endif
383
Richard Hughescb973682018-12-19 11:44:22 +0000384install_headers([
Thomas Heijligen58015c22022-04-14 13:50:55 +0200385 'include/libflashrom.h',
Richard Hughescb973682018-12-19 11:44:22 +0000386 ],
387)
388
Thomas Heijligen58015c22022-04-14 13:50:55 +0200389include_dir = include_directories('include')
390
Richard Hughescb973682018-12-19 11:44:22 +0000391mapfile = 'libflashrom.map'
392vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
Daniel Campello4bcc9a32021-03-17 18:03:28 -0600393flashrom = library(
Richard Hughescb973682018-12-19 11:44:22 +0000394 'flashrom',
395 sources : [
396 srcs,
397 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200398 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000399 soversion : lt_current,
400 version : lt_version,
401 dependencies : [
402 deps,
403 ],
404 c_args : [
405 cargs,
406 ],
407 install : true,
408 link_args : vflag,
409 link_depends : mapfile,
410)
411
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500412version = meson.project_version()
413#strip leading characters
414if version.startswith('v')
415 version = version.split('v')[1]
416endif
417if version.startswith('p')
418 version = version.split('p')[1]
419endif
420
Richard Hughescb973682018-12-19 11:44:22 +0000421pkgg = import('pkgconfig')
422pkgg.generate(
423 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500424 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500425 name : 'flashrom',
426 filebase : 'flashrom',
427 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000428)
429
Richard Hughesdad3a162020-02-17 09:57:01 +0000430conf.set('VERSION', version)
Samuel R. Messner21bcfa92022-02-17 06:17:31 +0100431conf.set('MAN_DATE', run_command('util/getversion.sh', '--man-date').stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000432configure_file(
433 input : 'flashrom.8.tmpl',
434 output : 'flashrom.8',
435 configuration : conf,
436 install: true,
Thomas Heijligen454a28c2022-05-03 11:50:16 +0200437 install_dir: join_paths(get_option('mandir'), 'man8'),
Richard Hughesdad3a162020-02-17 09:57:01 +0000438)
439
Richard Hughescb973682018-12-19 11:44:22 +0000440flashrom_dep = declare_dependency(
441 link_with : flashrom,
Thomas Heijligen58015c22022-04-14 13:50:55 +0200442 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000443 dependencies : deps
444)
445
Thomas Heijligen84e9c912021-06-01 16:22:14 +0200446if config_default_programmer_name != ''
447 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
448else
449 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
450endif
451
452cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
453
Daniel Campellof7a84fd2021-03-16 17:17:14 -0600454if config_print_wiki
455 srcs += 'print_wiki.c'
456 cargs += '-DCONFIG_PRINT_WIKI=1'
457endif
458
Richard Hughescb973682018-12-19 11:44:22 +0000459# we can't just link_with libflashrom as we require all the internal symbols...
460executable(
461 'flashrom',
462 sources : [
463 srcs,
464 'cli_classic.c',
465 'cli_common.c',
466 'cli_output.c',
467 'flashrom.c',
468 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200469 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000470 dependencies : [
471 deps,
472 ],
473 c_args : [
474 cargs,
Richard Hughescb973682018-12-19 11:44:22 +0000475 ],
476 install : true,
Thomas Heijligen454a28c2022-05-03 11:50:16 +0200477 install_dir : get_option('sbindir')
Richard Hughescb973682018-12-19 11:44:22 +0000478)
479
480subdir('util')