blob: 29a57a9a392bbff607ee560ac9e7f2c99080a7e2 [file] [log] [blame]
Richard Hughescb973682018-12-19 11:44:22 +00001project('flashromutils', 'c',
Samuel R. Messner21bcfa92022-02-17 06:17:31 +01002 version : run_command('util/getversion.sh', '--version').stdout().strip(),
Nico Huberb417c0c2019-09-24 22:12:40 +02003 license : 'GPL-2.0',
Angel Pons30649432021-01-26 10:21:46 +01004 meson_version : '>=0.50.0',
Richard Hughescb973682018-12-19 11:44:22 +00005 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')
Rosen Penev566193f2020-07-18 12:50:16 -070028add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c') # required for fileno, nanosleep, and strndup
Richard Hughescb973682018-12-19 11:44:22 +000029add_project_arguments('-D_BSD_SOURCE', language : 'c') # required for glibc < v2.19
30add_project_arguments('-DFLASHROM_VERSION="' + meson.project_version() + '"', language : 'c')
31
Thomas Heijligend6d96c12021-10-12 16:47:43 +020032if host_machine.endian() == 'little'
33 add_project_arguments('-D__FLASHROM_LITTLE_ENDIAN__=1', language : 'c')
34endif
35if host_machine.endian() == 'big'
36 add_project_arguments('-D__FLASHROM_BIG_ENDIAN__=1', language : 'c')
37endif
38
Thomas Heijligen847d94b2021-10-12 17:38:01 +020039if host_machine.system() in ['cygwin', 'windows']
40 add_project_arguments('-DIS_WINDOWS=1', language : 'c')
41else
42 add_project_arguments('-DIS_WINDOWS=0', language : 'c')
43endif
44
Richard Hughescb973682018-12-19 11:44:22 +000045# get defaults from configure
46config_atahpt = get_option('config_atahpt')
47config_atapromise = get_option('config_atapromise')
48config_atavia = get_option('config_atavia')
49config_buspirate_spi = get_option('config_buspirate_spi')
50config_ch341a_spi = get_option('config_ch341a_spi')
51config_dediprog = get_option('config_dediprog')
52config_developerbox_spi = get_option('config_developerbox_spi')
53config_digilent_spi = get_option('config_digilent_spi')
Jean THOMASe28d8e42022-10-11 17:54:30 +020054config_dirtyjtag_spi = get_option('config_dirtyjtag_spi')
Richard Hughescb973682018-12-19 11:44:22 +000055config_drkaiser = get_option('config_drkaiser')
56config_dummy = get_option('config_dummy')
57config_ft2232_spi = get_option('config_ft2232_spi')
58config_gfxnvidia = get_option('config_gfxnvidia')
59config_internal = get_option('config_internal')
60config_it8212 = get_option('config_it8212')
Marc Schink7ec2d632020-12-08 22:20:50 +010061config_jlink_spi = get_option('config_jlink_spi')
Richard Hughescb973682018-12-19 11:44:22 +000062config_linux_mtd = get_option('config_linux_mtd')
63config_linux_spi = get_option('config_linux_spi')
64config_mstarddc_spi = get_option('config_mstarddc_spi')
65config_nic3com = get_option('config_nic3com')
66config_nicintel_eeprom = get_option('config_nicintel_eeprom')
67config_nicintel = get_option('config_nicintel')
68config_nicintel_spi = get_option('config_nicintel_spi')
69config_nicnatsemi = get_option('config_nicnatsemi')
70config_nicrealtek = get_option('config_nicrealtek')
71config_ogp_spi = get_option('config_ogp_spi')
72config_pickit2_spi = get_option('config_pickit2_spi')
73config_pony_spi = get_option('config_pony_spi')
74config_rayer_spi = get_option('config_rayer_spi')
75config_satamv = get_option('config_satamv')
76config_satasii = get_option('config_satasii')
77config_serprog = get_option('config_serprog')
78config_usbblaster_spi = get_option('config_usbblaster_spi')
Miklós Márton324929c2019-08-01 19:14:10 +020079config_stlinkv3_spi = get_option('config_stlinkv3_spi')
Thomas Heijligen84e9c912021-06-01 16:22:14 +020080config_default_programmer_name = get_option('default_programmer_name')
81config_default_programmer_args = get_option('default_programmer_args')
Daniel Campellof7a84fd2021-03-16 17:17:14 -060082config_print_wiki= get_option('print_wiki')
Richard Hughescb973682018-12-19 11:44:22 +000083
84cargs = []
85deps = []
86srcs = []
87
Richard Hughescb973682018-12-19 11:44:22 +000088need_raw_access = false
89need_serial = false
90
91# check for required symbols
92if cc.has_function('clock_gettime')
93 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
94endif
95if cc.has_function('strnlen')
96 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
97endif
98if cc.check_header('sys/utsname.h')
99 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
100endif
101
102# some programmers require libusb
103if get_option('usb')
104 srcs += 'usbdev.c'
105 deps += dependency('libusb-1.0')
106else
107 config_ch341a_spi = false
108 config_dediprog = false
109 config_digilent_spi = false
Jean THOMASe28d8e42022-10-11 17:54:30 +0200110 config_dirtyjtag_spi = false
Richard Hughescb973682018-12-19 11:44:22 +0000111 config_developerbox_spi = false
Thomas Heijligenb221cd72019-04-05 15:08:35 +0200112 config_pickit2_spi = false
Richard Hughescb973682018-12-19 11:44:22 +0000113endif
114
115# some programmers require libpci
116if get_option('pciutils')
117 srcs += 'pcidev.c'
118 deps += dependency('libpci')
Daniel Campello924e6312021-03-17 09:14:11 -0600119 need_raw_access = true
Richard Hughescb973682018-12-19 11:44:22 +0000120 cargs += '-DNEED_PCI=1'
121else
122 config_atahpt = false
123 config_atapromise = false
124 config_atavia = false
125 config_drkaiser = false
126 config_gfxnvidia = false
127 config_internal = false
128 config_it8212 = false
129 config_nic3com = false
130 config_nicintel_eeprom = false
131 config_nicintel = false
132 config_nicintel_spi = false
133 config_nicnatsemi = false
134 config_nicrealtek = false
135 config_ogp_spi = false
Richard Hughescb973682018-12-19 11:44:22 +0000136 config_satamv = false
137 config_satasii = false
138endif
139
140# set defines for configured programmers
141if config_atahpt
142 srcs += 'atahpt.c'
143 cargs += '-DCONFIG_ATAHPT=1'
144endif
145if config_atapromise
146 srcs += 'atapromise.c'
147 cargs += '-DCONFIG_ATAPROMISE=1'
148endif
149if config_atavia
150 srcs += 'atavia.c'
151 cargs += '-DCONFIG_ATAVIA=1'
152endif
153if config_buspirate_spi
154 srcs += 'buspirate_spi.c'
155 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
156 need_serial = true
157endif
158if config_ch341a_spi
159 srcs += 'ch341a_spi.c'
160 cargs += '-DCONFIG_CH341A_SPI=1'
161endif
162if config_dediprog
163 srcs += 'dediprog.c'
164 cargs += '-DCONFIG_DEDIPROG=1'
165endif
166if config_developerbox_spi
167 srcs += 'developerbox_spi.c'
168 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
169endif
170if config_digilent_spi
171 srcs += 'digilent_spi.c'
172 cargs += '-DCONFIG_DIGILENT_SPI=1'
173endif
Jean THOMASe28d8e42022-10-11 17:54:30 +0200174if config_dirtyjtag_spi
175 srcs += 'dirtyjtag_spi.c'
176 cargs += '-DCONFIG_DIRTYJTAG_SPI=1'
177endif
Richard Hughescb973682018-12-19 11:44:22 +0000178if config_drkaiser
179 srcs += 'drkaiser.c'
180 cargs += '-DCONFIG_DRKAISER=1'
181endif
182if config_dummy
183 srcs += 'dummyflasher.c'
184 cargs += '-DCONFIG_DUMMY=1'
185endif
186if config_ft2232_spi
187 srcs += 'ft2232_spi.c'
188 cargs += '-DCONFIG_FT2232_SPI=1'
189 deps += dependency('libftdi1')
190 cargs += '-DHAVE_FT232H=1'
191endif
192if config_gfxnvidia
193 srcs += 'gfxnvidia.c'
194 cargs += '-DCONFIG_GFXNVIDIA=1'
195endif
196if config_internal
197 srcs += 'board_enable.c'
198 srcs += 'cbtable.c'
199 srcs += 'chipset_enable.c'
200 srcs += 'internal.c'
201 srcs += 'processor_enable.c'
202 if target_machine.cpu_family() == 'x86' or target_machine.cpu_family() == 'x86_64'
203 srcs += 'amd_imc.c'
204 srcs += 'dmi.c'
205 srcs += 'ichspi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000206 srcs += 'it87spi.c'
207 srcs += 'mcp6x_spi.c'
208 srcs += 'sb600spi.c'
209 srcs += 'wbsio_spi.c'
210 endif
211 config_bitbang_spi = true
212 cargs += '-DCONFIG_INTERNAL=1'
213 if get_option('config_internal_dmi')
214 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
215 cargs += '-DCONFIG_INTERNAL_DMI=1'
216 endif
217endif
218if config_it8212
219 srcs += 'it8212.c'
220 cargs += '-DCONFIG_IT8212=1'
221endif
Marc Schink7ec2d632020-12-08 22:20:50 +0100222if config_jlink_spi
223 srcs += 'jlink_spi.c'
224 cargs += '-DCONFIG_JLINK_SPI=1'
225 deps += dependency('libjaylink')
226endif
Richard Hughescb973682018-12-19 11:44:22 +0000227if config_linux_mtd
228 srcs += 'linux_mtd.c'
229 cargs += '-DCONFIG_LINUX_MTD=1'
230endif
231if config_linux_spi
232 srcs += 'linux_spi.c'
233 cargs += '-DCONFIG_LINUX_SPI=1'
234endif
235if config_mstarddc_spi
236 srcs += 'mstarddc_spi.c'
237 cargs += '-DCONFIG_MSTARDDC_SPI=1'
238endif
239if config_nic3com
240 srcs += 'nic3com.c'
241 cargs += '-DCONFIG_NIC3COM=1'
242endif
243if config_nicintel
244 srcs += 'nicintel.c'
245 cargs += '-DCONFIG_NICINTEL=1'
246endif
247if config_nicintel_eeprom
248 srcs += 'nicintel_eeprom.c'
249 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
250endif
251if config_nicintel_spi
252 srcs += 'nicintel_spi.c'
253 config_bitbang_spi = true
254 cargs += '-DCONFIG_NICINTEL_SPI=1'
255endif
256if config_nicnatsemi
257 srcs += 'nicnatsemi.c'
258 cargs += '-DCONFIG_NICNATSEMI=1'
259endif
260if config_nicrealtek
261 srcs += 'nicrealtek.c'
262 cargs += '-DCONFIG_NICREALTEK=1'
263endif
264if config_ogp_spi
265 config_bitbang_spi = true
266 srcs += 'ogp_spi.c'
267 cargs += '-DCONFIG_OGP_SPI=1'
268endif
269if config_pickit2_spi
270 srcs += 'pickit2_spi.c'
271 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000272endif
273if config_pony_spi
274 srcs += 'pony_spi.c'
275 need_serial = true
276 config_bitbang_spi = true
277 cargs += '-DCONFIG_PONY_SPI=1'
278endif
279if config_rayer_spi
280 srcs += 'rayer_spi.c'
281 config_bitbang_spi = true
282 need_raw_access = true
283 cargs += '-DCONFIG_RAYER_SPI=1'
284endif
285if config_satamv
286 srcs += 'satamv.c'
287 cargs += '-DCONFIG_SATAMV=1'
288endif
289if config_satasii
290 srcs += 'satasii.c'
291 cargs += '-DCONFIG_SATASII=1'
292endif
293if config_serprog
294 srcs += 'serprog.c'
295 cargs += '-DCONFIG_SERPROG=1'
296 need_serial = true
297endif
298if config_usbblaster_spi
299 srcs += 'usbblaster_spi.c'
300 cargs += '-DCONFIG_USBBLASTER_SPI=1'
301endif
Miklós Márton324929c2019-08-01 19:14:10 +0200302if config_stlinkv3_spi
303 srcs += 'stlinkv3_spi.c'
304 cargs += '-DCONFIG_STLINKV3_SPI=1'
305endif
Richard Hughescb973682018-12-19 11:44:22 +0000306
307# bitbanging SPI infrastructure
308if config_bitbang_spi
309 srcs += 'bitbang_spi.c'
310 cargs += '-DCONFIG_BITBANG_SPI=1'
311endif
312
313# raw memory, MSR or PCI port I/O access
314if need_raw_access
315 srcs += 'hwaccess.c'
316 srcs += 'physmap.c'
317 cargs += '-DNEED_RAW_ACCESS=1'
318endif
319
320# raw serial IO
321if need_serial
Richard Hughescb973682018-12-19 11:44:22 +0000322 srcs += 'serial.c'
Thomas Heijligen140c1262021-09-27 15:12:26 +0200323 if host_machine.system() == 'linux'
324 srcs += 'custom_baud_linux.c'
325 else
326 srcs += 'custom_baud.c'
327 endif
Richard Hughescb973682018-12-19 11:44:22 +0000328endif
329
Richard Hughescb973682018-12-19 11:44:22 +0000330prefix = get_option('prefix')
331sbindir = join_paths(prefix, get_option('sbindir'))
332libdir = join_paths(prefix, get_option('libdir'))
Richard Hughesdad3a162020-02-17 09:57:01 +0000333mandir = join_paths(prefix, get_option('mandir'))
Richard Hughescb973682018-12-19 11:44:22 +0000334
335install_headers([
336 'libflashrom.h',
337 ],
338)
339
340# core modules needed by both the library and the CLI
341srcs += '82802ab.c'
342srcs += 'at45db.c'
343srcs += 'edi.c'
344srcs += 'en29lv640b.c'
345srcs += 'flashchips.c'
346srcs += 'flashrom.c'
347srcs += 'fmap.c'
348srcs += 'helpers.c'
349srcs += 'ich_descriptors.c'
350srcs += 'jedec.c'
351srcs += 'layout.c'
352srcs += 'libflashrom.c'
353srcs += 'opaque.c'
354srcs += 'print.c'
355srcs += 'programmer.c'
Thomas Heijligenbbfacff2021-03-31 20:40:01 +0200356srcs += 'programmer_table.c'
Richard Hughescb973682018-12-19 11:44:22 +0000357srcs += 'sfdp.c'
358srcs += 'spi25.c'
359srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700360srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000361srcs += 'spi.c'
362srcs += 'sst28sf040.c'
363srcs += 'sst49lfxxxc.c'
364srcs += 'sst_fwhub.c'
365srcs += 'stm50.c'
366srcs += 'udelay.c'
367srcs += 'w29ee011.c'
368srcs += 'w39.c'
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100369srcs += 'writeprotect.c'
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100370srcs += 'writeprotect_ranges.c'
Richard Hughescb973682018-12-19 11:44:22 +0000371
372mapfile = 'libflashrom.map'
373vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
Daniel Campello4bcc9a32021-03-17 18:03:28 -0600374flashrom = library(
Richard Hughescb973682018-12-19 11:44:22 +0000375 'flashrom',
376 sources : [
377 srcs,
378 ],
379 soversion : lt_current,
380 version : lt_version,
381 dependencies : [
382 deps,
383 ],
384 c_args : [
385 cargs,
386 ],
387 install : true,
388 link_args : vflag,
389 link_depends : mapfile,
390)
391
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500392version = meson.project_version()
393#strip leading characters
394if version.startswith('v')
395 version = version.split('v')[1]
396endif
397if version.startswith('p')
398 version = version.split('p')[1]
399endif
400
Richard Hughescb973682018-12-19 11:44:22 +0000401pkgg = import('pkgconfig')
402pkgg.generate(
403 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500404 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500405 name : 'flashrom',
406 filebase : 'flashrom',
407 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000408)
409
Richard Hughesdad3a162020-02-17 09:57:01 +0000410conf.set('VERSION', version)
Samuel R. Messner21bcfa92022-02-17 06:17:31 +0100411conf.set('MAN_DATE', run_command('util/getversion.sh', '--man-date').stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000412configure_file(
413 input : 'flashrom.8.tmpl',
414 output : 'flashrom.8',
415 configuration : conf,
416 install: true,
417 install_dir: join_paths(mandir, 'man8'),
418)
419
Richard Hughescb973682018-12-19 11:44:22 +0000420flashrom_dep = declare_dependency(
421 link_with : flashrom,
422 include_directories : include_directories('.'),
423 dependencies : deps
424)
425
Thomas Heijligen84e9c912021-06-01 16:22:14 +0200426if config_default_programmer_name != ''
427 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
428else
429 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
430endif
431
432cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
433
Daniel Campellof7a84fd2021-03-16 17:17:14 -0600434if config_print_wiki
435 srcs += 'print_wiki.c'
436 cargs += '-DCONFIG_PRINT_WIKI=1'
437endif
438
Richard Hughescb973682018-12-19 11:44:22 +0000439# we can't just link_with libflashrom as we require all the internal symbols...
440executable(
441 'flashrom',
442 sources : [
443 srcs,
444 'cli_classic.c',
445 'cli_common.c',
446 'cli_output.c',
447 'flashrom.c',
448 ],
449 dependencies : [
450 deps,
451 ],
452 c_args : [
453 cargs,
Richard Hughescb973682018-12-19 11:44:22 +0000454 ],
455 install : true,
456 install_dir : sbindir,
457)
458
459subdir('util')