blob: f76f53d928a4c7dfa65e907cd1aeb3a683d7a5ea [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',
Richard Hughescb973682018-12-19 11:44:22 +00004 meson_version : '>=0.47.0',
5 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')
28add_project_arguments('-D_POSIX_C_SOURCE', language : 'c') # required for fileno
29add_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')
Jean THOMASe28d8e42022-10-11 17:54:30 +020041config_dirtyjtag_spi = get_option('config_dirtyjtag_spi')
Richard Hughescb973682018-12-19 11:44:22 +000042config_drkaiser = get_option('config_drkaiser')
43config_dummy = get_option('config_dummy')
44config_ft2232_spi = get_option('config_ft2232_spi')
45config_gfxnvidia = get_option('config_gfxnvidia')
46config_internal = get_option('config_internal')
47config_it8212 = get_option('config_it8212')
48config_linux_mtd = get_option('config_linux_mtd')
49config_linux_spi = get_option('config_linux_spi')
50config_mstarddc_spi = get_option('config_mstarddc_spi')
51config_nic3com = get_option('config_nic3com')
52config_nicintel_eeprom = get_option('config_nicintel_eeprom')
53config_nicintel = get_option('config_nicintel')
54config_nicintel_spi = get_option('config_nicintel_spi')
55config_nicnatsemi = get_option('config_nicnatsemi')
56config_nicrealtek = get_option('config_nicrealtek')
57config_ogp_spi = get_option('config_ogp_spi')
58config_pickit2_spi = get_option('config_pickit2_spi')
59config_pony_spi = get_option('config_pony_spi')
60config_rayer_spi = get_option('config_rayer_spi')
61config_satamv = get_option('config_satamv')
62config_satasii = get_option('config_satasii')
63config_serprog = get_option('config_serprog')
64config_usbblaster_spi = get_option('config_usbblaster_spi')
Miklós Márton324929c2019-08-01 19:14:10 +020065config_stlinkv3_spi = get_option('config_stlinkv3_spi')
Thomas Heijligen84e9c912021-06-01 16:22:14 +020066config_default_programmer_name = get_option('default_programmer_name')
67config_default_programmer_args = get_option('default_programmer_args')
Richard Hughescb973682018-12-19 11:44:22 +000068
69cargs = []
70deps = []
71srcs = []
72
Richard Hughescb973682018-12-19 11:44:22 +000073need_raw_access = false
74need_serial = false
75
76# check for required symbols
77if cc.has_function('clock_gettime')
78 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
79endif
80if cc.has_function('strnlen')
81 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
82endif
83if cc.check_header('sys/utsname.h')
84 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
85endif
86
87# some programmers require libusb
88if get_option('usb')
89 srcs += 'usbdev.c'
90 deps += dependency('libusb-1.0')
91else
92 config_ch341a_spi = false
93 config_dediprog = false
94 config_digilent_spi = false
Jean THOMASe28d8e42022-10-11 17:54:30 +020095 config_dirtyjtag_spi = false
Richard Hughescb973682018-12-19 11:44:22 +000096 config_developerbox_spi = false
Thomas Heijligenb221cd72019-04-05 15:08:35 +020097 config_pickit2_spi = false
Richard Hughescb973682018-12-19 11:44:22 +000098endif
99
100# some programmers require libpci
101if get_option('pciutils')
102 srcs += 'pcidev.c'
103 deps += dependency('libpci')
104 cargs += '-DNEED_PCI=1'
105else
106 config_atahpt = false
107 config_atapromise = false
108 config_atavia = false
109 config_drkaiser = false
110 config_gfxnvidia = false
111 config_internal = false
112 config_it8212 = false
113 config_nic3com = false
114 config_nicintel_eeprom = false
115 config_nicintel = false
116 config_nicintel_spi = false
117 config_nicnatsemi = false
118 config_nicrealtek = false
119 config_ogp_spi = false
120 config_rayer_spi = false
121 config_satamv = false
122 config_satasii = false
123endif
124
125# set defines for configured programmers
126if config_atahpt
127 srcs += 'atahpt.c'
128 cargs += '-DCONFIG_ATAHPT=1'
129endif
130if config_atapromise
131 srcs += 'atapromise.c'
132 cargs += '-DCONFIG_ATAPROMISE=1'
133endif
134if config_atavia
135 srcs += 'atavia.c'
136 cargs += '-DCONFIG_ATAVIA=1'
137endif
138if config_buspirate_spi
139 srcs += 'buspirate_spi.c'
140 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
141 need_serial = true
142endif
143if config_ch341a_spi
144 srcs += 'ch341a_spi.c'
145 cargs += '-DCONFIG_CH341A_SPI=1'
146endif
147if config_dediprog
148 srcs += 'dediprog.c'
149 cargs += '-DCONFIG_DEDIPROG=1'
150endif
151if config_developerbox_spi
152 srcs += 'developerbox_spi.c'
153 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
154endif
155if config_digilent_spi
156 srcs += 'digilent_spi.c'
157 cargs += '-DCONFIG_DIGILENT_SPI=1'
158endif
Jean THOMASe28d8e42022-10-11 17:54:30 +0200159if config_dirtyjtag_spi
160 srcs += 'dirtyjtag_spi.c'
161 cargs += '-DCONFIG_DIRTYJTAG_SPI=1'
162endif
Richard Hughescb973682018-12-19 11:44:22 +0000163if config_drkaiser
164 srcs += 'drkaiser.c'
165 cargs += '-DCONFIG_DRKAISER=1'
166endif
167if config_dummy
168 srcs += 'dummyflasher.c'
169 cargs += '-DCONFIG_DUMMY=1'
170endif
171if config_ft2232_spi
172 srcs += 'ft2232_spi.c'
173 cargs += '-DCONFIG_FT2232_SPI=1'
174 deps += dependency('libftdi1')
175 cargs += '-DHAVE_FT232H=1'
176endif
177if config_gfxnvidia
178 srcs += 'gfxnvidia.c'
179 cargs += '-DCONFIG_GFXNVIDIA=1'
180endif
181if config_internal
182 srcs += 'board_enable.c'
183 srcs += 'cbtable.c'
184 srcs += 'chipset_enable.c'
185 srcs += 'internal.c'
186 srcs += 'processor_enable.c'
187 if target_machine.cpu_family() == 'x86' or target_machine.cpu_family() == 'x86_64'
188 srcs += 'amd_imc.c'
189 srcs += 'dmi.c'
190 srcs += 'ichspi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000191 srcs += 'it87spi.c'
192 srcs += 'mcp6x_spi.c'
193 srcs += 'sb600spi.c'
194 srcs += 'wbsio_spi.c'
195 endif
196 config_bitbang_spi = true
197 cargs += '-DCONFIG_INTERNAL=1'
198 if get_option('config_internal_dmi')
199 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
200 cargs += '-DCONFIG_INTERNAL_DMI=1'
201 endif
202endif
203if config_it8212
204 srcs += 'it8212.c'
205 cargs += '-DCONFIG_IT8212=1'
206endif
207if config_linux_mtd
208 srcs += 'linux_mtd.c'
209 cargs += '-DCONFIG_LINUX_MTD=1'
210endif
211if config_linux_spi
212 srcs += 'linux_spi.c'
213 cargs += '-DCONFIG_LINUX_SPI=1'
214endif
215if config_mstarddc_spi
216 srcs += 'mstarddc_spi.c'
217 cargs += '-DCONFIG_MSTARDDC_SPI=1'
218endif
219if config_nic3com
220 srcs += 'nic3com.c'
221 cargs += '-DCONFIG_NIC3COM=1'
222endif
223if config_nicintel
224 srcs += 'nicintel.c'
225 cargs += '-DCONFIG_NICINTEL=1'
226endif
227if config_nicintel_eeprom
228 srcs += 'nicintel_eeprom.c'
229 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
230endif
231if config_nicintel_spi
232 srcs += 'nicintel_spi.c'
233 config_bitbang_spi = true
234 cargs += '-DCONFIG_NICINTEL_SPI=1'
235endif
236if config_nicnatsemi
237 srcs += 'nicnatsemi.c'
238 cargs += '-DCONFIG_NICNATSEMI=1'
239endif
240if config_nicrealtek
241 srcs += 'nicrealtek.c'
242 cargs += '-DCONFIG_NICREALTEK=1'
243endif
244if config_ogp_spi
245 config_bitbang_spi = true
246 srcs += 'ogp_spi.c'
247 cargs += '-DCONFIG_OGP_SPI=1'
248endif
249if config_pickit2_spi
250 srcs += 'pickit2_spi.c'
251 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000252endif
253if config_pony_spi
254 srcs += 'pony_spi.c'
255 need_serial = true
256 config_bitbang_spi = true
257 cargs += '-DCONFIG_PONY_SPI=1'
258endif
259if config_rayer_spi
260 srcs += 'rayer_spi.c'
261 config_bitbang_spi = true
262 need_raw_access = true
263 cargs += '-DCONFIG_RAYER_SPI=1'
264endif
265if config_satamv
266 srcs += 'satamv.c'
267 cargs += '-DCONFIG_SATAMV=1'
268endif
269if config_satasii
270 srcs += 'satasii.c'
271 cargs += '-DCONFIG_SATASII=1'
272endif
273if config_serprog
274 srcs += 'serprog.c'
275 cargs += '-DCONFIG_SERPROG=1'
276 need_serial = true
277endif
278if config_usbblaster_spi
279 srcs += 'usbblaster_spi.c'
280 cargs += '-DCONFIG_USBBLASTER_SPI=1'
281endif
Miklós Márton324929c2019-08-01 19:14:10 +0200282if config_stlinkv3_spi
283 srcs += 'stlinkv3_spi.c'
284 cargs += '-DCONFIG_STLINKV3_SPI=1'
285endif
Richard Hughescb973682018-12-19 11:44:22 +0000286
287# bitbanging SPI infrastructure
288if config_bitbang_spi
289 srcs += 'bitbang_spi.c'
290 cargs += '-DCONFIG_BITBANG_SPI=1'
291endif
292
293# raw memory, MSR or PCI port I/O access
294if need_raw_access
295 srcs += 'hwaccess.c'
296 srcs += 'physmap.c'
297 cargs += '-DNEED_RAW_ACCESS=1'
298endif
299
300# raw serial IO
301if need_serial
Richard Hughescb973682018-12-19 11:44:22 +0000302 srcs += 'serial.c'
Thomas Heijligen140c1262021-09-27 15:12:26 +0200303 if host_machine.system() == 'linux'
304 srcs += 'custom_baud_linux.c'
305 else
306 srcs += 'custom_baud.c'
307 endif
Richard Hughescb973682018-12-19 11:44:22 +0000308endif
309
Richard Hughescb973682018-12-19 11:44:22 +0000310prefix = get_option('prefix')
311sbindir = join_paths(prefix, get_option('sbindir'))
312libdir = join_paths(prefix, get_option('libdir'))
Richard Hughesdad3a162020-02-17 09:57:01 +0000313mandir = join_paths(prefix, get_option('mandir'))
Richard Hughescb973682018-12-19 11:44:22 +0000314
315install_headers([
316 'libflashrom.h',
317 ],
318)
319
320# core modules needed by both the library and the CLI
321srcs += '82802ab.c'
322srcs += 'at45db.c'
323srcs += 'edi.c'
324srcs += 'en29lv640b.c'
325srcs += 'flashchips.c'
326srcs += 'flashrom.c'
327srcs += 'fmap.c'
328srcs += 'helpers.c'
329srcs += 'ich_descriptors.c'
330srcs += 'jedec.c'
331srcs += 'layout.c'
332srcs += 'libflashrom.c'
333srcs += 'opaque.c'
334srcs += 'print.c'
335srcs += 'programmer.c'
Thomas Heijligenbbfacff2021-03-31 20:40:01 +0200336srcs += 'programmer_table.c'
Richard Hughescb973682018-12-19 11:44:22 +0000337srcs += 'sfdp.c'
338srcs += 'spi25.c'
339srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700340srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000341srcs += 'spi.c'
342srcs += 'sst28sf040.c'
343srcs += 'sst49lfxxxc.c'
344srcs += 'sst_fwhub.c'
345srcs += 'stm50.c'
346srcs += 'udelay.c'
347srcs += 'w29ee011.c'
348srcs += 'w39.c'
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100349srcs += 'writeprotect.c'
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100350srcs += 'writeprotect_ranges.c'
Richard Hughescb973682018-12-19 11:44:22 +0000351
352mapfile = 'libflashrom.map'
353vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
354flashrom = shared_library(
355 'flashrom',
356 sources : [
357 srcs,
358 ],
359 soversion : lt_current,
360 version : lt_version,
361 dependencies : [
362 deps,
363 ],
364 c_args : [
365 cargs,
366 ],
367 install : true,
368 link_args : vflag,
369 link_depends : mapfile,
370)
371
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500372version = meson.project_version()
373#strip leading characters
374if version.startswith('v')
375 version = version.split('v')[1]
376endif
377if version.startswith('p')
378 version = version.split('p')[1]
379endif
380
Richard Hughescb973682018-12-19 11:44:22 +0000381pkgg = import('pkgconfig')
382pkgg.generate(
383 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500384 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500385 name : 'flashrom',
386 filebase : 'flashrom',
387 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000388)
389
Richard Hughesdad3a162020-02-17 09:57:01 +0000390conf.set('VERSION', version)
391conf.set('MAN_DATE', run_command('util/getrevision.sh', '--date', 'flashrom.8.tmpl').stdout().strip())
392configure_file(
393 input : 'flashrom.8.tmpl',
394 output : 'flashrom.8',
395 configuration : conf,
396 install: true,
397 install_dir: join_paths(mandir, 'man8'),
398)
399
Richard Hughescb973682018-12-19 11:44:22 +0000400flashrom_dep = declare_dependency(
401 link_with : flashrom,
402 include_directories : include_directories('.'),
403 dependencies : deps
404)
405
Thomas Heijligen84e9c912021-06-01 16:22:14 +0200406if config_default_programmer_name != ''
407 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
408else
409 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
410endif
411
412cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
413
Richard Hughescb973682018-12-19 11:44:22 +0000414# we can't just link_with libflashrom as we require all the internal symbols...
415executable(
416 'flashrom',
417 sources : [
418 srcs,
419 'cli_classic.c',
420 'cli_common.c',
421 'cli_output.c',
422 'flashrom.c',
423 ],
424 dependencies : [
425 deps,
426 ],
427 c_args : [
428 cargs,
429 '-DSTANDALONE',
Richard Hughescb973682018-12-19 11:44:22 +0000430 ],
431 install : true,
432 install_dir : sbindir,
433)
434
435subdir('util')