blob: 19b90c5b32de7e28adc75eb067db30d47d3754c5 [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
Thomas Heijligen433dc1c2021-10-12 17:58:35 +020045if host_machine.system() in ['linux', 'darwin', 'netbsd', 'openbsd']
46 add_project_arguments('-DUSE_IOPL=1', language : 'c')
47else
48 add_project_arguments('-DUSE_IOPL=0', language : 'c')
49endif
50
51if host_machine.system() in ['freebsd', 'dragonfly']
52 add_project_arguments('-DUSE_DEV_IO=1', language : 'c')
53else
54 add_project_arguments('-DUSE_DEV_IO=0', language : 'c')
55endif
56
57if host_machine.system() in ['gnu']
58 add_project_arguments('-DUSE_IOPERM=1', language : 'c')
59else
60 add_project_arguments('-DUSE_IOPERM=0', language : 'c')
61endif
62
Richard Hughescb973682018-12-19 11:44:22 +000063# get defaults from configure
64config_atahpt = get_option('config_atahpt')
65config_atapromise = get_option('config_atapromise')
66config_atavia = get_option('config_atavia')
67config_buspirate_spi = get_option('config_buspirate_spi')
68config_ch341a_spi = get_option('config_ch341a_spi')
69config_dediprog = get_option('config_dediprog')
70config_developerbox_spi = get_option('config_developerbox_spi')
71config_digilent_spi = get_option('config_digilent_spi')
Jean THOMASe28d8e42022-10-11 17:54:30 +020072config_dirtyjtag_spi = get_option('config_dirtyjtag_spi')
Richard Hughescb973682018-12-19 11:44:22 +000073config_drkaiser = get_option('config_drkaiser')
74config_dummy = get_option('config_dummy')
75config_ft2232_spi = get_option('config_ft2232_spi')
76config_gfxnvidia = get_option('config_gfxnvidia')
77config_internal = get_option('config_internal')
78config_it8212 = get_option('config_it8212')
Marc Schink7ec2d632020-12-08 22:20:50 +010079config_jlink_spi = get_option('config_jlink_spi')
Richard Hughescb973682018-12-19 11:44:22 +000080config_linux_mtd = get_option('config_linux_mtd')
81config_linux_spi = get_option('config_linux_spi')
82config_mstarddc_spi = get_option('config_mstarddc_spi')
83config_nic3com = get_option('config_nic3com')
84config_nicintel_eeprom = get_option('config_nicintel_eeprom')
85config_nicintel = get_option('config_nicintel')
86config_nicintel_spi = get_option('config_nicintel_spi')
87config_nicnatsemi = get_option('config_nicnatsemi')
88config_nicrealtek = get_option('config_nicrealtek')
89config_ogp_spi = get_option('config_ogp_spi')
90config_pickit2_spi = get_option('config_pickit2_spi')
91config_pony_spi = get_option('config_pony_spi')
92config_rayer_spi = get_option('config_rayer_spi')
93config_satamv = get_option('config_satamv')
94config_satasii = get_option('config_satasii')
95config_serprog = get_option('config_serprog')
96config_usbblaster_spi = get_option('config_usbblaster_spi')
Miklós Márton324929c2019-08-01 19:14:10 +020097config_stlinkv3_spi = get_option('config_stlinkv3_spi')
Thomas Heijligen84e9c912021-06-01 16:22:14 +020098config_default_programmer_name = get_option('default_programmer_name')
99config_default_programmer_args = get_option('default_programmer_args')
Daniel Campellof7a84fd2021-03-16 17:17:14 -0600100config_print_wiki= get_option('print_wiki')
Richard Hughescb973682018-12-19 11:44:22 +0000101
102cargs = []
103deps = []
104srcs = []
105
Peter Marheine306c8b72022-01-21 02:07:30 +0000106host_is_x86 = ['x86', 'x86_64'].contains(host_machine.cpu_family())
107
108need_serial = [
109 config_buspirate_spi, config_pony_spi, config_serprog,
110].contains(true)
111need_bitbang_spi = [
112 config_internal, config_nicintel_spi, config_ogp_spi,
113 config_pony_spi, config_rayer_spi,
114].contains(true)
115need_raw_mem_access = [
116 config_atapromise, config_drkaiser, config_gfxnvidia, config_internal,
117 config_it8212, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
118 config_ogp_spi, config_satamv, config_satasii,
119].contains(true)
120# Internal programmer uses x86 features if the system is x86
121need_x86_msr = config_internal and host_is_x86
122need_x86_port_io = [
123 config_atahpt, config_atapromise, config_internal and host_is_x86,
124 config_nic3com, config_nicnatsemi, config_nicrealtek, config_rayer_spi,
125 config_satamv,
126].contains(true)
127need_libpci = [
128 config_atahpt, config_atapromise, config_atavia,
129 config_drkaiser, config_gfxnvidia, config_internal, config_it8212,
130 config_nic3com, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
131 config_nicnatsemi, config_nicrealtek, config_ogp_spi, config_satamv,
132 config_satasii,
133].contains(true)
134need_libusb1 = [
135 config_ch341a_spi, config_dediprog, config_developerbox_spi,
136 config_digilent_spi, config_dirtyjtag_spi, config_pickit2_spi,
137 config_stlinkv3_spi,
138].contains(true)
139need_libftdi1 = [
140 config_ft2232_spi, config_usbblaster_spi,
141].contains(true)
142need_libjaylink = config_jlink_spi
143
144if (need_x86_port_io or need_x86_msr) and not host_is_x86
145 error('one or more enabled programmer only supports x86 and target is not')
146endif
147
Richard Hughescb973682018-12-19 11:44:22 +0000148
149# check for required symbols
150if cc.has_function('clock_gettime')
151 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
152endif
153if cc.has_function('strnlen')
154 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
155endif
156if cc.check_header('sys/utsname.h')
157 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
158endif
159
160# some programmers require libusb
161if get_option('usb')
162 srcs += 'usbdev.c'
163 deps += dependency('libusb-1.0')
Peter Marheine306c8b72022-01-21 02:07:30 +0000164elif need_libusb1
165 error('usb is disabled but one or more enabled programmer requires USB access')
Richard Hughescb973682018-12-19 11:44:22 +0000166endif
167
168# some programmers require libpci
169if get_option('pciutils')
170 srcs += 'pcidev.c'
171 deps += dependency('libpci')
172 cargs += '-DNEED_PCI=1'
Peter Marheine306c8b72022-01-21 02:07:30 +0000173elif need_libpci
174 error('pciutils is disabled but one or more enabled programmer requires PCI access')
175endif
176
177if need_libftdi1
178 deps += dependency('libftdi1')
179endif
180
181if need_libjaylink
182 deps += dependency('libjaylink')
Richard Hughescb973682018-12-19 11:44:22 +0000183endif
184
185# set defines for configured programmers
186if config_atahpt
187 srcs += 'atahpt.c'
188 cargs += '-DCONFIG_ATAHPT=1'
189endif
190if config_atapromise
191 srcs += 'atapromise.c'
192 cargs += '-DCONFIG_ATAPROMISE=1'
193endif
194if config_atavia
195 srcs += 'atavia.c'
196 cargs += '-DCONFIG_ATAVIA=1'
197endif
198if config_buspirate_spi
199 srcs += 'buspirate_spi.c'
200 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000201endif
202if config_ch341a_spi
203 srcs += 'ch341a_spi.c'
204 cargs += '-DCONFIG_CH341A_SPI=1'
205endif
206if config_dediprog
207 srcs += 'dediprog.c'
208 cargs += '-DCONFIG_DEDIPROG=1'
209endif
210if config_developerbox_spi
211 srcs += 'developerbox_spi.c'
212 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
213endif
214if config_digilent_spi
215 srcs += 'digilent_spi.c'
216 cargs += '-DCONFIG_DIGILENT_SPI=1'
217endif
Jean THOMASe28d8e42022-10-11 17:54:30 +0200218if config_dirtyjtag_spi
219 srcs += 'dirtyjtag_spi.c'
220 cargs += '-DCONFIG_DIRTYJTAG_SPI=1'
221endif
Richard Hughescb973682018-12-19 11:44:22 +0000222if config_drkaiser
223 srcs += 'drkaiser.c'
224 cargs += '-DCONFIG_DRKAISER=1'
225endif
226if config_dummy
227 srcs += 'dummyflasher.c'
228 cargs += '-DCONFIG_DUMMY=1'
229endif
230if config_ft2232_spi
231 srcs += 'ft2232_spi.c'
232 cargs += '-DCONFIG_FT2232_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000233 cargs += '-DHAVE_FT232H=1'
234endif
235if config_gfxnvidia
236 srcs += 'gfxnvidia.c'
237 cargs += '-DCONFIG_GFXNVIDIA=1'
238endif
239if config_internal
240 srcs += 'board_enable.c'
241 srcs += 'cbtable.c'
242 srcs += 'chipset_enable.c'
243 srcs += 'internal.c'
244 srcs += 'processor_enable.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000245 if host_is_x86
Richard Hughescb973682018-12-19 11:44:22 +0000246 srcs += 'amd_imc.c'
247 srcs += 'dmi.c'
248 srcs += 'ichspi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000249 srcs += 'it87spi.c'
250 srcs += 'mcp6x_spi.c'
251 srcs += 'sb600spi.c'
252 srcs += 'wbsio_spi.c'
253 endif
Richard Hughescb973682018-12-19 11:44:22 +0000254 cargs += '-DCONFIG_INTERNAL=1'
255 if get_option('config_internal_dmi')
256 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
257 cargs += '-DCONFIG_INTERNAL_DMI=1'
258 endif
259endif
260if config_it8212
261 srcs += 'it8212.c'
262 cargs += '-DCONFIG_IT8212=1'
263endif
Marc Schink7ec2d632020-12-08 22:20:50 +0100264if config_jlink_spi
265 srcs += 'jlink_spi.c'
266 cargs += '-DCONFIG_JLINK_SPI=1'
Marc Schink7ec2d632020-12-08 22:20:50 +0100267endif
Richard Hughescb973682018-12-19 11:44:22 +0000268if config_linux_mtd
269 srcs += 'linux_mtd.c'
270 cargs += '-DCONFIG_LINUX_MTD=1'
271endif
272if config_linux_spi
273 srcs += 'linux_spi.c'
274 cargs += '-DCONFIG_LINUX_SPI=1'
275endif
276if config_mstarddc_spi
277 srcs += 'mstarddc_spi.c'
278 cargs += '-DCONFIG_MSTARDDC_SPI=1'
279endif
280if config_nic3com
281 srcs += 'nic3com.c'
282 cargs += '-DCONFIG_NIC3COM=1'
283endif
284if config_nicintel
285 srcs += 'nicintel.c'
286 cargs += '-DCONFIG_NICINTEL=1'
287endif
288if config_nicintel_eeprom
289 srcs += 'nicintel_eeprom.c'
290 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
291endif
292if config_nicintel_spi
293 srcs += 'nicintel_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000294 cargs += '-DCONFIG_NICINTEL_SPI=1'
295endif
296if config_nicnatsemi
297 srcs += 'nicnatsemi.c'
298 cargs += '-DCONFIG_NICNATSEMI=1'
299endif
300if config_nicrealtek
301 srcs += 'nicrealtek.c'
302 cargs += '-DCONFIG_NICREALTEK=1'
303endif
304if config_ogp_spi
Richard Hughescb973682018-12-19 11:44:22 +0000305 srcs += 'ogp_spi.c'
306 cargs += '-DCONFIG_OGP_SPI=1'
307endif
308if config_pickit2_spi
309 srcs += 'pickit2_spi.c'
310 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000311endif
312if config_pony_spi
313 srcs += 'pony_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000314 cargs += '-DCONFIG_PONY_SPI=1'
315endif
316if config_rayer_spi
317 srcs += 'rayer_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000318 cargs += '-DCONFIG_RAYER_SPI=1'
319endif
320if config_satamv
321 srcs += 'satamv.c'
322 cargs += '-DCONFIG_SATAMV=1'
323endif
324if config_satasii
325 srcs += 'satasii.c'
326 cargs += '-DCONFIG_SATASII=1'
327endif
328if config_serprog
329 srcs += 'serprog.c'
330 cargs += '-DCONFIG_SERPROG=1'
Richard Hughescb973682018-12-19 11:44:22 +0000331endif
332if config_usbblaster_spi
333 srcs += 'usbblaster_spi.c'
334 cargs += '-DCONFIG_USBBLASTER_SPI=1'
335endif
Miklós Márton324929c2019-08-01 19:14:10 +0200336if config_stlinkv3_spi
337 srcs += 'stlinkv3_spi.c'
338 cargs += '-DCONFIG_STLINKV3_SPI=1'
339endif
Richard Hughescb973682018-12-19 11:44:22 +0000340
341# bitbanging SPI infrastructure
Peter Marheine306c8b72022-01-21 02:07:30 +0000342if need_bitbang_spi
Richard Hughescb973682018-12-19 11:44:22 +0000343 srcs += 'bitbang_spi.c'
344 cargs += '-DCONFIG_BITBANG_SPI=1'
345endif
346
Peter Marheine306c8b72022-01-21 02:07:30 +0000347if need_raw_mem_access
Thomas Heijligen74b4aa02021-12-14 17:52:30 +0100348 srcs += 'hwaccess_physmap.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000349endif
350
351if need_x86_port_io
352 srcs += 'hwaccess_x86_io.c'
Thomas Heijligena0655202021-12-14 16:36:05 +0100353 cargs += '-D__FLASHROM_HAVE_OUTB__=1'
Richard Hughescb973682018-12-19 11:44:22 +0000354endif
355
Peter Marheine306c8b72022-01-21 02:07:30 +0000356if need_x86_msr
357 srcs += 'hwaccess_x86_msr.c'
358endif
359
Richard Hughescb973682018-12-19 11:44:22 +0000360# raw serial IO
361if need_serial
Richard Hughescb973682018-12-19 11:44:22 +0000362 srcs += 'serial.c'
Thomas Heijligen140c1262021-09-27 15:12:26 +0200363 if host_machine.system() == 'linux'
364 srcs += 'custom_baud_linux.c'
365 else
366 srcs += 'custom_baud.c'
367 endif
Richard Hughescb973682018-12-19 11:44:22 +0000368endif
369
Richard Hughescb973682018-12-19 11:44:22 +0000370prefix = get_option('prefix')
371sbindir = join_paths(prefix, get_option('sbindir'))
372libdir = join_paths(prefix, get_option('libdir'))
Richard Hughesdad3a162020-02-17 09:57:01 +0000373mandir = join_paths(prefix, get_option('mandir'))
Richard Hughescb973682018-12-19 11:44:22 +0000374
375install_headers([
376 'libflashrom.h',
377 ],
378)
379
380# core modules needed by both the library and the CLI
381srcs += '82802ab.c'
382srcs += 'at45db.c'
383srcs += 'edi.c'
384srcs += 'en29lv640b.c'
385srcs += 'flashchips.c'
386srcs += 'flashrom.c'
387srcs += 'fmap.c'
388srcs += 'helpers.c'
389srcs += 'ich_descriptors.c'
390srcs += 'jedec.c'
391srcs += 'layout.c'
392srcs += 'libflashrom.c'
393srcs += 'opaque.c'
394srcs += 'print.c'
395srcs += 'programmer.c'
Thomas Heijligenbbfacff2021-03-31 20:40:01 +0200396srcs += 'programmer_table.c'
Richard Hughescb973682018-12-19 11:44:22 +0000397srcs += 'sfdp.c'
398srcs += 'spi25.c'
399srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700400srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000401srcs += 'spi.c'
402srcs += 'sst28sf040.c'
403srcs += 'sst49lfxxxc.c'
404srcs += 'sst_fwhub.c'
405srcs += 'stm50.c'
406srcs += 'udelay.c'
407srcs += 'w29ee011.c'
408srcs += 'w39.c'
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100409srcs += 'writeprotect.c'
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100410srcs += 'writeprotect_ranges.c'
Richard Hughescb973682018-12-19 11:44:22 +0000411
412mapfile = 'libflashrom.map'
413vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
Daniel Campello4bcc9a32021-03-17 18:03:28 -0600414flashrom = library(
Richard Hughescb973682018-12-19 11:44:22 +0000415 'flashrom',
416 sources : [
417 srcs,
418 ],
419 soversion : lt_current,
420 version : lt_version,
421 dependencies : [
422 deps,
423 ],
424 c_args : [
425 cargs,
426 ],
427 install : true,
428 link_args : vflag,
429 link_depends : mapfile,
430)
431
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500432version = meson.project_version()
433#strip leading characters
434if version.startswith('v')
435 version = version.split('v')[1]
436endif
437if version.startswith('p')
438 version = version.split('p')[1]
439endif
440
Richard Hughescb973682018-12-19 11:44:22 +0000441pkgg = import('pkgconfig')
442pkgg.generate(
443 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500444 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500445 name : 'flashrom',
446 filebase : 'flashrom',
447 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000448)
449
Richard Hughesdad3a162020-02-17 09:57:01 +0000450conf.set('VERSION', version)
Samuel R. Messner21bcfa92022-02-17 06:17:31 +0100451conf.set('MAN_DATE', run_command('util/getversion.sh', '--man-date').stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000452configure_file(
453 input : 'flashrom.8.tmpl',
454 output : 'flashrom.8',
455 configuration : conf,
456 install: true,
457 install_dir: join_paths(mandir, 'man8'),
458)
459
Richard Hughescb973682018-12-19 11:44:22 +0000460flashrom_dep = declare_dependency(
461 link_with : flashrom,
462 include_directories : include_directories('.'),
463 dependencies : deps
464)
465
Thomas Heijligen84e9c912021-06-01 16:22:14 +0200466if config_default_programmer_name != ''
467 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
468else
469 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
470endif
471
472cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
473
Daniel Campellof7a84fd2021-03-16 17:17:14 -0600474if config_print_wiki
475 srcs += 'print_wiki.c'
476 cargs += '-DCONFIG_PRINT_WIKI=1'
477endif
478
Richard Hughescb973682018-12-19 11:44:22 +0000479# we can't just link_with libflashrom as we require all the internal symbols...
480executable(
481 'flashrom',
482 sources : [
483 srcs,
484 'cli_classic.c',
485 'cli_common.c',
486 'cli_output.c',
487 'flashrom.c',
488 ],
489 dependencies : [
490 deps,
491 ],
492 c_args : [
493 cargs,
Richard Hughescb973682018-12-19 11:44:22 +0000494 ],
495 install : true,
496 install_dir : sbindir,
497)
498
499subdir('util')