blob: 6a9981f573a41c958b8db6ae91cb641510f85406 [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
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')
Jean THOMASe28d8e42022-10-11 17:54:30 +020041config_dirtyjtag_spi = get_option('config_dirtyjtag_spi')
Richard Hughescb973682018-12-19 11:44:22 +000042config_drkaiser = get_option('config_drkaiser')
43config_dummy = get_option('config_dummy')
44config_ft2232_spi = get_option('config_ft2232_spi')
45config_gfxnvidia = get_option('config_gfxnvidia')
46config_internal = get_option('config_internal')
47config_it8212 = get_option('config_it8212')
Marc Schink7ec2d632020-12-08 22:20:50 +010048config_jlink_spi = get_option('config_jlink_spi')
Richard Hughescb973682018-12-19 11:44:22 +000049config_linux_mtd = get_option('config_linux_mtd')
50config_linux_spi = get_option('config_linux_spi')
51config_mstarddc_spi = get_option('config_mstarddc_spi')
52config_nic3com = get_option('config_nic3com')
53config_nicintel_eeprom = get_option('config_nicintel_eeprom')
54config_nicintel = get_option('config_nicintel')
55config_nicintel_spi = get_option('config_nicintel_spi')
56config_nicnatsemi = get_option('config_nicnatsemi')
57config_nicrealtek = get_option('config_nicrealtek')
58config_ogp_spi = get_option('config_ogp_spi')
59config_pickit2_spi = get_option('config_pickit2_spi')
60config_pony_spi = get_option('config_pony_spi')
61config_rayer_spi = get_option('config_rayer_spi')
62config_satamv = get_option('config_satamv')
63config_satasii = get_option('config_satasii')
64config_serprog = get_option('config_serprog')
65config_usbblaster_spi = get_option('config_usbblaster_spi')
Miklós Márton324929c2019-08-01 19:14:10 +020066config_stlinkv3_spi = get_option('config_stlinkv3_spi')
Thomas Heijligen84e9c912021-06-01 16:22:14 +020067config_default_programmer_name = get_option('default_programmer_name')
68config_default_programmer_args = get_option('default_programmer_args')
Richard Hughescb973682018-12-19 11:44:22 +000069
70cargs = []
71deps = []
72srcs = []
73
Richard Hughescb973682018-12-19 11:44:22 +000074need_raw_access = false
75need_serial = false
76
77# check for required symbols
78if cc.has_function('clock_gettime')
79 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
80endif
81if cc.has_function('strnlen')
82 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
83endif
84if cc.check_header('sys/utsname.h')
85 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
86endif
87
88# some programmers require libusb
89if get_option('usb')
90 srcs += 'usbdev.c'
91 deps += dependency('libusb-1.0')
92else
93 config_ch341a_spi = false
94 config_dediprog = false
95 config_digilent_spi = false
Jean THOMASe28d8e42022-10-11 17:54:30 +020096 config_dirtyjtag_spi = false
Richard Hughescb973682018-12-19 11:44:22 +000097 config_developerbox_spi = false
Thomas Heijligenb221cd72019-04-05 15:08:35 +020098 config_pickit2_spi = false
Richard Hughescb973682018-12-19 11:44:22 +000099endif
100
101# some programmers require libpci
102if get_option('pciutils')
103 srcs += 'pcidev.c'
104 deps += dependency('libpci')
Daniel Campello924e6312021-03-17 09:14:11 -0600105 need_raw_access = true
Richard Hughescb973682018-12-19 11:44:22 +0000106 cargs += '-DNEED_PCI=1'
107else
108 config_atahpt = false
109 config_atapromise = false
110 config_atavia = false
111 config_drkaiser = false
112 config_gfxnvidia = false
113 config_internal = false
114 config_it8212 = false
115 config_nic3com = false
116 config_nicintel_eeprom = false
117 config_nicintel = false
118 config_nicintel_spi = false
119 config_nicnatsemi = false
120 config_nicrealtek = false
121 config_ogp_spi = false
Richard Hughescb973682018-12-19 11:44:22 +0000122 config_satamv = false
123 config_satasii = false
124endif
125
126# set defines for configured programmers
127if config_atahpt
128 srcs += 'atahpt.c'
129 cargs += '-DCONFIG_ATAHPT=1'
130endif
131if config_atapromise
132 srcs += 'atapromise.c'
133 cargs += '-DCONFIG_ATAPROMISE=1'
134endif
135if config_atavia
136 srcs += 'atavia.c'
137 cargs += '-DCONFIG_ATAVIA=1'
138endif
139if config_buspirate_spi
140 srcs += 'buspirate_spi.c'
141 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
142 need_serial = true
143endif
144if config_ch341a_spi
145 srcs += 'ch341a_spi.c'
146 cargs += '-DCONFIG_CH341A_SPI=1'
147endif
148if config_dediprog
149 srcs += 'dediprog.c'
150 cargs += '-DCONFIG_DEDIPROG=1'
151endif
152if config_developerbox_spi
153 srcs += 'developerbox_spi.c'
154 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
155endif
156if config_digilent_spi
157 srcs += 'digilent_spi.c'
158 cargs += '-DCONFIG_DIGILENT_SPI=1'
159endif
Jean THOMASe28d8e42022-10-11 17:54:30 +0200160if config_dirtyjtag_spi
161 srcs += 'dirtyjtag_spi.c'
162 cargs += '-DCONFIG_DIRTYJTAG_SPI=1'
163endif
Richard Hughescb973682018-12-19 11:44:22 +0000164if config_drkaiser
165 srcs += 'drkaiser.c'
166 cargs += '-DCONFIG_DRKAISER=1'
167endif
168if config_dummy
169 srcs += 'dummyflasher.c'
170 cargs += '-DCONFIG_DUMMY=1'
171endif
172if config_ft2232_spi
173 srcs += 'ft2232_spi.c'
174 cargs += '-DCONFIG_FT2232_SPI=1'
175 deps += dependency('libftdi1')
176 cargs += '-DHAVE_FT232H=1'
177endif
178if config_gfxnvidia
179 srcs += 'gfxnvidia.c'
180 cargs += '-DCONFIG_GFXNVIDIA=1'
181endif
182if config_internal
183 srcs += 'board_enable.c'
184 srcs += 'cbtable.c'
185 srcs += 'chipset_enable.c'
186 srcs += 'internal.c'
187 srcs += 'processor_enable.c'
188 if target_machine.cpu_family() == 'x86' or target_machine.cpu_family() == 'x86_64'
189 srcs += 'amd_imc.c'
190 srcs += 'dmi.c'
191 srcs += 'ichspi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000192 srcs += 'it87spi.c'
193 srcs += 'mcp6x_spi.c'
194 srcs += 'sb600spi.c'
195 srcs += 'wbsio_spi.c'
196 endif
197 config_bitbang_spi = true
198 cargs += '-DCONFIG_INTERNAL=1'
199 if get_option('config_internal_dmi')
200 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
201 cargs += '-DCONFIG_INTERNAL_DMI=1'
202 endif
203endif
204if config_it8212
205 srcs += 'it8212.c'
206 cargs += '-DCONFIG_IT8212=1'
207endif
Marc Schink7ec2d632020-12-08 22:20:50 +0100208if config_jlink_spi
209 srcs += 'jlink_spi.c'
210 cargs += '-DCONFIG_JLINK_SPI=1'
211 deps += dependency('libjaylink')
212endif
Richard Hughescb973682018-12-19 11:44:22 +0000213if config_linux_mtd
214 srcs += 'linux_mtd.c'
215 cargs += '-DCONFIG_LINUX_MTD=1'
216endif
217if config_linux_spi
218 srcs += 'linux_spi.c'
219 cargs += '-DCONFIG_LINUX_SPI=1'
220endif
221if config_mstarddc_spi
222 srcs += 'mstarddc_spi.c'
223 cargs += '-DCONFIG_MSTARDDC_SPI=1'
224endif
225if config_nic3com
226 srcs += 'nic3com.c'
227 cargs += '-DCONFIG_NIC3COM=1'
228endif
229if config_nicintel
230 srcs += 'nicintel.c'
231 cargs += '-DCONFIG_NICINTEL=1'
232endif
233if config_nicintel_eeprom
234 srcs += 'nicintel_eeprom.c'
235 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
236endif
237if config_nicintel_spi
238 srcs += 'nicintel_spi.c'
239 config_bitbang_spi = true
240 cargs += '-DCONFIG_NICINTEL_SPI=1'
241endif
242if config_nicnatsemi
243 srcs += 'nicnatsemi.c'
244 cargs += '-DCONFIG_NICNATSEMI=1'
245endif
246if config_nicrealtek
247 srcs += 'nicrealtek.c'
248 cargs += '-DCONFIG_NICREALTEK=1'
249endif
250if config_ogp_spi
251 config_bitbang_spi = true
252 srcs += 'ogp_spi.c'
253 cargs += '-DCONFIG_OGP_SPI=1'
254endif
255if config_pickit2_spi
256 srcs += 'pickit2_spi.c'
257 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000258endif
259if config_pony_spi
260 srcs += 'pony_spi.c'
261 need_serial = true
262 config_bitbang_spi = true
263 cargs += '-DCONFIG_PONY_SPI=1'
264endif
265if config_rayer_spi
266 srcs += 'rayer_spi.c'
267 config_bitbang_spi = true
268 need_raw_access = true
269 cargs += '-DCONFIG_RAYER_SPI=1'
270endif
271if config_satamv
272 srcs += 'satamv.c'
273 cargs += '-DCONFIG_SATAMV=1'
274endif
275if config_satasii
276 srcs += 'satasii.c'
277 cargs += '-DCONFIG_SATASII=1'
278endif
279if config_serprog
280 srcs += 'serprog.c'
281 cargs += '-DCONFIG_SERPROG=1'
282 need_serial = true
283endif
284if config_usbblaster_spi
285 srcs += 'usbblaster_spi.c'
286 cargs += '-DCONFIG_USBBLASTER_SPI=1'
287endif
Miklós Márton324929c2019-08-01 19:14:10 +0200288if config_stlinkv3_spi
289 srcs += 'stlinkv3_spi.c'
290 cargs += '-DCONFIG_STLINKV3_SPI=1'
291endif
Richard Hughescb973682018-12-19 11:44:22 +0000292
293# bitbanging SPI infrastructure
294if config_bitbang_spi
295 srcs += 'bitbang_spi.c'
296 cargs += '-DCONFIG_BITBANG_SPI=1'
297endif
298
299# raw memory, MSR or PCI port I/O access
300if need_raw_access
301 srcs += 'hwaccess.c'
302 srcs += 'physmap.c'
303 cargs += '-DNEED_RAW_ACCESS=1'
304endif
305
306# raw serial IO
307if need_serial
Richard Hughescb973682018-12-19 11:44:22 +0000308 srcs += 'serial.c'
Thomas Heijligen140c1262021-09-27 15:12:26 +0200309 if host_machine.system() == 'linux'
310 srcs += 'custom_baud_linux.c'
311 else
312 srcs += 'custom_baud.c'
313 endif
Richard Hughescb973682018-12-19 11:44:22 +0000314endif
315
Richard Hughescb973682018-12-19 11:44:22 +0000316prefix = get_option('prefix')
317sbindir = join_paths(prefix, get_option('sbindir'))
318libdir = join_paths(prefix, get_option('libdir'))
Richard Hughesdad3a162020-02-17 09:57:01 +0000319mandir = join_paths(prefix, get_option('mandir'))
Richard Hughescb973682018-12-19 11:44:22 +0000320
321install_headers([
322 'libflashrom.h',
323 ],
324)
325
326# core modules needed by both the library and the CLI
327srcs += '82802ab.c'
328srcs += 'at45db.c'
329srcs += 'edi.c'
330srcs += 'en29lv640b.c'
331srcs += 'flashchips.c'
332srcs += 'flashrom.c'
333srcs += 'fmap.c'
334srcs += 'helpers.c'
335srcs += 'ich_descriptors.c'
336srcs += 'jedec.c'
337srcs += 'layout.c'
338srcs += 'libflashrom.c'
339srcs += 'opaque.c'
340srcs += 'print.c'
341srcs += 'programmer.c'
Thomas Heijligenbbfacff2021-03-31 20:40:01 +0200342srcs += 'programmer_table.c'
Richard Hughescb973682018-12-19 11:44:22 +0000343srcs += 'sfdp.c'
344srcs += 'spi25.c'
345srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700346srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000347srcs += 'spi.c'
348srcs += 'sst28sf040.c'
349srcs += 'sst49lfxxxc.c'
350srcs += 'sst_fwhub.c'
351srcs += 'stm50.c'
352srcs += 'udelay.c'
353srcs += 'w29ee011.c'
354srcs += 'w39.c'
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100355srcs += 'writeprotect.c'
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100356srcs += 'writeprotect_ranges.c'
Richard Hughescb973682018-12-19 11:44:22 +0000357
358mapfile = 'libflashrom.map'
359vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
Daniel Campello4bcc9a32021-03-17 18:03:28 -0600360flashrom = library(
Richard Hughescb973682018-12-19 11:44:22 +0000361 'flashrom',
362 sources : [
363 srcs,
364 ],
365 soversion : lt_current,
366 version : lt_version,
367 dependencies : [
368 deps,
369 ],
370 c_args : [
371 cargs,
372 ],
373 install : true,
374 link_args : vflag,
375 link_depends : mapfile,
376)
377
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500378version = meson.project_version()
379#strip leading characters
380if version.startswith('v')
381 version = version.split('v')[1]
382endif
383if version.startswith('p')
384 version = version.split('p')[1]
385endif
386
Richard Hughescb973682018-12-19 11:44:22 +0000387pkgg = import('pkgconfig')
388pkgg.generate(
389 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500390 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500391 name : 'flashrom',
392 filebase : 'flashrom',
393 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000394)
395
Richard Hughesdad3a162020-02-17 09:57:01 +0000396conf.set('VERSION', version)
Samuel R. Messner21bcfa92022-02-17 06:17:31 +0100397conf.set('MAN_DATE', run_command('util/getversion.sh', '--man-date').stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000398configure_file(
399 input : 'flashrom.8.tmpl',
400 output : 'flashrom.8',
401 configuration : conf,
402 install: true,
403 install_dir: join_paths(mandir, 'man8'),
404)
405
Richard Hughescb973682018-12-19 11:44:22 +0000406flashrom_dep = declare_dependency(
407 link_with : flashrom,
408 include_directories : include_directories('.'),
409 dependencies : deps
410)
411
Thomas Heijligen84e9c912021-06-01 16:22:14 +0200412if config_default_programmer_name != ''
413 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
414else
415 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
416endif
417
418cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
419
Richard Hughescb973682018-12-19 11:44:22 +0000420# we can't just link_with libflashrom as we require all the internal symbols...
421executable(
422 'flashrom',
423 sources : [
424 srcs,
425 'cli_classic.c',
426 'cli_common.c',
427 'cli_output.c',
428 'flashrom.c',
429 ],
430 dependencies : [
431 deps,
432 ],
433 c_args : [
434 cargs,
Richard Hughescb973682018-12-19 11:44:22 +0000435 ],
436 install : true,
437 install_dir : sbindir,
438)
439
440subdir('util')