blob: 6ebf3dcd03e6e0b82a40485aefe547b9a65f0144 [file] [log] [blame]
Richard Hughescb973682018-12-19 11:44:22 +00001project('flashromutils', 'c',
Nico Huber2f6936b2019-09-24 18:31:38 +02002 version : run_command('util/getversion.sh', '-v').stdout().strip(),
Nico Huberb417c0c2019-09-24 22:12:40 +02003 license : 'GPL-2.0',
Angel Ponsdfded992021-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 = [
Jacob Garber4a84ec22019-07-25 19:12:31 -060016 '-Wwrite-strings',
Richard Hughescb973682018-12-19 11:44:22 +000017 '-Wno-unused-parameter',
Richard Hughescb973682018-12-19 11:44:22 +000018 '-Wno-address-of-packed-member',
19 '-Wno-enum-conversion',
Richard Hughescb973682018-12-19 11:44:22 +000020 '-Wno-missing-braces',
21]
22
23conf = configuration_data()
24
25cc = meson.get_compiler('c')
26add_project_arguments(cc.get_supported_arguments(warning_flags), language : 'c')
27add_project_arguments('-D_DEFAULT_SOURCE', language : 'c')
Rosen Peneve4101642020-07-18 12:50:16 -070028add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c') # required for fileno, nanosleep, and strndup
Richard Hughescb973682018-12-19 11:44:22 +000029add_project_arguments('-D_BSD_SOURCE', language : 'c') # required for glibc < v2.19
30add_project_arguments('-DFLASHROM_VERSION="' + meson.project_version() + '"', language : 'c')
31
32# get defaults from configure
33config_atahpt = get_option('config_atahpt')
34config_atapromise = get_option('config_atapromise')
35config_atavia = get_option('config_atavia')
36config_buspirate_spi = get_option('config_buspirate_spi')
37config_ch341a_spi = get_option('config_ch341a_spi')
38config_dediprog = get_option('config_dediprog')
39config_developerbox_spi = get_option('config_developerbox_spi')
40config_digilent_spi = get_option('config_digilent_spi')
Marc Schink13a35682020-12-08 22:20:50 +010041config_jlink_spi = get_option('config_jlink_spi')
Richard Hughescb973682018-12-19 11:44:22 +000042config_drkaiser = get_option('config_drkaiser')
43config_dummy = get_option('config_dummy')
Victor Ding436b4152020-08-19 22:48:19 +100044config_ene_lpc = get_option('config_ene_lpc')
Richard Hughescb973682018-12-19 11:44:22 +000045config_ft2232_spi = get_option('config_ft2232_spi')
46config_gfxnvidia = get_option('config_gfxnvidia')
Edward O'Callaghan084d6a32021-01-26 12:10:41 +110047config_raiden_debug_spi = get_option('config_raiden_debug_spi')
Richard Hughescb973682018-12-19 11:44:22 +000048config_internal = get_option('config_internal')
49config_it8212 = get_option('config_it8212')
50config_linux_mtd = get_option('config_linux_mtd')
51config_linux_spi = get_option('config_linux_spi')
Victor Ding821e44c2020-08-18 18:27:26 +100052config_mec1308 = get_option('config_mec1308')
Richard Hughescb973682018-12-19 11:44:22 +000053config_mstarddc_spi = get_option('config_mstarddc_spi')
54config_nic3com = get_option('config_nic3com')
55config_nicintel_eeprom = get_option('config_nicintel_eeprom')
56config_nicintel = get_option('config_nicintel')
57config_nicintel_spi = get_option('config_nicintel_spi')
58config_nicnatsemi = get_option('config_nicnatsemi')
59config_nicrealtek = get_option('config_nicrealtek')
60config_ogp_spi = get_option('config_ogp_spi')
61config_pickit2_spi = get_option('config_pickit2_spi')
62config_pony_spi = get_option('config_pony_spi')
63config_rayer_spi = get_option('config_rayer_spi')
64config_satamv = get_option('config_satamv')
65config_satasii = get_option('config_satasii')
66config_serprog = get_option('config_serprog')
67config_usbblaster_spi = get_option('config_usbblaster_spi')
Miklós Márton324929c2019-08-01 19:14:10 +020068config_stlinkv3_spi = get_option('config_stlinkv3_spi')
Shiyu Sun13a2ef62020-03-19 14:37:57 +110069config_lspcon_i2c_spi = get_option('config_lspcon_i2c_spi')
Edward O'Callaghand97f87b2020-03-26 00:00:41 +110070config_realtek_mst_i2c_spi = get_option('config_realtek_mst_i2c_spi')
Daniel Campello0e5ae952021-03-16 17:17:14 -060071config_print_wiki= get_option('print_wiki')
Thomas Heijligen732aafd2021-06-01 16:22:14 +020072config_default_programmer_name = get_option('default_programmer_name')
73config_default_programmer_args = get_option('default_programmer_args')
Richard Hughescb973682018-12-19 11:44:22 +000074
75cargs = []
76deps = []
77srcs = []
78
Richard Hughescb973682018-12-19 11:44:22 +000079need_raw_access = false
80need_serial = false
81
82# check for required symbols
83if cc.has_function('clock_gettime')
84 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
85endif
86if cc.has_function('strnlen')
87 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
88endif
89if cc.check_header('sys/utsname.h')
90 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
91endif
92
93# some programmers require libusb
94if get_option('usb')
95 srcs += 'usbdev.c'
Edward O'Callaghand3396402020-02-17 12:47:12 +110096 srcs += 'usb_device.c'
Richard Hughescb973682018-12-19 11:44:22 +000097 deps += dependency('libusb-1.0')
98else
99 config_ch341a_spi = false
100 config_dediprog = false
101 config_digilent_spi = false
102 config_developerbox_spi = false
Thomas Heijligenb221cd72019-04-05 15:08:35 +0200103 config_pickit2_spi = false
Edward O'Callaghanc193fbd2021-03-30 10:40:30 +1100104 config_raiden_debug_spi = false
Richard Hughescb973682018-12-19 11:44:22 +0000105endif
106
107# some programmers require libpci
108if get_option('pciutils')
109 srcs += 'pcidev.c'
110 deps += dependency('libpci')
Daniel Campello8d6ef732021-03-17 09:14:11 -0600111 need_raw_access = true
Richard Hughescb973682018-12-19 11:44:22 +0000112 cargs += '-DNEED_PCI=1'
113else
114 config_atahpt = false
115 config_atapromise = false
116 config_atavia = false
117 config_drkaiser = false
118 config_gfxnvidia = false
119 config_internal = false
120 config_it8212 = false
121 config_nic3com = false
122 config_nicintel_eeprom = false
123 config_nicintel = false
124 config_nicintel_spi = false
125 config_nicnatsemi = false
126 config_nicrealtek = false
127 config_ogp_spi = false
Richard Hughescb973682018-12-19 11:44:22 +0000128 config_satamv = false
129 config_satasii = false
130endif
131
132# set defines for configured programmers
133if config_atahpt
134 srcs += 'atahpt.c'
135 cargs += '-DCONFIG_ATAHPT=1'
136endif
137if config_atapromise
138 srcs += 'atapromise.c'
139 cargs += '-DCONFIG_ATAPROMISE=1'
140endif
141if config_atavia
142 srcs += 'atavia.c'
143 cargs += '-DCONFIG_ATAVIA=1'
144endif
145if config_buspirate_spi
146 srcs += 'buspirate_spi.c'
147 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
148 need_serial = true
149endif
150if config_ch341a_spi
151 srcs += 'ch341a_spi.c'
152 cargs += '-DCONFIG_CH341A_SPI=1'
153endif
154if config_dediprog
155 srcs += 'dediprog.c'
156 cargs += '-DCONFIG_DEDIPROG=1'
157endif
158if config_developerbox_spi
159 srcs += 'developerbox_spi.c'
160 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
161endif
162if config_digilent_spi
163 srcs += 'digilent_spi.c'
164 cargs += '-DCONFIG_DIGILENT_SPI=1'
165endif
Marc Schink13a35682020-12-08 22:20:50 +0100166if config_jlink_spi
167 srcs += 'jlink_spi.c'
168 cargs += '-DCONFIG_JLINK_SPI=1'
169 deps += dependency('libjaylink')
170endif
Richard Hughescb973682018-12-19 11:44:22 +0000171if config_drkaiser
172 srcs += 'drkaiser.c'
173 cargs += '-DCONFIG_DRKAISER=1'
174endif
175if config_dummy
176 srcs += 'dummyflasher.c'
177 cargs += '-DCONFIG_DUMMY=1'
178endif
179if config_ft2232_spi
180 srcs += 'ft2232_spi.c'
181 cargs += '-DCONFIG_FT2232_SPI=1'
182 deps += dependency('libftdi1')
183 cargs += '-DHAVE_FT232H=1'
184endif
185if config_gfxnvidia
186 srcs += 'gfxnvidia.c'
187 cargs += '-DCONFIG_GFXNVIDIA=1'
188endif
Edward O'Callaghan084d6a32021-01-26 12:10:41 +1100189if config_raiden_debug_spi
Edward O'Callaghanad08aef2020-03-02 18:16:14 +1100190 srcs += 'raiden_debug_spi.c'
Edward O'Callaghan732f2ee2020-11-27 12:54:31 +1100191 cargs += '-DCONFIG_RAIDEN_DEBUG_SPI=1'
Edward O'Callaghanad08aef2020-03-02 18:16:14 +1100192endif
Richard Hughescb973682018-12-19 11:44:22 +0000193if config_internal
194 srcs += 'board_enable.c'
195 srcs += 'cbtable.c'
196 srcs += 'chipset_enable.c'
197 srcs += 'internal.c'
198 srcs += 'processor_enable.c'
199 if target_machine.cpu_family() == 'x86' or target_machine.cpu_family() == 'x86_64'
200 srcs += 'amd_imc.c'
201 srcs += 'dmi.c'
202 srcs += 'ichspi.c'
203 srcs += 'it85spi.c'
204 srcs += 'it87spi.c'
205 srcs += 'mcp6x_spi.c'
206 srcs += 'sb600spi.c'
207 srcs += 'wbsio_spi.c'
208 endif
209 config_bitbang_spi = true
210 cargs += '-DCONFIG_INTERNAL=1'
211 if get_option('config_internal_dmi')
212 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
213 cargs += '-DCONFIG_INTERNAL_DMI=1'
214 endif
215endif
Victor Ding436b4152020-08-19 22:48:19 +1000216if config_ene_lpc
217 srcs += 'ene_lpc.c'
218 cargs += '-DCONFIG_ENE_LPC=1'
219endif
Richard Hughescb973682018-12-19 11:44:22 +0000220if config_it8212
221 srcs += 'it8212.c'
222 cargs += '-DCONFIG_IT8212=1'
223endif
224if config_linux_mtd
225 srcs += 'linux_mtd.c'
226 cargs += '-DCONFIG_LINUX_MTD=1'
227endif
228if config_linux_spi
229 srcs += 'linux_spi.c'
230 cargs += '-DCONFIG_LINUX_SPI=1'
231endif
Victor Ding821e44c2020-08-18 18:27:26 +1000232if config_mec1308
233 srcs += 'mec1308.c'
234 cargs += '-DCONFIG_MEC1308=1'
235endif
Richard Hughescb973682018-12-19 11:44:22 +0000236if config_mstarddc_spi
237 srcs += 'mstarddc_spi.c'
238 cargs += '-DCONFIG_MSTARDDC_SPI=1'
239endif
240if config_nic3com
241 srcs += 'nic3com.c'
242 cargs += '-DCONFIG_NIC3COM=1'
243endif
244if config_nicintel
245 srcs += 'nicintel.c'
246 cargs += '-DCONFIG_NICINTEL=1'
247endif
248if config_nicintel_eeprom
249 srcs += 'nicintel_eeprom.c'
250 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
251endif
252if config_nicintel_spi
253 srcs += 'nicintel_spi.c'
254 config_bitbang_spi = true
255 cargs += '-DCONFIG_NICINTEL_SPI=1'
256endif
257if config_nicnatsemi
258 srcs += 'nicnatsemi.c'
259 cargs += '-DCONFIG_NICNATSEMI=1'
260endif
261if config_nicrealtek
262 srcs += 'nicrealtek.c'
263 cargs += '-DCONFIG_NICREALTEK=1'
264endif
265if config_ogp_spi
266 config_bitbang_spi = true
267 srcs += 'ogp_spi.c'
268 cargs += '-DCONFIG_OGP_SPI=1'
269endif
270if config_pickit2_spi
271 srcs += 'pickit2_spi.c'
272 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000273endif
274if config_pony_spi
275 srcs += 'pony_spi.c'
276 need_serial = true
277 config_bitbang_spi = true
278 cargs += '-DCONFIG_PONY_SPI=1'
279endif
280if config_rayer_spi
281 srcs += 'rayer_spi.c'
282 config_bitbang_spi = true
Daniel Campello0cdd42f2021-03-29 16:55:17 -0600283 need_raw_access = true
Richard Hughescb973682018-12-19 11:44:22 +0000284 cargs += '-DCONFIG_RAYER_SPI=1'
285endif
286if config_satamv
287 srcs += 'satamv.c'
288 cargs += '-DCONFIG_SATAMV=1'
289endif
290if config_satasii
291 srcs += 'satasii.c'
292 cargs += '-DCONFIG_SATASII=1'
293endif
294if config_serprog
295 srcs += 'serprog.c'
296 cargs += '-DCONFIG_SERPROG=1'
297 need_serial = true
298endif
299if config_usbblaster_spi
300 srcs += 'usbblaster_spi.c'
301 cargs += '-DCONFIG_USBBLASTER_SPI=1'
302endif
Miklós Márton324929c2019-08-01 19:14:10 +0200303if config_stlinkv3_spi
304 srcs += 'stlinkv3_spi.c'
305 cargs += '-DCONFIG_STLINKV3_SPI=1'
306endif
Shiyu Sun13a2ef62020-03-19 14:37:57 +1100307if config_lspcon_i2c_spi
308 srcs += 'lspcon_i2c_spi.c'
309 cargs += '-DCONFIG_LSPCON_I2C_SPI=1'
310endif
Edward O'Callaghand97f87b2020-03-26 00:00:41 +1100311if config_realtek_mst_i2c_spi
312 srcs += 'realtek_mst_i2c_spi.c'
313 cargs += '-DCONFIG_REALTEK_MST_I2C_SPI=1'
314endif
Richard Hughescb973682018-12-19 11:44:22 +0000315
316# bitbanging SPI infrastructure
317if config_bitbang_spi
318 srcs += 'bitbang_spi.c'
319 cargs += '-DCONFIG_BITBANG_SPI=1'
320endif
321
Shiyu Sundc2c83b2020-03-19 16:59:52 +1100322if host_machine.system() == 'linux'
323 srcs += 'i2c_helper_linux.c'
324 cargs += '-DCONFIG_I2C_SUPPORT=1'
325endif
326
Richard Hughescb973682018-12-19 11:44:22 +0000327# raw memory, MSR or PCI port I/O access
328if need_raw_access
329 srcs += 'hwaccess.c'
330 srcs += 'physmap.c'
331 cargs += '-DNEED_RAW_ACCESS=1'
332endif
333
334# raw serial IO
335if need_serial
336 srcs += 'custom_baud.c'
337 srcs += 'serial.c'
338endif
339
Richard Hughescb973682018-12-19 11:44:22 +0000340prefix = get_option('prefix')
341sbindir = join_paths(prefix, get_option('sbindir'))
342libdir = join_paths(prefix, get_option('libdir'))
Richard Hughes7aea04f2020-02-17 09:57:01 +0000343mandir = join_paths(prefix, get_option('mandir'))
Richard Hughescb973682018-12-19 11:44:22 +0000344
345install_headers([
346 'libflashrom.h',
347 ],
348)
349
350# core modules needed by both the library and the CLI
351srcs += '82802ab.c'
352srcs += 'at45db.c'
353srcs += 'edi.c'
354srcs += 'en29lv640b.c'
355srcs += 'flashchips.c'
356srcs += 'flashrom.c'
357srcs += 'fmap.c'
358srcs += 'helpers.c'
359srcs += 'ich_descriptors.c'
360srcs += 'jedec.c'
361srcs += 'layout.c'
362srcs += 'libflashrom.c'
363srcs += 'opaque.c'
364srcs += 'print.c'
365srcs += 'programmer.c'
Thomas Heijligen9e090952021-03-31 20:40:01 +0200366srcs += 'programmer_table.c'
Nikolai Artemievadbae0e2020-10-06 16:59:51 +1100367srcs += 's25f.c'
Richard Hughescb973682018-12-19 11:44:22 +0000368srcs += 'sfdp.c'
369srcs += 'spi25.c'
370srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700371srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000372srcs += 'spi.c'
373srcs += 'sst28sf040.c'
374srcs += 'sst49lfxxxc.c'
375srcs += 'sst_fwhub.c'
376srcs += 'stm50.c'
377srcs += 'udelay.c'
378srcs += 'w29ee011.c'
379srcs += 'w39.c'
Edward O'Callaghand3b6acf2020-09-21 17:10:21 +1000380srcs += 'writeprotect.c'
Richard Hughescb973682018-12-19 11:44:22 +0000381
382mapfile = 'libflashrom.map'
383vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
Daniel Campelloa8301662021-03-17 18:03:28 -0600384flashrom = library(
Richard Hughescb973682018-12-19 11:44:22 +0000385 'flashrom',
386 sources : [
387 srcs,
388 ],
389 soversion : lt_current,
390 version : lt_version,
391 dependencies : [
392 deps,
393 ],
394 c_args : [
395 cargs,
396 ],
397 install : true,
398 link_args : vflag,
399 link_depends : mapfile,
400)
401
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500402version = meson.project_version()
403#strip leading characters
404if version.startswith('v')
405 version = version.split('v')[1]
406endif
407if version.startswith('p')
408 version = version.split('p')[1]
409endif
410
Richard Hughescb973682018-12-19 11:44:22 +0000411pkgg = import('pkgconfig')
412pkgg.generate(
413 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500414 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500415 name : 'flashrom',
416 filebase : 'flashrom',
417 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000418)
419
Richard Hughes7aea04f2020-02-17 09:57:01 +0000420conf.set('VERSION', version)
421conf.set('MAN_DATE', run_command('util/getrevision.sh', '--date', 'flashrom.8.tmpl').stdout().strip())
422configure_file(
423 input : 'flashrom.8.tmpl',
424 output : 'flashrom.8',
425 configuration : conf,
426 install: true,
427 install_dir: join_paths(mandir, 'man8'),
428)
429
Richard Hughescb973682018-12-19 11:44:22 +0000430flashrom_dep = declare_dependency(
431 link_with : flashrom,
432 include_directories : include_directories('.'),
433 dependencies : deps
434)
435
Daniel Campello0e5ae952021-03-16 17:17:14 -0600436if config_print_wiki
437 srcs += 'print_wiki.c'
438 cargs += '-DCONFIG_PRINT_WIKI=1'
439endif
440
Thomas Heijligen732aafd2021-06-01 16:22:14 +0200441if config_default_programmer_name != ''
442 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
443else
444 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
445endif
446
447cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
448
Richard Hughescb973682018-12-19 11:44:22 +0000449# we can't just link_with libflashrom as we require all the internal symbols...
450executable(
451 'flashrom',
452 sources : [
453 srcs,
454 'cli_classic.c',
455 'cli_common.c',
456 'cli_output.c',
457 'flashrom.c',
458 ],
459 dependencies : [
460 deps,
461 ],
462 c_args : [
Thomas Heijligen732aafd2021-06-01 16:22:14 +0200463 cargs
Richard Hughescb973682018-12-19 11:44:22 +0000464 ],
465 install : true,
466 install_dir : sbindir,
467)
468
469subdir('util')
Edward O'Callaghan46f2d4e2020-05-20 20:10:20 +1000470
471# unit-test framework
472cmocka_dep = dependency(
473 'cmocka',
Edward O'Callaghan16c62a72021-05-17 21:10:23 +1000474 fallback: ['cmocka', 'cmocka_dep'],
475 required: false
Edward O'Callaghan46f2d4e2020-05-20 20:10:20 +1000476)
477flashrom_test_dep = declare_dependency(
478 include_directories : include_directories('.'),
479 sources : [
480 srcs,
481 'cli_common.c',
482 'cli_output.c',
483 'flashrom.c',
484 ],
Anastasia Klimchuk2daeea22021-03-04 09:54:56 +1100485 compile_args : [
486 '-includestdlib.h',
487 '-includeunittest_env.h',
Anastasia Klimchuk21e22ba2021-05-10 10:19:25 +1000488 '-includehwaccess_x86_io_unittest.h'
Anastasia Klimchuk2daeea22021-03-04 09:54:56 +1100489 ],
Edward O'Callaghan46f2d4e2020-05-20 20:10:20 +1000490 dependencies : [
491 deps,
492 ],
493)
494
Edward O'Callaghan16c62a72021-05-17 21:10:23 +1000495if cmocka_dep.found()
496 subdir('tests')
497endif