blob: 443cdcc9458a42fa2b85c0c3ccc0a6fadbc70419 [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'
Richard Hughescb973682018-12-19 11:44:22 +0000185 srcs += 'it87spi.c'
186 srcs += 'mcp6x_spi.c'
187 srcs += 'sb600spi.c'
188 srcs += 'wbsio_spi.c'
189 endif
190 config_bitbang_spi = true
191 cargs += '-DCONFIG_INTERNAL=1'
192 if get_option('config_internal_dmi')
193 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
194 cargs += '-DCONFIG_INTERNAL_DMI=1'
195 endif
196endif
197if config_it8212
198 srcs += 'it8212.c'
199 cargs += '-DCONFIG_IT8212=1'
200endif
201if config_linux_mtd
202 srcs += 'linux_mtd.c'
203 cargs += '-DCONFIG_LINUX_MTD=1'
204endif
205if config_linux_spi
206 srcs += 'linux_spi.c'
207 cargs += '-DCONFIG_LINUX_SPI=1'
208endif
209if config_mstarddc_spi
210 srcs += 'mstarddc_spi.c'
211 cargs += '-DCONFIG_MSTARDDC_SPI=1'
212endif
213if config_nic3com
214 srcs += 'nic3com.c'
215 cargs += '-DCONFIG_NIC3COM=1'
216endif
217if config_nicintel
218 srcs += 'nicintel.c'
219 cargs += '-DCONFIG_NICINTEL=1'
220endif
221if config_nicintel_eeprom
222 srcs += 'nicintel_eeprom.c'
223 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
224endif
225if config_nicintel_spi
226 srcs += 'nicintel_spi.c'
227 config_bitbang_spi = true
228 cargs += '-DCONFIG_NICINTEL_SPI=1'
229endif
230if config_nicnatsemi
231 srcs += 'nicnatsemi.c'
232 cargs += '-DCONFIG_NICNATSEMI=1'
233endif
234if config_nicrealtek
235 srcs += 'nicrealtek.c'
236 cargs += '-DCONFIG_NICREALTEK=1'
237endif
238if config_ogp_spi
239 config_bitbang_spi = true
240 srcs += 'ogp_spi.c'
241 cargs += '-DCONFIG_OGP_SPI=1'
242endif
243if config_pickit2_spi
244 srcs += 'pickit2_spi.c'
245 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000246endif
247if config_pony_spi
248 srcs += 'pony_spi.c'
249 need_serial = true
250 config_bitbang_spi = true
251 cargs += '-DCONFIG_PONY_SPI=1'
252endif
253if config_rayer_spi
254 srcs += 'rayer_spi.c'
255 config_bitbang_spi = true
256 need_raw_access = true
257 cargs += '-DCONFIG_RAYER_SPI=1'
258endif
259if config_satamv
260 srcs += 'satamv.c'
261 cargs += '-DCONFIG_SATAMV=1'
262endif
263if config_satasii
264 srcs += 'satasii.c'
265 cargs += '-DCONFIG_SATASII=1'
266endif
267if config_serprog
268 srcs += 'serprog.c'
269 cargs += '-DCONFIG_SERPROG=1'
270 need_serial = true
271endif
272if config_usbblaster_spi
273 srcs += 'usbblaster_spi.c'
274 cargs += '-DCONFIG_USBBLASTER_SPI=1'
275endif
Miklós Márton324929c2019-08-01 19:14:10 +0200276if config_stlinkv3_spi
277 srcs += 'stlinkv3_spi.c'
278 cargs += '-DCONFIG_STLINKV3_SPI=1'
279endif
Richard Hughescb973682018-12-19 11:44:22 +0000280
281# bitbanging SPI infrastructure
282if config_bitbang_spi
283 srcs += 'bitbang_spi.c'
284 cargs += '-DCONFIG_BITBANG_SPI=1'
285endif
286
287# raw memory, MSR or PCI port I/O access
288if need_raw_access
289 srcs += 'hwaccess.c'
290 srcs += 'physmap.c'
291 cargs += '-DNEED_RAW_ACCESS=1'
292endif
293
294# raw serial IO
295if need_serial
Richard Hughescb973682018-12-19 11:44:22 +0000296 srcs += 'serial.c'
Thomas Heijligen140c1262021-09-27 15:12:26 +0200297 if host_machine.system() == 'linux'
298 srcs += 'custom_baud_linux.c'
299 else
300 srcs += 'custom_baud.c'
301 endif
Richard Hughescb973682018-12-19 11:44:22 +0000302endif
303
Richard Hughescb973682018-12-19 11:44:22 +0000304prefix = get_option('prefix')
305sbindir = join_paths(prefix, get_option('sbindir'))
306libdir = join_paths(prefix, get_option('libdir'))
307
308install_headers([
309 'libflashrom.h',
310 ],
311)
312
313# core modules needed by both the library and the CLI
314srcs += '82802ab.c'
315srcs += 'at45db.c'
316srcs += 'edi.c'
317srcs += 'en29lv640b.c'
318srcs += 'flashchips.c'
319srcs += 'flashrom.c'
320srcs += 'fmap.c'
321srcs += 'helpers.c'
322srcs += 'ich_descriptors.c'
323srcs += 'jedec.c'
324srcs += 'layout.c'
325srcs += 'libflashrom.c'
326srcs += 'opaque.c'
327srcs += 'print.c'
328srcs += 'programmer.c'
Thomas Heijligenbbfacff2021-03-31 20:40:01 +0200329srcs += 'programmer_table.c'
Richard Hughescb973682018-12-19 11:44:22 +0000330srcs += 'sfdp.c'
331srcs += 'spi25.c'
332srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700333srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000334srcs += 'spi.c'
335srcs += 'sst28sf040.c'
336srcs += 'sst49lfxxxc.c'
337srcs += 'sst_fwhub.c'
338srcs += 'stm50.c'
339srcs += 'udelay.c'
340srcs += 'w29ee011.c'
341srcs += 'w39.c'
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100342srcs += 'writeprotect.c'
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100343srcs += 'writeprotect_ranges.c'
Richard Hughescb973682018-12-19 11:44:22 +0000344
345mapfile = 'libflashrom.map'
346vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
347flashrom = shared_library(
348 'flashrom',
349 sources : [
350 srcs,
351 ],
352 soversion : lt_current,
353 version : lt_version,
354 dependencies : [
355 deps,
356 ],
357 c_args : [
358 cargs,
359 ],
360 install : true,
361 link_args : vflag,
362 link_depends : mapfile,
363)
364
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500365version = meson.project_version()
366#strip leading characters
367if version.startswith('v')
368 version = version.split('v')[1]
369endif
370if version.startswith('p')
371 version = version.split('p')[1]
372endif
373
Richard Hughescb973682018-12-19 11:44:22 +0000374pkgg = import('pkgconfig')
375pkgg.generate(
376 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500377 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500378 name : 'flashrom',
379 filebase : 'flashrom',
380 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000381)
382
383flashrom_dep = declare_dependency(
384 link_with : flashrom,
385 include_directories : include_directories('.'),
386 dependencies : deps
387)
388
Thomas Heijligen84e9c912021-06-01 16:22:14 +0200389if config_default_programmer_name != ''
390 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
391else
392 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
393endif
394
395cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
396
Richard Hughescb973682018-12-19 11:44:22 +0000397# we can't just link_with libflashrom as we require all the internal symbols...
398executable(
399 'flashrom',
400 sources : [
401 srcs,
402 'cli_classic.c',
403 'cli_common.c',
404 'cli_output.c',
405 'flashrom.c',
406 ],
407 dependencies : [
408 deps,
409 ],
410 c_args : [
411 cargs,
412 '-DSTANDALONE',
Richard Hughescb973682018-12-19 11:44:22 +0000413 ],
414 install : true,
415 install_dir : sbindir,
416)
417
418subdir('util')