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