blob: 81d63a9d1ee61210903bb1900974172f5ddf3888 [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')
Richard Hughescb973682018-12-19 11:44:22 +000072
73cargs = []
74deps = []
75srcs = []
76
Richard Hughescb973682018-12-19 11:44:22 +000077need_raw_access = false
78need_serial = false
79
80# check for required symbols
81if cc.has_function('clock_gettime')
82 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
83endif
84if cc.has_function('strnlen')
85 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
86endif
87if cc.check_header('sys/utsname.h')
88 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
89endif
90
91# some programmers require libusb
92if get_option('usb')
93 srcs += 'usbdev.c'
Edward O'Callaghand3396402020-02-17 12:47:12 +110094 srcs += 'usb_device.c'
Richard Hughescb973682018-12-19 11:44:22 +000095 deps += dependency('libusb-1.0')
96else
97 config_ch341a_spi = false
98 config_dediprog = false
99 config_digilent_spi = false
100 config_developerbox_spi = false
Thomas Heijligenb221cd72019-04-05 15:08:35 +0200101 config_pickit2_spi = false
Edward O'Callaghanc193fbd2021-03-30 10:40:30 +1100102 config_raiden_debug_spi = false
Richard Hughescb973682018-12-19 11:44:22 +0000103endif
104
105# some programmers require libpci
106if get_option('pciutils')
107 srcs += 'pcidev.c'
108 deps += dependency('libpci')
Daniel Campello8d6ef732021-03-17 09:14:11 -0600109 need_raw_access = true
Richard Hughescb973682018-12-19 11:44:22 +0000110 cargs += '-DNEED_PCI=1'
111else
112 config_atahpt = false
113 config_atapromise = false
114 config_atavia = false
115 config_drkaiser = false
116 config_gfxnvidia = false
117 config_internal = false
118 config_it8212 = false
119 config_nic3com = false
120 config_nicintel_eeprom = false
121 config_nicintel = false
122 config_nicintel_spi = false
123 config_nicnatsemi = false
124 config_nicrealtek = false
125 config_ogp_spi = false
Richard Hughescb973682018-12-19 11:44:22 +0000126 config_satamv = false
127 config_satasii = false
128endif
129
130# set defines for configured programmers
131if config_atahpt
132 srcs += 'atahpt.c'
133 cargs += '-DCONFIG_ATAHPT=1'
134endif
135if config_atapromise
136 srcs += 'atapromise.c'
137 cargs += '-DCONFIG_ATAPROMISE=1'
138endif
139if config_atavia
140 srcs += 'atavia.c'
141 cargs += '-DCONFIG_ATAVIA=1'
142endif
143if config_buspirate_spi
144 srcs += 'buspirate_spi.c'
145 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
146 need_serial = true
147endif
148if config_ch341a_spi
149 srcs += 'ch341a_spi.c'
150 cargs += '-DCONFIG_CH341A_SPI=1'
151endif
152if config_dediprog
153 srcs += 'dediprog.c'
154 cargs += '-DCONFIG_DEDIPROG=1'
155endif
156if config_developerbox_spi
157 srcs += 'developerbox_spi.c'
158 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
159endif
160if config_digilent_spi
161 srcs += 'digilent_spi.c'
162 cargs += '-DCONFIG_DIGILENT_SPI=1'
163endif
Marc Schink13a35682020-12-08 22:20:50 +0100164if config_jlink_spi
165 srcs += 'jlink_spi.c'
166 cargs += '-DCONFIG_JLINK_SPI=1'
167 deps += dependency('libjaylink')
168endif
Richard Hughescb973682018-12-19 11:44:22 +0000169if config_drkaiser
170 srcs += 'drkaiser.c'
171 cargs += '-DCONFIG_DRKAISER=1'
172endif
173if config_dummy
174 srcs += 'dummyflasher.c'
175 cargs += '-DCONFIG_DUMMY=1'
176endif
177if config_ft2232_spi
178 srcs += 'ft2232_spi.c'
179 cargs += '-DCONFIG_FT2232_SPI=1'
180 deps += dependency('libftdi1')
181 cargs += '-DHAVE_FT232H=1'
182endif
183if config_gfxnvidia
184 srcs += 'gfxnvidia.c'
185 cargs += '-DCONFIG_GFXNVIDIA=1'
186endif
Edward O'Callaghan084d6a32021-01-26 12:10:41 +1100187if config_raiden_debug_spi
Edward O'Callaghanad08aef2020-03-02 18:16:14 +1100188 srcs += 'raiden_debug_spi.c'
Edward O'Callaghan732f2ee2020-11-27 12:54:31 +1100189 cargs += '-DCONFIG_RAIDEN_DEBUG_SPI=1'
Edward O'Callaghanad08aef2020-03-02 18:16:14 +1100190endif
Richard Hughescb973682018-12-19 11:44:22 +0000191if config_internal
192 srcs += 'board_enable.c'
193 srcs += 'cbtable.c'
194 srcs += 'chipset_enable.c'
195 srcs += 'internal.c'
196 srcs += 'processor_enable.c'
197 if target_machine.cpu_family() == 'x86' or target_machine.cpu_family() == 'x86_64'
198 srcs += 'amd_imc.c'
199 srcs += 'dmi.c'
200 srcs += 'ichspi.c'
201 srcs += 'it85spi.c'
202 srcs += 'it87spi.c'
203 srcs += 'mcp6x_spi.c'
204 srcs += 'sb600spi.c'
205 srcs += 'wbsio_spi.c'
206 endif
207 config_bitbang_spi = true
208 cargs += '-DCONFIG_INTERNAL=1'
209 if get_option('config_internal_dmi')
210 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
211 cargs += '-DCONFIG_INTERNAL_DMI=1'
212 endif
213endif
Victor Ding436b4152020-08-19 22:48:19 +1000214if config_ene_lpc
215 srcs += 'ene_lpc.c'
216 cargs += '-DCONFIG_ENE_LPC=1'
217endif
Richard Hughescb973682018-12-19 11:44:22 +0000218if config_it8212
219 srcs += 'it8212.c'
220 cargs += '-DCONFIG_IT8212=1'
221endif
222if config_linux_mtd
223 srcs += 'linux_mtd.c'
224 cargs += '-DCONFIG_LINUX_MTD=1'
225endif
226if config_linux_spi
227 srcs += 'linux_spi.c'
228 cargs += '-DCONFIG_LINUX_SPI=1'
229endif
Victor Ding821e44c2020-08-18 18:27:26 +1000230if config_mec1308
231 srcs += 'mec1308.c'
232 cargs += '-DCONFIG_MEC1308=1'
233endif
Richard Hughescb973682018-12-19 11:44:22 +0000234if config_mstarddc_spi
235 srcs += 'mstarddc_spi.c'
236 cargs += '-DCONFIG_MSTARDDC_SPI=1'
237endif
238if config_nic3com
239 srcs += 'nic3com.c'
240 cargs += '-DCONFIG_NIC3COM=1'
241endif
242if config_nicintel
243 srcs += 'nicintel.c'
244 cargs += '-DCONFIG_NICINTEL=1'
245endif
246if config_nicintel_eeprom
247 srcs += 'nicintel_eeprom.c'
248 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
249endif
250if config_nicintel_spi
251 srcs += 'nicintel_spi.c'
252 config_bitbang_spi = true
253 cargs += '-DCONFIG_NICINTEL_SPI=1'
254endif
255if config_nicnatsemi
256 srcs += 'nicnatsemi.c'
257 cargs += '-DCONFIG_NICNATSEMI=1'
258endif
259if config_nicrealtek
260 srcs += 'nicrealtek.c'
261 cargs += '-DCONFIG_NICREALTEK=1'
262endif
263if config_ogp_spi
264 config_bitbang_spi = true
265 srcs += 'ogp_spi.c'
266 cargs += '-DCONFIG_OGP_SPI=1'
267endif
268if config_pickit2_spi
269 srcs += 'pickit2_spi.c'
270 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000271endif
272if config_pony_spi
273 srcs += 'pony_spi.c'
274 need_serial = true
275 config_bitbang_spi = true
276 cargs += '-DCONFIG_PONY_SPI=1'
277endif
278if config_rayer_spi
279 srcs += 'rayer_spi.c'
280 config_bitbang_spi = true
Daniel Campello0cdd42f2021-03-29 16:55:17 -0600281 need_raw_access = true
Richard Hughescb973682018-12-19 11:44:22 +0000282 cargs += '-DCONFIG_RAYER_SPI=1'
283endif
284if config_satamv
285 srcs += 'satamv.c'
286 cargs += '-DCONFIG_SATAMV=1'
287endif
288if config_satasii
289 srcs += 'satasii.c'
290 cargs += '-DCONFIG_SATASII=1'
291endif
292if config_serprog
293 srcs += 'serprog.c'
294 cargs += '-DCONFIG_SERPROG=1'
295 need_serial = true
296endif
297if config_usbblaster_spi
298 srcs += 'usbblaster_spi.c'
299 cargs += '-DCONFIG_USBBLASTER_SPI=1'
300endif
Miklós Márton324929c2019-08-01 19:14:10 +0200301if config_stlinkv3_spi
302 srcs += 'stlinkv3_spi.c'
303 cargs += '-DCONFIG_STLINKV3_SPI=1'
304endif
Shiyu Sun13a2ef62020-03-19 14:37:57 +1100305if config_lspcon_i2c_spi
306 srcs += 'lspcon_i2c_spi.c'
307 cargs += '-DCONFIG_LSPCON_I2C_SPI=1'
308endif
Edward O'Callaghand97f87b2020-03-26 00:00:41 +1100309if config_realtek_mst_i2c_spi
310 srcs += 'realtek_mst_i2c_spi.c'
311 cargs += '-DCONFIG_REALTEK_MST_I2C_SPI=1'
312endif
Richard Hughescb973682018-12-19 11:44:22 +0000313
314# bitbanging SPI infrastructure
315if config_bitbang_spi
316 srcs += 'bitbang_spi.c'
317 cargs += '-DCONFIG_BITBANG_SPI=1'
318endif
319
Shiyu Sundc2c83b2020-03-19 16:59:52 +1100320if host_machine.system() == 'linux'
321 srcs += 'i2c_helper_linux.c'
322 cargs += '-DCONFIG_I2C_SUPPORT=1'
323endif
324
Richard Hughescb973682018-12-19 11:44:22 +0000325# raw memory, MSR or PCI port I/O access
326if need_raw_access
327 srcs += 'hwaccess.c'
328 srcs += 'physmap.c'
329 cargs += '-DNEED_RAW_ACCESS=1'
330endif
331
332# raw serial IO
333if need_serial
334 srcs += 'custom_baud.c'
335 srcs += 'serial.c'
336endif
337
Richard Hughescb973682018-12-19 11:44:22 +0000338prefix = get_option('prefix')
339sbindir = join_paths(prefix, get_option('sbindir'))
340libdir = join_paths(prefix, get_option('libdir'))
Richard Hughes7aea04f2020-02-17 09:57:01 +0000341mandir = join_paths(prefix, get_option('mandir'))
Richard Hughescb973682018-12-19 11:44:22 +0000342
343install_headers([
344 'libflashrom.h',
345 ],
346)
347
348# core modules needed by both the library and the CLI
349srcs += '82802ab.c'
350srcs += 'at45db.c'
351srcs += 'edi.c'
352srcs += 'en29lv640b.c'
353srcs += 'flashchips.c'
354srcs += 'flashrom.c'
355srcs += 'fmap.c'
356srcs += 'helpers.c'
357srcs += 'ich_descriptors.c'
358srcs += 'jedec.c'
359srcs += 'layout.c'
360srcs += 'libflashrom.c'
361srcs += 'opaque.c'
362srcs += 'print.c'
363srcs += 'programmer.c'
Nikolai Artemievadbae0e2020-10-06 16:59:51 +1100364srcs += 's25f.c'
Richard Hughescb973682018-12-19 11:44:22 +0000365srcs += 'sfdp.c'
366srcs += 'spi25.c'
367srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700368srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000369srcs += 'spi.c'
370srcs += 'sst28sf040.c'
371srcs += 'sst49lfxxxc.c'
372srcs += 'sst_fwhub.c'
373srcs += 'stm50.c'
374srcs += 'udelay.c'
375srcs += 'w29ee011.c'
376srcs += 'w39.c'
Edward O'Callaghand3b6acf2020-09-21 17:10:21 +1000377srcs += 'writeprotect.c'
Richard Hughescb973682018-12-19 11:44:22 +0000378
379mapfile = 'libflashrom.map'
380vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
Daniel Campelloa8301662021-03-17 18:03:28 -0600381flashrom = library(
Richard Hughescb973682018-12-19 11:44:22 +0000382 'flashrom',
383 sources : [
384 srcs,
385 ],
386 soversion : lt_current,
387 version : lt_version,
388 dependencies : [
389 deps,
390 ],
391 c_args : [
392 cargs,
393 ],
394 install : true,
395 link_args : vflag,
396 link_depends : mapfile,
397)
398
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500399version = meson.project_version()
400#strip leading characters
401if version.startswith('v')
402 version = version.split('v')[1]
403endif
404if version.startswith('p')
405 version = version.split('p')[1]
406endif
407
Richard Hughescb973682018-12-19 11:44:22 +0000408pkgg = import('pkgconfig')
409pkgg.generate(
410 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500411 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500412 name : 'flashrom',
413 filebase : 'flashrom',
414 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000415)
416
Richard Hughes7aea04f2020-02-17 09:57:01 +0000417conf.set('VERSION', version)
418conf.set('MAN_DATE', run_command('util/getrevision.sh', '--date', 'flashrom.8.tmpl').stdout().strip())
419configure_file(
420 input : 'flashrom.8.tmpl',
421 output : 'flashrom.8',
422 configuration : conf,
423 install: true,
424 install_dir: join_paths(mandir, 'man8'),
425)
426
Richard Hughescb973682018-12-19 11:44:22 +0000427flashrom_dep = declare_dependency(
428 link_with : flashrom,
429 include_directories : include_directories('.'),
430 dependencies : deps
431)
432
Daniel Campello0e5ae952021-03-16 17:17:14 -0600433if config_print_wiki
434 srcs += 'print_wiki.c'
435 cargs += '-DCONFIG_PRINT_WIKI=1'
436endif
437
Richard Hughescb973682018-12-19 11:44:22 +0000438# we can't just link_with libflashrom as we require all the internal symbols...
439executable(
440 'flashrom',
441 sources : [
442 srcs,
443 'cli_classic.c',
444 'cli_common.c',
445 'cli_output.c',
446 'flashrom.c',
447 ],
448 dependencies : [
449 deps,
450 ],
451 c_args : [
452 cargs,
Richard Hughescb973682018-12-19 11:44:22 +0000453 '-DCONFIG_DEFAULT_PROGRAMMER=PROGRAMMER_INVALID',
454 '-DCONFIG_DEFAULT_PROGRAMMER_ARGS=""',
455 ],
456 install : true,
457 install_dir : sbindir,
458)
459
460subdir('util')
Edward O'Callaghan46f2d4e2020-05-20 20:10:20 +1000461
462# unit-test framework
463cmocka_dep = dependency(
464 'cmocka',
Edward O'Callaghan16c62a72021-05-17 21:10:23 +1000465 fallback: ['cmocka', 'cmocka_dep'],
466 required: false
Edward O'Callaghan46f2d4e2020-05-20 20:10:20 +1000467)
468flashrom_test_dep = declare_dependency(
469 include_directories : include_directories('.'),
470 sources : [
471 srcs,
472 'cli_common.c',
473 'cli_output.c',
474 'flashrom.c',
475 ],
Anastasia Klimchuk2daeea22021-03-04 09:54:56 +1100476 compile_args : [
477 '-includestdlib.h',
478 '-includeunittest_env.h',
479 ],
Edward O'Callaghan46f2d4e2020-05-20 20:10:20 +1000480 dependencies : [
481 deps,
482 ],
483)
484
Edward O'Callaghan16c62a72021-05-17 21:10:23 +1000485if cmocka_dep.found()
486 subdir('tests')
487endif