blob: c312ca688e978c34ffaad705ee7debdac70e1b9c [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')
41config_drkaiser = get_option('config_drkaiser')
42config_dummy = get_option('config_dummy')
43config_ft2232_spi = get_option('config_ft2232_spi')
44config_gfxnvidia = get_option('config_gfxnvidia')
45config_internal = get_option('config_internal')
46config_it8212 = get_option('config_it8212')
47config_linux_mtd = get_option('config_linux_mtd')
48config_linux_spi = get_option('config_linux_spi')
49config_mstarddc_spi = get_option('config_mstarddc_spi')
50config_nic3com = get_option('config_nic3com')
51config_nicintel_eeprom = get_option('config_nicintel_eeprom')
52config_nicintel = get_option('config_nicintel')
53config_nicintel_spi = get_option('config_nicintel_spi')
54config_nicnatsemi = get_option('config_nicnatsemi')
55config_nicrealtek = get_option('config_nicrealtek')
56config_ogp_spi = get_option('config_ogp_spi')
57config_pickit2_spi = get_option('config_pickit2_spi')
58config_pony_spi = get_option('config_pony_spi')
59config_rayer_spi = get_option('config_rayer_spi')
60config_satamv = get_option('config_satamv')
61config_satasii = get_option('config_satasii')
62config_serprog = get_option('config_serprog')
63config_usbblaster_spi = get_option('config_usbblaster_spi')
Miklós Márton324929c2019-08-01 19:14:10 +020064config_stlinkv3_spi = get_option('config_stlinkv3_spi')
Richard Hughescb973682018-12-19 11:44:22 +000065
66cargs = []
67deps = []
68srcs = []
69
Richard Hughescb973682018-12-19 11:44:22 +000070need_raw_access = false
71need_serial = false
72
73# check for required symbols
74if cc.has_function('clock_gettime')
75 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
76endif
77if cc.has_function('strnlen')
78 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
79endif
80if cc.check_header('sys/utsname.h')
81 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
82endif
83
84# some programmers require libusb
85if get_option('usb')
86 srcs += 'usbdev.c'
87 deps += dependency('libusb-1.0')
88else
89 config_ch341a_spi = false
90 config_dediprog = false
91 config_digilent_spi = false
92 config_developerbox_spi = false
Thomas Heijligenb221cd72019-04-05 15:08:35 +020093 config_pickit2_spi = false
Richard Hughescb973682018-12-19 11:44:22 +000094endif
95
96# some programmers require libpci
97if get_option('pciutils')
98 srcs += 'pcidev.c'
99 deps += dependency('libpci')
100 cargs += '-DNEED_PCI=1'
101else
102 config_atahpt = false
103 config_atapromise = false
104 config_atavia = false
105 config_drkaiser = false
106 config_gfxnvidia = false
107 config_internal = false
108 config_it8212 = false
109 config_nic3com = false
110 config_nicintel_eeprom = false
111 config_nicintel = false
112 config_nicintel_spi = false
113 config_nicnatsemi = false
114 config_nicrealtek = false
115 config_ogp_spi = false
116 config_rayer_spi = false
117 config_satamv = false
118 config_satasii = false
119endif
120
121# set defines for configured programmers
122if config_atahpt
123 srcs += 'atahpt.c'
124 cargs += '-DCONFIG_ATAHPT=1'
125endif
126if config_atapromise
127 srcs += 'atapromise.c'
128 cargs += '-DCONFIG_ATAPROMISE=1'
129endif
130if config_atavia
131 srcs += 'atavia.c'
132 cargs += '-DCONFIG_ATAVIA=1'
133endif
134if config_buspirate_spi
135 srcs += 'buspirate_spi.c'
136 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
137 need_serial = true
138endif
139if config_ch341a_spi
140 srcs += 'ch341a_spi.c'
141 cargs += '-DCONFIG_CH341A_SPI=1'
142endif
143if config_dediprog
144 srcs += 'dediprog.c'
145 cargs += '-DCONFIG_DEDIPROG=1'
146endif
147if config_developerbox_spi
148 srcs += 'developerbox_spi.c'
149 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
150endif
151if config_digilent_spi
152 srcs += 'digilent_spi.c'
153 cargs += '-DCONFIG_DIGILENT_SPI=1'
154endif
155if config_drkaiser
156 srcs += 'drkaiser.c'
157 cargs += '-DCONFIG_DRKAISER=1'
158endif
159if config_dummy
160 srcs += 'dummyflasher.c'
161 cargs += '-DCONFIG_DUMMY=1'
162endif
163if config_ft2232_spi
164 srcs += 'ft2232_spi.c'
165 cargs += '-DCONFIG_FT2232_SPI=1'
166 deps += dependency('libftdi1')
167 cargs += '-DHAVE_FT232H=1'
168endif
169if config_gfxnvidia
170 srcs += 'gfxnvidia.c'
171 cargs += '-DCONFIG_GFXNVIDIA=1'
172endif
173if config_internal
174 srcs += 'board_enable.c'
175 srcs += 'cbtable.c'
176 srcs += 'chipset_enable.c'
177 srcs += 'internal.c'
178 srcs += 'processor_enable.c'
179 if target_machine.cpu_family() == 'x86' or target_machine.cpu_family() == 'x86_64'
180 srcs += 'amd_imc.c'
181 srcs += 'dmi.c'
182 srcs += 'ichspi.c'
183 srcs += 'it85spi.c'
184 srcs += 'it87spi.c'
185 srcs += 'mcp6x_spi.c'
186 srcs += 'sb600spi.c'
187 srcs += 'wbsio_spi.c'
188 endif
189 config_bitbang_spi = true
190 cargs += '-DCONFIG_INTERNAL=1'
191 if get_option('config_internal_dmi')
192 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
193 cargs += '-DCONFIG_INTERNAL_DMI=1'
194 endif
195endif
196if config_it8212
197 srcs += 'it8212.c'
198 cargs += '-DCONFIG_IT8212=1'
199endif
200if config_linux_mtd
201 srcs += 'linux_mtd.c'
202 cargs += '-DCONFIG_LINUX_MTD=1'
203endif
204if config_linux_spi
205 srcs += 'linux_spi.c'
206 cargs += '-DCONFIG_LINUX_SPI=1'
207endif
208if config_mstarddc_spi
209 srcs += 'mstarddc_spi.c'
210 cargs += '-DCONFIG_MSTARDDC_SPI=1'
211endif
212if config_nic3com
213 srcs += 'nic3com.c'
214 cargs += '-DCONFIG_NIC3COM=1'
215endif
216if config_nicintel
217 srcs += 'nicintel.c'
218 cargs += '-DCONFIG_NICINTEL=1'
219endif
220if config_nicintel_eeprom
221 srcs += 'nicintel_eeprom.c'
222 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
223endif
224if config_nicintel_spi
225 srcs += 'nicintel_spi.c'
226 config_bitbang_spi = true
227 cargs += '-DCONFIG_NICINTEL_SPI=1'
228endif
229if config_nicnatsemi
230 srcs += 'nicnatsemi.c'
231 cargs += '-DCONFIG_NICNATSEMI=1'
232endif
233if config_nicrealtek
234 srcs += 'nicrealtek.c'
235 cargs += '-DCONFIG_NICREALTEK=1'
236endif
237if config_ogp_spi
238 config_bitbang_spi = true
239 srcs += 'ogp_spi.c'
240 cargs += '-DCONFIG_OGP_SPI=1'
241endif
242if config_pickit2_spi
243 srcs += 'pickit2_spi.c'
244 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000245endif
246if config_pony_spi
247 srcs += 'pony_spi.c'
248 need_serial = true
249 config_bitbang_spi = true
250 cargs += '-DCONFIG_PONY_SPI=1'
251endif
252if config_rayer_spi
253 srcs += 'rayer_spi.c'
254 config_bitbang_spi = true
255 need_raw_access = true
256 cargs += '-DCONFIG_RAYER_SPI=1'
257endif
258if config_satamv
259 srcs += 'satamv.c'
260 cargs += '-DCONFIG_SATAMV=1'
261endif
262if config_satasii
263 srcs += 'satasii.c'
264 cargs += '-DCONFIG_SATASII=1'
265endif
266if config_serprog
267 srcs += 'serprog.c'
268 cargs += '-DCONFIG_SERPROG=1'
269 need_serial = true
270endif
271if config_usbblaster_spi
272 srcs += 'usbblaster_spi.c'
273 cargs += '-DCONFIG_USBBLASTER_SPI=1'
274endif
Miklós Márton324929c2019-08-01 19:14:10 +0200275if config_stlinkv3_spi
276 srcs += 'stlinkv3_spi.c'
277 cargs += '-DCONFIG_STLINKV3_SPI=1'
278endif
Richard Hughescb973682018-12-19 11:44:22 +0000279
280# bitbanging SPI infrastructure
281if config_bitbang_spi
282 srcs += 'bitbang_spi.c'
283 cargs += '-DCONFIG_BITBANG_SPI=1'
284endif
285
286# raw memory, MSR or PCI port I/O access
287if need_raw_access
288 srcs += 'hwaccess.c'
289 srcs += 'physmap.c'
290 cargs += '-DNEED_RAW_ACCESS=1'
291endif
292
293# raw serial IO
294if need_serial
295 srcs += 'custom_baud.c'
296 srcs += 'serial.c'
297endif
298
Richard Hughescb973682018-12-19 11:44:22 +0000299prefix = get_option('prefix')
300sbindir = join_paths(prefix, get_option('sbindir'))
301libdir = join_paths(prefix, get_option('libdir'))
302
303install_headers([
304 'libflashrom.h',
305 ],
306)
307
308# core modules needed by both the library and the CLI
309srcs += '82802ab.c'
310srcs += 'at45db.c'
311srcs += 'edi.c'
312srcs += 'en29lv640b.c'
313srcs += 'flashchips.c'
314srcs += 'flashrom.c'
315srcs += 'fmap.c'
316srcs += 'helpers.c'
317srcs += 'ich_descriptors.c'
318srcs += 'jedec.c'
319srcs += 'layout.c'
320srcs += 'libflashrom.c'
321srcs += 'opaque.c'
322srcs += 'print.c'
323srcs += 'programmer.c'
324srcs += 'sfdp.c'
325srcs += 'spi25.c'
326srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700327srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000328srcs += 'spi.c'
329srcs += 'sst28sf040.c'
330srcs += 'sst49lfxxxc.c'
331srcs += 'sst_fwhub.c'
332srcs += 'stm50.c'
333srcs += 'udelay.c'
334srcs += 'w29ee011.c'
335srcs += 'w39.c'
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100336srcs += 'writeprotect.c'
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100337srcs += 'writeprotect_ranges.c'
Richard Hughescb973682018-12-19 11:44:22 +0000338
339mapfile = 'libflashrom.map'
340vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
341flashrom = shared_library(
342 'flashrom',
343 sources : [
344 srcs,
345 ],
346 soversion : lt_current,
347 version : lt_version,
348 dependencies : [
349 deps,
350 ],
351 c_args : [
352 cargs,
353 ],
354 install : true,
355 link_args : vflag,
356 link_depends : mapfile,
357)
358
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500359version = meson.project_version()
360#strip leading characters
361if version.startswith('v')
362 version = version.split('v')[1]
363endif
364if version.startswith('p')
365 version = version.split('p')[1]
366endif
367
Richard Hughescb973682018-12-19 11:44:22 +0000368pkgg = import('pkgconfig')
369pkgg.generate(
370 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500371 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500372 name : 'flashrom',
373 filebase : 'flashrom',
374 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000375)
376
377flashrom_dep = declare_dependency(
378 link_with : flashrom,
379 include_directories : include_directories('.'),
380 dependencies : deps
381)
382
383# we can't just link_with libflashrom as we require all the internal symbols...
384executable(
385 'flashrom',
386 sources : [
387 srcs,
388 'cli_classic.c',
389 'cli_common.c',
390 'cli_output.c',
391 'flashrom.c',
392 ],
393 dependencies : [
394 deps,
395 ],
396 c_args : [
397 cargs,
398 '-DSTANDALONE',
399 '-DCONFIG_DEFAULT_PROGRAMMER=PROGRAMMER_INVALID',
400 '-DCONFIG_DEFAULT_PROGRAMMER_ARGS=""',
401 ],
402 install : true,
403 install_dir : sbindir,
404)
405
406subdir('util')