blob: 37ee3093e85c580e9a70f352a30dc754eff9d847 [file] [log] [blame]
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +10001project('flashromutils', 'c',
2 version : run_command('util/getversion.sh', '-v').stdout().strip(),
3 license : 'GPL-2.0',
Angel Ponsb54d7012021-01-26 10:21:46 +01004 meson_version : '>=0.50.0',
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +10005 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
14# hide/enable some warnings
15warning_flags = [
16 '-Wwrite-strings',
17 '-Wno-unused-parameter',
18 '-Wno-address-of-packed-member',
19 '-Wno-enum-conversion',
20 '-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')
Edward O'Callaghan4fb8e282020-11-27 20:44:56 +110028add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c') # required for fileno, nanosleep, and strndup
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +100029add_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')
Edward O'Callaghanb9727042021-01-07 21:05:46 +110041config_jlink_spi = get_option('config_jlink_spi')
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +100042config_drkaiser = get_option('config_drkaiser')
43config_dummy = get_option('config_dummy')
Edward O'Callaghan4fb8e282020-11-27 20:44:56 +110044config_ene_lpc = get_option('config_ene_lpc')
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +100045config_ft2232_spi = get_option('config_ft2232_spi')
46config_gfxnvidia = get_option('config_gfxnvidia')
Edward O'Callaghan42d88702021-01-26 12:10:41 +110047config_raiden_debug_spi = get_option('config_raiden_debug_spi')
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +100048config_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')
Edward O'Callaghan4fb8e282020-11-27 20:44:56 +110052config_mec1308 = get_option('config_mec1308')
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +100053config_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')
68config_stlinkv3_spi = get_option('config_stlinkv3_spi')
69config_lspcon_i2c_spi = get_option('config_lspcon_i2c_spi')
70config_realtek_mst_i2c_spi = get_option('config_realtek_mst_i2c_spi')
Daniel Campello438b9c92021-03-16 15:28:14 -060071config_print_wiki= get_option('print_wiki')
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +100072
73cargs = []
74deps = []
75srcs = []
76
77need_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'
94 srcs += 'usb_device.c'
95 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
101 config_pickit2_spi = false
Edward O'Callaghan17420242021-03-30 10:40:30 +1100102 config_raiden_debug_spi = false
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000103endif
104
105# some programmers require libpci
106if get_option('pciutils')
107 srcs += 'pcidev.c'
108 deps += dependency('libpci')
Daniel Campello5c3ae8d2021-03-17 09:14:11 -0600109 need_raw_access = true
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000110 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
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000117 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
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000126 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
Edward O'Callaghan6f944b22020-10-03 00:37:18 +1000139if config_atavia
140 srcs += 'atavia.c'
141 cargs += '-DCONFIG_ATAVIA=1'
142endif
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000143if config_buspirate_spi
144 srcs += 'buspirate_spi.c'
145 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
146 need_serial = true
147endif
Edward O'Callaghan6f944b22020-10-03 00:37:18 +1000148if config_ch341a_spi
149 srcs += 'ch341a_spi.c'
150 cargs += '-DCONFIG_CH341A_SPI=1'
151endif
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000152if config_dediprog
153 srcs += 'dediprog.c'
154 cargs += '-DCONFIG_DEDIPROG=1'
155endif
Edward O'Callaghan6f944b22020-10-03 00:37:18 +1000156if 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
Edward O'Callaghanb9727042021-01-07 21:05:46 +1100164if config_jlink_spi
165 srcs += 'jlink_spi.c'
166 cargs += '-DCONFIG_JLINK_SPI=1'
167 deps += dependency('libjaylink')
168endif
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000169if 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'Callaghan42d88702021-01-26 12:10:41 +1100187if config_raiden_debug_spi
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000188 srcs += 'raiden_debug_spi.c'
Edward O'Callaghan16056852020-11-27 12:54:31 +1100189 cargs += '-DCONFIG_RAIDEN_DEBUG_SPI=1'
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000190endif
191if 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
Edward O'Callaghan4fb8e282020-11-27 20:44:56 +1100214if config_ene_lpc
215 srcs += 'ene_lpc.c'
216 cargs += '-DCONFIG_ENE_LPC=1'
217endif
Edward O'Callaghan6f944b22020-10-03 00:37:18 +1000218if config_it8212
219 srcs += 'it8212.c'
220 cargs += '-DCONFIG_IT8212=1'
221endif
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000222if 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
Edward O'Callaghan4fb8e282020-11-27 20:44:56 +1100230if config_mec1308
231 srcs += 'mec1308.c'
232 cargs += '-DCONFIG_MEC1308=1'
233endif
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000234if 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
Edward O'Callaghan6f944b22020-10-03 00:37:18 +1000246if config_nicintel_eeprom
247 srcs += 'nicintel_eeprom.c'
248 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
249endif
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000250if 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
Edward O'Callaghan6f944b22020-10-03 00:37:18 +1000268if config_pickit2_spi
269 srcs += 'pickit2_spi.c'
270 cargs += '-DCONFIG_PICKIT2_SPI=1'
271endif
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
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000278if config_rayer_spi
279 srcs += 'rayer_spi.c'
280 config_bitbang_spi = true
Daniel Campello21315382021-03-29 16:55:17 -0600281 need_raw_access = true
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000282 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
Edward O'Callaghan6f944b22020-10-03 00:37:18 +1000297if config_usbblaster_spi
298 srcs += 'usbblaster_spi.c'
299 cargs += '-DCONFIG_USBBLASTER_SPI=1'
300endif
301if config_stlinkv3_spi
302 srcs += 'stlinkv3_spi.c'
303 cargs += '-DCONFIG_STLINKV3_SPI=1'
304endif
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000305if config_lspcon_i2c_spi
306 srcs += 'lspcon_i2c_spi.c'
307 cargs += '-DCONFIG_LSPCON_I2C_SPI=1'
308endif
309if config_realtek_mst_i2c_spi
310 srcs += 'realtek_mst_i2c_spi.c'
311 cargs += '-DCONFIG_REALTEK_MST_I2C_SPI=1'
312endif
313
314# bitbanging SPI infrastructure
315if config_bitbang_spi
316 srcs += 'bitbang_spi.c'
317 cargs += '-DCONFIG_BITBANG_SPI=1'
318endif
319
Edward O'Callaghanfd4a1e72020-04-21 18:04:46 +1000320if host_machine.system() == 'linux'
321 srcs += 'i2c_helper_linux.c'
322 cargs += '-DCONFIG_I2C_SUPPORT=1'
323endif
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000324
325# 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
338prefix = get_option('prefix')
339sbindir = join_paths(prefix, get_option('sbindir'))
340libdir = join_paths(prefix, get_option('libdir'))
Edward O'Callaghan4fb8e282020-11-27 20:44:56 +1100341mandir = join_paths(prefix, get_option('mandir'))
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000342
343install_headers([
344 'libflashrom.h',
345 ],
346)
347
Edward O'Callaghanf03fde22020-04-21 18:05:35 +1000348### CrOS Tree
Edward O'Callaghanf03fde22020-04-21 18:05:35 +1000349srcs += 'power.c'
Edward O'Callaghanf03fde22020-04-21 18:05:35 +1000350srcs += 'file.c'
Edward O'Callaghandd262432021-01-11 13:02:22 +1100351srcs += 'action_descriptor.c'
352
Edward O'Callaghan33ed5272021-01-07 21:12:15 +1100353srcs += 'cros_alias.c'
Edward O'Callaghanf03fde22020-04-21 18:05:35 +1000354srcs += 'cros_ec.c'
Edward O'Callaghanf03fde22020-04-21 18:05:35 +1000355srcs += 'cros_ec_dev.c'
Edward O'Callaghandd262432021-01-11 13:02:22 +1100356cargs += '-DCONFIG_CROS_ALIAS=1'
Nicolas Boichat24892532021-04-08 13:25:38 +0800357
358srcs += 'big_lock.c'
359srcs += 'file_lock.c'
360cargs += '-DUSE_BIG_LOCK=1'
Edward O'Callaghanf03fde22020-04-21 18:05:35 +1000361###
362
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000363# core modules needed by both the library and the CLI
364srcs += '82802ab.c'
365srcs += 'at45db.c'
366srcs += 'edi.c'
Edward O'Callaghan6f944b22020-10-03 00:37:18 +1000367srcs += 'en29lv640b.c'
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000368srcs += 'flashchips.c'
369srcs += 'flashrom.c'
370srcs += 'fmap.c'
371srcs += 'helpers.c'
372srcs += 'ich_descriptors.c'
373srcs += 'jedec.c'
374srcs += 'layout.c'
Edward O'Callaghand712e0b2021-01-07 21:07:47 +1100375srcs += 'libflashrom.c'
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000376srcs += 'opaque.c'
377srcs += 'print.c'
378srcs += 'programmer.c'
Edward O'Callaghan61fa4372021-01-07 21:06:36 +1100379srcs += 's25f.c'
Edward O'Callaghan6f944b22020-10-03 00:37:18 +1000380srcs += 'sfdp.c'
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000381srcs += 'spi25.c'
382srcs += 'spi25_statusreg.c'
Edward O'Callaghan6f944b22020-10-03 00:37:18 +1000383srcs += 'spi95.c'
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000384srcs += 'spi.c'
385srcs += 'sst28sf040.c'
386srcs += 'sst49lfxxxc.c'
387srcs += 'sst_fwhub.c'
Edward O'Callaghan6f944b22020-10-03 00:37:18 +1000388srcs += 'stm50.c'
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000389srcs += 'udelay.c'
390srcs += 'w29ee011.c'
391srcs += 'w39.c'
Edward O'Callaghan4fb8e282020-11-27 20:44:56 +1100392srcs += 'writeprotect.c'
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000393
394mapfile = 'libflashrom.map'
395vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
Daniel Campello054a16d2021-03-17 18:03:28 -0600396flashrom = library(
Edward O'Callaghand712e0b2021-01-07 21:07:47 +1100397 'flashrom',
398 sources : [
399 srcs,
400 ],
401 soversion : lt_current,
402 version : lt_version,
403 dependencies : [
404 deps,
405 ],
406 c_args : [
407 cargs,
408 ],
409 install : true,
410 link_args : vflag,
411 link_depends : mapfile,
412)
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000413
414version = meson.project_version()
415#strip leading characters
416if version.startswith('v')
417 version = version.split('v')[1]
418endif
419if version.startswith('p')
420 version = version.split('p')[1]
421endif
422
Edward O'Callaghand712e0b2021-01-07 21:07:47 +1100423pkgg = import('pkgconfig')
424pkgg.generate(
425 libraries : flashrom,
426 version : version,
427 name : 'flashrom',
428 filebase : 'flashrom',
429 description : 'library to interact with flashrom',
430)
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000431
Edward O'Callaghan4fb8e282020-11-27 20:44:56 +1100432conf.set('VERSION', version)
433conf.set('MAN_DATE', run_command('util/getrevision.sh', '--date', 'flashrom.8.tmpl').stdout().strip())
434configure_file(
435 input : 'flashrom.8.tmpl',
436 output : 'flashrom.8',
437 configuration : conf,
438 install: true,
439 install_dir: join_paths(mandir, 'man8'),
440)
441
442
Daniel Campello438b9c92021-03-16 15:28:14 -0600443if config_print_wiki
444 srcs += 'print_wiki.c'
445 cargs += '-DCONFIG_PRINT_WIKI=1'
446endif
447
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000448# we can't just link_with libflashrom as we require all the internal symbols...
449executable(
450 'flashrom',
451 sources : [
452 srcs,
453 'cli_classic.c',
454 'cli_common.c',
455 'cli_output.c',
456 'flashrom.c',
457 ],
458 dependencies : [
459 deps,
460 ],
461 c_args : [
462 cargs,
Edward O'Callaghan9a4e9ab2020-04-17 11:05:07 +1000463 '-DCONFIG_DEFAULT_PROGRAMMER=PROGRAMMER_INVALID',
464 '-DCONFIG_DEFAULT_PROGRAMMER_ARGS=""',
465 ],
466 install : true,
467 install_dir : sbindir,
468)
469
Edward O'Callaghan62704c12020-04-21 18:08:26 +1000470#subdir('util')
Edward O'Callaghan6a2abda2020-05-20 20:10:20 +1000471
472# unit-test framework
473cmocka_dep = dependency(
474 'cmocka',
475 fallback: ['cmocka', 'cmocka_dep']
476)
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 ],
485 dependencies : [
486 deps,
487 ],
488)
489
490subdir('tests')