blob: 28f15a029301458c1c8b58ecb2f1cba62de3d856 [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
Richard Hughescb973682018-12-19 11:44:22 +000039# get defaults from configure
40config_atahpt = get_option('config_atahpt')
41config_atapromise = get_option('config_atapromise')
42config_atavia = get_option('config_atavia')
43config_buspirate_spi = get_option('config_buspirate_spi')
44config_ch341a_spi = get_option('config_ch341a_spi')
45config_dediprog = get_option('config_dediprog')
46config_developerbox_spi = get_option('config_developerbox_spi')
47config_digilent_spi = get_option('config_digilent_spi')
Jean THOMASe28d8e42022-10-11 17:54:30 +020048config_dirtyjtag_spi = get_option('config_dirtyjtag_spi')
Richard Hughescb973682018-12-19 11:44:22 +000049config_drkaiser = get_option('config_drkaiser')
50config_dummy = get_option('config_dummy')
51config_ft2232_spi = get_option('config_ft2232_spi')
52config_gfxnvidia = get_option('config_gfxnvidia')
53config_internal = get_option('config_internal')
54config_it8212 = get_option('config_it8212')
Marc Schink7ec2d632020-12-08 22:20:50 +010055config_jlink_spi = get_option('config_jlink_spi')
Richard Hughescb973682018-12-19 11:44:22 +000056config_linux_mtd = get_option('config_linux_mtd')
57config_linux_spi = get_option('config_linux_spi')
58config_mstarddc_spi = get_option('config_mstarddc_spi')
59config_nic3com = get_option('config_nic3com')
60config_nicintel_eeprom = get_option('config_nicintel_eeprom')
61config_nicintel = get_option('config_nicintel')
62config_nicintel_spi = get_option('config_nicintel_spi')
63config_nicnatsemi = get_option('config_nicnatsemi')
64config_nicrealtek = get_option('config_nicrealtek')
65config_ogp_spi = get_option('config_ogp_spi')
66config_pickit2_spi = get_option('config_pickit2_spi')
67config_pony_spi = get_option('config_pony_spi')
68config_rayer_spi = get_option('config_rayer_spi')
69config_satamv = get_option('config_satamv')
70config_satasii = get_option('config_satasii')
71config_serprog = get_option('config_serprog')
72config_usbblaster_spi = get_option('config_usbblaster_spi')
Miklós Márton324929c2019-08-01 19:14:10 +020073config_stlinkv3_spi = get_option('config_stlinkv3_spi')
Thomas Heijligen84e9c912021-06-01 16:22:14 +020074config_default_programmer_name = get_option('default_programmer_name')
75config_default_programmer_args = get_option('default_programmer_args')
Daniel Campellof7a84fd2021-03-16 17:17:14 -060076config_print_wiki= get_option('print_wiki')
Richard Hughescb973682018-12-19 11:44:22 +000077
78cargs = []
79deps = []
80srcs = []
81
Richard Hughescb973682018-12-19 11:44:22 +000082need_raw_access = false
83need_serial = false
84
85# check for required symbols
86if cc.has_function('clock_gettime')
87 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
88endif
89if cc.has_function('strnlen')
90 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
91endif
92if cc.check_header('sys/utsname.h')
93 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
94endif
95
96# some programmers require libusb
97if get_option('usb')
98 srcs += 'usbdev.c'
99 deps += dependency('libusb-1.0')
100else
101 config_ch341a_spi = false
102 config_dediprog = false
103 config_digilent_spi = false
Jean THOMASe28d8e42022-10-11 17:54:30 +0200104 config_dirtyjtag_spi = false
Richard Hughescb973682018-12-19 11:44:22 +0000105 config_developerbox_spi = false
Thomas Heijligenb221cd72019-04-05 15:08:35 +0200106 config_pickit2_spi = false
Richard Hughescb973682018-12-19 11:44:22 +0000107endif
108
109# some programmers require libpci
110if get_option('pciutils')
111 srcs += 'pcidev.c'
112 deps += dependency('libpci')
Daniel Campello924e6312021-03-17 09:14:11 -0600113 need_raw_access = true
Richard Hughescb973682018-12-19 11:44:22 +0000114 cargs += '-DNEED_PCI=1'
115else
116 config_atahpt = false
117 config_atapromise = false
118 config_atavia = false
119 config_drkaiser = false
120 config_gfxnvidia = false
121 config_internal = false
122 config_it8212 = false
123 config_nic3com = false
124 config_nicintel_eeprom = false
125 config_nicintel = false
126 config_nicintel_spi = false
127 config_nicnatsemi = false
128 config_nicrealtek = false
129 config_ogp_spi = false
Richard Hughescb973682018-12-19 11:44:22 +0000130 config_satamv = false
131 config_satasii = false
132endif
133
134# set defines for configured programmers
135if config_atahpt
136 srcs += 'atahpt.c'
137 cargs += '-DCONFIG_ATAHPT=1'
138endif
139if config_atapromise
140 srcs += 'atapromise.c'
141 cargs += '-DCONFIG_ATAPROMISE=1'
142endif
143if config_atavia
144 srcs += 'atavia.c'
145 cargs += '-DCONFIG_ATAVIA=1'
146endif
147if config_buspirate_spi
148 srcs += 'buspirate_spi.c'
149 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
150 need_serial = true
151endif
152if config_ch341a_spi
153 srcs += 'ch341a_spi.c'
154 cargs += '-DCONFIG_CH341A_SPI=1'
155endif
156if config_dediprog
157 srcs += 'dediprog.c'
158 cargs += '-DCONFIG_DEDIPROG=1'
159endif
160if config_developerbox_spi
161 srcs += 'developerbox_spi.c'
162 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
163endif
164if config_digilent_spi
165 srcs += 'digilent_spi.c'
166 cargs += '-DCONFIG_DIGILENT_SPI=1'
167endif
Jean THOMASe28d8e42022-10-11 17:54:30 +0200168if config_dirtyjtag_spi
169 srcs += 'dirtyjtag_spi.c'
170 cargs += '-DCONFIG_DIRTYJTAG_SPI=1'
171endif
Richard Hughescb973682018-12-19 11:44:22 +0000172if config_drkaiser
173 srcs += 'drkaiser.c'
174 cargs += '-DCONFIG_DRKAISER=1'
175endif
176if config_dummy
177 srcs += 'dummyflasher.c'
178 cargs += '-DCONFIG_DUMMY=1'
179endif
180if config_ft2232_spi
181 srcs += 'ft2232_spi.c'
182 cargs += '-DCONFIG_FT2232_SPI=1'
183 deps += dependency('libftdi1')
184 cargs += '-DHAVE_FT232H=1'
185endif
186if config_gfxnvidia
187 srcs += 'gfxnvidia.c'
188 cargs += '-DCONFIG_GFXNVIDIA=1'
189endif
190if config_internal
191 srcs += 'board_enable.c'
192 srcs += 'cbtable.c'
193 srcs += 'chipset_enable.c'
194 srcs += 'internal.c'
195 srcs += 'processor_enable.c'
196 if target_machine.cpu_family() == 'x86' or target_machine.cpu_family() == 'x86_64'
197 srcs += 'amd_imc.c'
198 srcs += 'dmi.c'
199 srcs += 'ichspi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000200 srcs += 'it87spi.c'
201 srcs += 'mcp6x_spi.c'
202 srcs += 'sb600spi.c'
203 srcs += 'wbsio_spi.c'
204 endif
205 config_bitbang_spi = true
206 cargs += '-DCONFIG_INTERNAL=1'
207 if get_option('config_internal_dmi')
208 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
209 cargs += '-DCONFIG_INTERNAL_DMI=1'
210 endif
211endif
212if config_it8212
213 srcs += 'it8212.c'
214 cargs += '-DCONFIG_IT8212=1'
215endif
Marc Schink7ec2d632020-12-08 22:20:50 +0100216if config_jlink_spi
217 srcs += 'jlink_spi.c'
218 cargs += '-DCONFIG_JLINK_SPI=1'
219 deps += dependency('libjaylink')
220endif
Richard Hughescb973682018-12-19 11:44:22 +0000221if config_linux_mtd
222 srcs += 'linux_mtd.c'
223 cargs += '-DCONFIG_LINUX_MTD=1'
224endif
225if config_linux_spi
226 srcs += 'linux_spi.c'
227 cargs += '-DCONFIG_LINUX_SPI=1'
228endif
229if config_mstarddc_spi
230 srcs += 'mstarddc_spi.c'
231 cargs += '-DCONFIG_MSTARDDC_SPI=1'
232endif
233if config_nic3com
234 srcs += 'nic3com.c'
235 cargs += '-DCONFIG_NIC3COM=1'
236endif
237if config_nicintel
238 srcs += 'nicintel.c'
239 cargs += '-DCONFIG_NICINTEL=1'
240endif
241if config_nicintel_eeprom
242 srcs += 'nicintel_eeprom.c'
243 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
244endif
245if config_nicintel_spi
246 srcs += 'nicintel_spi.c'
247 config_bitbang_spi = true
248 cargs += '-DCONFIG_NICINTEL_SPI=1'
249endif
250if config_nicnatsemi
251 srcs += 'nicnatsemi.c'
252 cargs += '-DCONFIG_NICNATSEMI=1'
253endif
254if config_nicrealtek
255 srcs += 'nicrealtek.c'
256 cargs += '-DCONFIG_NICREALTEK=1'
257endif
258if config_ogp_spi
259 config_bitbang_spi = true
260 srcs += 'ogp_spi.c'
261 cargs += '-DCONFIG_OGP_SPI=1'
262endif
263if config_pickit2_spi
264 srcs += 'pickit2_spi.c'
265 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000266endif
267if config_pony_spi
268 srcs += 'pony_spi.c'
269 need_serial = true
270 config_bitbang_spi = true
271 cargs += '-DCONFIG_PONY_SPI=1'
272endif
273if config_rayer_spi
274 srcs += 'rayer_spi.c'
275 config_bitbang_spi = true
276 need_raw_access = true
277 cargs += '-DCONFIG_RAYER_SPI=1'
278endif
279if config_satamv
280 srcs += 'satamv.c'
281 cargs += '-DCONFIG_SATAMV=1'
282endif
283if config_satasii
284 srcs += 'satasii.c'
285 cargs += '-DCONFIG_SATASII=1'
286endif
287if config_serprog
288 srcs += 'serprog.c'
289 cargs += '-DCONFIG_SERPROG=1'
290 need_serial = true
291endif
292if config_usbblaster_spi
293 srcs += 'usbblaster_spi.c'
294 cargs += '-DCONFIG_USBBLASTER_SPI=1'
295endif
Miklós Márton324929c2019-08-01 19:14:10 +0200296if config_stlinkv3_spi
297 srcs += 'stlinkv3_spi.c'
298 cargs += '-DCONFIG_STLINKV3_SPI=1'
299endif
Richard Hughescb973682018-12-19 11:44:22 +0000300
301# bitbanging SPI infrastructure
302if config_bitbang_spi
303 srcs += 'bitbang_spi.c'
304 cargs += '-DCONFIG_BITBANG_SPI=1'
305endif
306
307# raw memory, MSR or PCI port I/O access
308if need_raw_access
309 srcs += 'hwaccess.c'
310 srcs += 'physmap.c'
311 cargs += '-DNEED_RAW_ACCESS=1'
312endif
313
314# raw serial IO
315if need_serial
Richard Hughescb973682018-12-19 11:44:22 +0000316 srcs += 'serial.c'
Thomas Heijligen140c1262021-09-27 15:12:26 +0200317 if host_machine.system() == 'linux'
318 srcs += 'custom_baud_linux.c'
319 else
320 srcs += 'custom_baud.c'
321 endif
Richard Hughescb973682018-12-19 11:44:22 +0000322endif
323
Richard Hughescb973682018-12-19 11:44:22 +0000324prefix = get_option('prefix')
325sbindir = join_paths(prefix, get_option('sbindir'))
326libdir = join_paths(prefix, get_option('libdir'))
Richard Hughesdad3a162020-02-17 09:57:01 +0000327mandir = join_paths(prefix, get_option('mandir'))
Richard Hughescb973682018-12-19 11:44:22 +0000328
329install_headers([
330 'libflashrom.h',
331 ],
332)
333
334# core modules needed by both the library and the CLI
335srcs += '82802ab.c'
336srcs += 'at45db.c'
337srcs += 'edi.c'
338srcs += 'en29lv640b.c'
339srcs += 'flashchips.c'
340srcs += 'flashrom.c'
341srcs += 'fmap.c'
342srcs += 'helpers.c'
343srcs += 'ich_descriptors.c'
344srcs += 'jedec.c'
345srcs += 'layout.c'
346srcs += 'libflashrom.c'
347srcs += 'opaque.c'
348srcs += 'print.c'
349srcs += 'programmer.c'
Thomas Heijligenbbfacff2021-03-31 20:40:01 +0200350srcs += 'programmer_table.c'
Richard Hughescb973682018-12-19 11:44:22 +0000351srcs += 'sfdp.c'
352srcs += 'spi25.c'
353srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700354srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000355srcs += 'spi.c'
356srcs += 'sst28sf040.c'
357srcs += 'sst49lfxxxc.c'
358srcs += 'sst_fwhub.c'
359srcs += 'stm50.c'
360srcs += 'udelay.c'
361srcs += 'w29ee011.c'
362srcs += 'w39.c'
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100363srcs += 'writeprotect.c'
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100364srcs += 'writeprotect_ranges.c'
Richard Hughescb973682018-12-19 11:44:22 +0000365
366mapfile = 'libflashrom.map'
367vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
Daniel Campello4bcc9a32021-03-17 18:03:28 -0600368flashrom = library(
Richard Hughescb973682018-12-19 11:44:22 +0000369 'flashrom',
370 sources : [
371 srcs,
372 ],
373 soversion : lt_current,
374 version : lt_version,
375 dependencies : [
376 deps,
377 ],
378 c_args : [
379 cargs,
380 ],
381 install : true,
382 link_args : vflag,
383 link_depends : mapfile,
384)
385
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500386version = meson.project_version()
387#strip leading characters
388if version.startswith('v')
389 version = version.split('v')[1]
390endif
391if version.startswith('p')
392 version = version.split('p')[1]
393endif
394
Richard Hughescb973682018-12-19 11:44:22 +0000395pkgg = import('pkgconfig')
396pkgg.generate(
397 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500398 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500399 name : 'flashrom',
400 filebase : 'flashrom',
401 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000402)
403
Richard Hughesdad3a162020-02-17 09:57:01 +0000404conf.set('VERSION', version)
Samuel R. Messner21bcfa92022-02-17 06:17:31 +0100405conf.set('MAN_DATE', run_command('util/getversion.sh', '--man-date').stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000406configure_file(
407 input : 'flashrom.8.tmpl',
408 output : 'flashrom.8',
409 configuration : conf,
410 install: true,
411 install_dir: join_paths(mandir, 'man8'),
412)
413
Richard Hughescb973682018-12-19 11:44:22 +0000414flashrom_dep = declare_dependency(
415 link_with : flashrom,
416 include_directories : include_directories('.'),
417 dependencies : deps
418)
419
Thomas Heijligen84e9c912021-06-01 16:22:14 +0200420if config_default_programmer_name != ''
421 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
422else
423 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
424endif
425
426cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
427
Daniel Campellof7a84fd2021-03-16 17:17:14 -0600428if config_print_wiki
429 srcs += 'print_wiki.c'
430 cargs += '-DCONFIG_PRINT_WIKI=1'
431endif
432
Richard Hughescb973682018-12-19 11:44:22 +0000433# we can't just link_with libflashrom as we require all the internal symbols...
434executable(
435 'flashrom',
436 sources : [
437 srcs,
438 'cli_classic.c',
439 'cli_common.c',
440 'cli_output.c',
441 'flashrom.c',
442 ],
443 dependencies : [
444 deps,
445 ],
446 c_args : [
447 cargs,
Richard Hughescb973682018-12-19 11:44:22 +0000448 ],
449 install : true,
450 install_dir : sbindir,
451)
452
453subdir('util')