blob: be61892f34485f327a0fa9ca9c636d75762c3220 [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 Heijligen847d94b2021-10-12 17:38:01 +020032if host_machine.system() in ['cygwin', 'windows']
33 add_project_arguments('-DIS_WINDOWS=1', language : 'c')
34else
35 add_project_arguments('-DIS_WINDOWS=0', language : 'c')
36endif
37
Richard Hughescb973682018-12-19 11:44:22 +000038# get defaults from configure
39config_atahpt = get_option('config_atahpt')
40config_atapromise = get_option('config_atapromise')
41config_atavia = get_option('config_atavia')
42config_buspirate_spi = get_option('config_buspirate_spi')
43config_ch341a_spi = get_option('config_ch341a_spi')
44config_dediprog = get_option('config_dediprog')
45config_developerbox_spi = get_option('config_developerbox_spi')
46config_digilent_spi = get_option('config_digilent_spi')
Jean THOMASe28d8e42022-10-11 17:54:30 +020047config_dirtyjtag_spi = get_option('config_dirtyjtag_spi')
Richard Hughescb973682018-12-19 11:44:22 +000048config_drkaiser = get_option('config_drkaiser')
49config_dummy = get_option('config_dummy')
50config_ft2232_spi = get_option('config_ft2232_spi')
51config_gfxnvidia = get_option('config_gfxnvidia')
52config_internal = get_option('config_internal')
53config_it8212 = get_option('config_it8212')
Marc Schink7ec2d632020-12-08 22:20:50 +010054config_jlink_spi = get_option('config_jlink_spi')
Richard Hughescb973682018-12-19 11:44:22 +000055config_linux_mtd = get_option('config_linux_mtd')
56config_linux_spi = get_option('config_linux_spi')
57config_mstarddc_spi = get_option('config_mstarddc_spi')
58config_nic3com = get_option('config_nic3com')
59config_nicintel_eeprom = get_option('config_nicintel_eeprom')
60config_nicintel = get_option('config_nicintel')
61config_nicintel_spi = get_option('config_nicintel_spi')
62config_nicnatsemi = get_option('config_nicnatsemi')
63config_nicrealtek = get_option('config_nicrealtek')
64config_ogp_spi = get_option('config_ogp_spi')
65config_pickit2_spi = get_option('config_pickit2_spi')
66config_pony_spi = get_option('config_pony_spi')
67config_rayer_spi = get_option('config_rayer_spi')
68config_satamv = get_option('config_satamv')
69config_satasii = get_option('config_satasii')
70config_serprog = get_option('config_serprog')
71config_usbblaster_spi = get_option('config_usbblaster_spi')
Miklós Márton324929c2019-08-01 19:14:10 +020072config_stlinkv3_spi = get_option('config_stlinkv3_spi')
Thomas Heijligen84e9c912021-06-01 16:22:14 +020073config_default_programmer_name = get_option('default_programmer_name')
74config_default_programmer_args = get_option('default_programmer_args')
Daniel Campellof7a84fd2021-03-16 17:17:14 -060075config_print_wiki= get_option('print_wiki')
Richard Hughescb973682018-12-19 11:44:22 +000076
77cargs = []
78deps = []
79srcs = []
80
Peter Marheine306c8b72022-01-21 02:07:30 +000081host_is_x86 = ['x86', 'x86_64'].contains(host_machine.cpu_family())
82
83need_serial = [
84 config_buspirate_spi, config_pony_spi, config_serprog,
85].contains(true)
86need_bitbang_spi = [
87 config_internal, config_nicintel_spi, config_ogp_spi,
88 config_pony_spi, config_rayer_spi,
89].contains(true)
90need_raw_mem_access = [
91 config_atapromise, config_drkaiser, config_gfxnvidia, config_internal,
92 config_it8212, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
93 config_ogp_spi, config_satamv, config_satasii,
94].contains(true)
95# Internal programmer uses x86 features if the system is x86
96need_x86_msr = config_internal and host_is_x86
97need_x86_port_io = [
98 config_atahpt, config_atapromise, config_internal and host_is_x86,
99 config_nic3com, config_nicnatsemi, config_nicrealtek, config_rayer_spi,
100 config_satamv,
101].contains(true)
102need_libpci = [
103 config_atahpt, config_atapromise, config_atavia,
104 config_drkaiser, config_gfxnvidia, config_internal, config_it8212,
105 config_nic3com, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
106 config_nicnatsemi, config_nicrealtek, config_ogp_spi, config_satamv,
107 config_satasii,
108].contains(true)
109need_libusb1 = [
110 config_ch341a_spi, config_dediprog, config_developerbox_spi,
111 config_digilent_spi, config_dirtyjtag_spi, config_pickit2_spi,
112 config_stlinkv3_spi,
113].contains(true)
114need_libftdi1 = [
115 config_ft2232_spi, config_usbblaster_spi,
116].contains(true)
117need_libjaylink = config_jlink_spi
118
119if (need_x86_port_io or need_x86_msr) and not host_is_x86
120 error('one or more enabled programmer only supports x86 and target is not')
121endif
122
Richard Hughescb973682018-12-19 11:44:22 +0000123
124# check for required symbols
125if cc.has_function('clock_gettime')
126 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
127endif
128if cc.has_function('strnlen')
129 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
130endif
131if cc.check_header('sys/utsname.h')
132 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
133endif
134
Thomas Heijligen5194d582022-02-19 22:31:32 +0100135srcs += 'platform/memaccess.c'
136
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100137if host_machine.endian() == 'little'
Thomas Heijligenc92f94b2022-03-17 13:41:17 +0100138 srcs += 'platform/endian_little.c'
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100139 add_project_arguments('-D__FLASHROM_LITTLE_ENDIAN__=1', language : 'c')
140endif
141if host_machine.endian() == 'big'
Thomas Heijligenc92f94b2022-03-17 13:41:17 +0100142 srcs += 'platform/endian_big.c'
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100143 add_project_arguments('-D__FLASHROM_BIG_ENDIAN__=1', language : 'c')
144endif
145
Richard Hughescb973682018-12-19 11:44:22 +0000146# some programmers require libusb
147if get_option('usb')
148 srcs += 'usbdev.c'
149 deps += dependency('libusb-1.0')
Peter Marheine306c8b72022-01-21 02:07:30 +0000150elif need_libusb1
151 error('usb is disabled but one or more enabled programmer requires USB access')
Richard Hughescb973682018-12-19 11:44:22 +0000152endif
153
154# some programmers require libpci
155if get_option('pciutils')
156 srcs += 'pcidev.c'
157 deps += dependency('libpci')
Peter Marheine306c8b72022-01-21 02:07:30 +0000158elif need_libpci
159 error('pciutils is disabled but one or more enabled programmer requires PCI access')
160endif
161
162if need_libftdi1
163 deps += dependency('libftdi1')
164endif
165
166if need_libjaylink
167 deps += dependency('libjaylink')
Richard Hughescb973682018-12-19 11:44:22 +0000168endif
169
170# set defines for configured programmers
171if config_atahpt
172 srcs += 'atahpt.c'
173 cargs += '-DCONFIG_ATAHPT=1'
174endif
175if config_atapromise
176 srcs += 'atapromise.c'
177 cargs += '-DCONFIG_ATAPROMISE=1'
178endif
179if config_atavia
180 srcs += 'atavia.c'
181 cargs += '-DCONFIG_ATAVIA=1'
182endif
183if config_buspirate_spi
184 srcs += 'buspirate_spi.c'
185 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000186endif
187if config_ch341a_spi
188 srcs += 'ch341a_spi.c'
189 cargs += '-DCONFIG_CH341A_SPI=1'
190endif
191if config_dediprog
192 srcs += 'dediprog.c'
193 cargs += '-DCONFIG_DEDIPROG=1'
194endif
195if config_developerbox_spi
196 srcs += 'developerbox_spi.c'
197 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
198endif
199if config_digilent_spi
200 srcs += 'digilent_spi.c'
201 cargs += '-DCONFIG_DIGILENT_SPI=1'
202endif
Jean THOMASe28d8e42022-10-11 17:54:30 +0200203if config_dirtyjtag_spi
204 srcs += 'dirtyjtag_spi.c'
205 cargs += '-DCONFIG_DIRTYJTAG_SPI=1'
206endif
Richard Hughescb973682018-12-19 11:44:22 +0000207if config_drkaiser
208 srcs += 'drkaiser.c'
209 cargs += '-DCONFIG_DRKAISER=1'
210endif
211if config_dummy
212 srcs += 'dummyflasher.c'
213 cargs += '-DCONFIG_DUMMY=1'
214endif
215if config_ft2232_spi
216 srcs += 'ft2232_spi.c'
217 cargs += '-DCONFIG_FT2232_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000218 cargs += '-DHAVE_FT232H=1'
219endif
220if config_gfxnvidia
221 srcs += 'gfxnvidia.c'
222 cargs += '-DCONFIG_GFXNVIDIA=1'
223endif
224if config_internal
225 srcs += 'board_enable.c'
226 srcs += 'cbtable.c'
227 srcs += 'chipset_enable.c'
228 srcs += 'internal.c'
229 srcs += 'processor_enable.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000230 if host_is_x86
Richard Hughescb973682018-12-19 11:44:22 +0000231 srcs += 'amd_imc.c'
232 srcs += 'dmi.c'
233 srcs += 'ichspi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000234 srcs += 'it87spi.c'
235 srcs += 'mcp6x_spi.c'
236 srcs += 'sb600spi.c'
237 srcs += 'wbsio_spi.c'
238 endif
Richard Hughescb973682018-12-19 11:44:22 +0000239 cargs += '-DCONFIG_INTERNAL=1'
240 if get_option('config_internal_dmi')
241 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
242 cargs += '-DCONFIG_INTERNAL_DMI=1'
243 endif
244endif
245if config_it8212
246 srcs += 'it8212.c'
247 cargs += '-DCONFIG_IT8212=1'
248endif
Marc Schink7ec2d632020-12-08 22:20:50 +0100249if config_jlink_spi
250 srcs += 'jlink_spi.c'
251 cargs += '-DCONFIG_JLINK_SPI=1'
Marc Schink7ec2d632020-12-08 22:20:50 +0100252endif
Richard Hughescb973682018-12-19 11:44:22 +0000253if config_linux_mtd
254 srcs += 'linux_mtd.c'
255 cargs += '-DCONFIG_LINUX_MTD=1'
256endif
257if config_linux_spi
258 srcs += 'linux_spi.c'
259 cargs += '-DCONFIG_LINUX_SPI=1'
260endif
261if config_mstarddc_spi
262 srcs += 'mstarddc_spi.c'
263 cargs += '-DCONFIG_MSTARDDC_SPI=1'
264endif
265if config_nic3com
266 srcs += 'nic3com.c'
267 cargs += '-DCONFIG_NIC3COM=1'
268endif
269if config_nicintel
270 srcs += 'nicintel.c'
271 cargs += '-DCONFIG_NICINTEL=1'
272endif
273if config_nicintel_eeprom
274 srcs += 'nicintel_eeprom.c'
275 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
276endif
277if config_nicintel_spi
278 srcs += 'nicintel_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000279 cargs += '-DCONFIG_NICINTEL_SPI=1'
280endif
281if config_nicnatsemi
282 srcs += 'nicnatsemi.c'
283 cargs += '-DCONFIG_NICNATSEMI=1'
284endif
285if config_nicrealtek
286 srcs += 'nicrealtek.c'
287 cargs += '-DCONFIG_NICREALTEK=1'
288endif
289if config_ogp_spi
Richard Hughescb973682018-12-19 11:44:22 +0000290 srcs += 'ogp_spi.c'
291 cargs += '-DCONFIG_OGP_SPI=1'
292endif
293if config_pickit2_spi
294 srcs += 'pickit2_spi.c'
295 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000296endif
297if config_pony_spi
298 srcs += 'pony_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000299 cargs += '-DCONFIG_PONY_SPI=1'
300endif
301if config_rayer_spi
302 srcs += 'rayer_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000303 cargs += '-DCONFIG_RAYER_SPI=1'
304endif
305if config_satamv
306 srcs += 'satamv.c'
307 cargs += '-DCONFIG_SATAMV=1'
308endif
309if config_satasii
310 srcs += 'satasii.c'
311 cargs += '-DCONFIG_SATASII=1'
312endif
313if config_serprog
314 srcs += 'serprog.c'
315 cargs += '-DCONFIG_SERPROG=1'
Richard Hughescb973682018-12-19 11:44:22 +0000316endif
317if config_usbblaster_spi
318 srcs += 'usbblaster_spi.c'
319 cargs += '-DCONFIG_USBBLASTER_SPI=1'
320endif
Miklós Márton324929c2019-08-01 19:14:10 +0200321if config_stlinkv3_spi
322 srcs += 'stlinkv3_spi.c'
323 cargs += '-DCONFIG_STLINKV3_SPI=1'
324endif
Richard Hughescb973682018-12-19 11:44:22 +0000325
326# bitbanging SPI infrastructure
Peter Marheine306c8b72022-01-21 02:07:30 +0000327if need_bitbang_spi
Richard Hughescb973682018-12-19 11:44:22 +0000328 srcs += 'bitbang_spi.c'
329 cargs += '-DCONFIG_BITBANG_SPI=1'
330endif
331
Peter Marheine306c8b72022-01-21 02:07:30 +0000332if need_raw_mem_access
Thomas Heijligen74b4aa02021-12-14 17:52:30 +0100333 srcs += 'hwaccess_physmap.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000334endif
335
336if need_x86_port_io
337 srcs += 'hwaccess_x86_io.c'
Thomas Heijligena0655202021-12-14 16:36:05 +0100338 cargs += '-D__FLASHROM_HAVE_OUTB__=1'
Richard Hughescb973682018-12-19 11:44:22 +0000339endif
340
Peter Marheine306c8b72022-01-21 02:07:30 +0000341if need_x86_msr
342 srcs += 'hwaccess_x86_msr.c'
343endif
344
Richard Hughescb973682018-12-19 11:44:22 +0000345# raw serial IO
346if need_serial
Richard Hughescb973682018-12-19 11:44:22 +0000347 srcs += 'serial.c'
Thomas Heijligen140c1262021-09-27 15:12:26 +0200348 if host_machine.system() == 'linux'
349 srcs += 'custom_baud_linux.c'
350 else
351 srcs += 'custom_baud.c'
352 endif
Richard Hughescb973682018-12-19 11:44:22 +0000353endif
354
Richard Hughescb973682018-12-19 11:44:22 +0000355prefix = get_option('prefix')
356sbindir = join_paths(prefix, get_option('sbindir'))
357libdir = join_paths(prefix, get_option('libdir'))
Richard Hughesdad3a162020-02-17 09:57:01 +0000358mandir = join_paths(prefix, get_option('mandir'))
Richard Hughescb973682018-12-19 11:44:22 +0000359
360install_headers([
361 'libflashrom.h',
362 ],
363)
364
365# core modules needed by both the library and the CLI
366srcs += '82802ab.c'
367srcs += 'at45db.c'
368srcs += 'edi.c'
369srcs += 'en29lv640b.c'
370srcs += 'flashchips.c'
371srcs += 'flashrom.c'
372srcs += 'fmap.c'
373srcs += 'helpers.c'
374srcs += 'ich_descriptors.c'
375srcs += 'jedec.c'
376srcs += 'layout.c'
377srcs += 'libflashrom.c'
378srcs += 'opaque.c'
379srcs += 'print.c'
380srcs += 'programmer.c'
Thomas Heijligenbbfacff2021-03-31 20:40:01 +0200381srcs += 'programmer_table.c'
Richard Hughescb973682018-12-19 11:44:22 +0000382srcs += 'sfdp.c'
383srcs += 'spi25.c'
384srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700385srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000386srcs += 'spi.c'
387srcs += 'sst28sf040.c'
388srcs += 'sst49lfxxxc.c'
389srcs += 'sst_fwhub.c'
390srcs += 'stm50.c'
391srcs += 'udelay.c'
392srcs += 'w29ee011.c'
393srcs += 'w39.c'
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100394srcs += 'writeprotect.c'
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100395srcs += 'writeprotect_ranges.c'
Richard Hughescb973682018-12-19 11:44:22 +0000396
397mapfile = 'libflashrom.map'
398vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
Daniel Campello4bcc9a32021-03-17 18:03:28 -0600399flashrom = library(
Richard Hughescb973682018-12-19 11:44:22 +0000400 'flashrom',
401 sources : [
402 srcs,
403 ],
404 soversion : lt_current,
405 version : lt_version,
406 dependencies : [
407 deps,
408 ],
409 c_args : [
410 cargs,
411 ],
412 install : true,
413 link_args : vflag,
414 link_depends : mapfile,
415)
416
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500417version = meson.project_version()
418#strip leading characters
419if version.startswith('v')
420 version = version.split('v')[1]
421endif
422if version.startswith('p')
423 version = version.split('p')[1]
424endif
425
Richard Hughescb973682018-12-19 11:44:22 +0000426pkgg = import('pkgconfig')
427pkgg.generate(
428 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500429 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500430 name : 'flashrom',
431 filebase : 'flashrom',
432 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000433)
434
Richard Hughesdad3a162020-02-17 09:57:01 +0000435conf.set('VERSION', version)
Samuel R. Messner21bcfa92022-02-17 06:17:31 +0100436conf.set('MAN_DATE', run_command('util/getversion.sh', '--man-date').stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000437configure_file(
438 input : 'flashrom.8.tmpl',
439 output : 'flashrom.8',
440 configuration : conf,
441 install: true,
442 install_dir: join_paths(mandir, 'man8'),
443)
444
Richard Hughescb973682018-12-19 11:44:22 +0000445flashrom_dep = declare_dependency(
446 link_with : flashrom,
447 include_directories : include_directories('.'),
448 dependencies : deps
449)
450
Thomas Heijligen84e9c912021-06-01 16:22:14 +0200451if config_default_programmer_name != ''
452 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
453else
454 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
455endif
456
457cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
458
Daniel Campellof7a84fd2021-03-16 17:17:14 -0600459if config_print_wiki
460 srcs += 'print_wiki.c'
461 cargs += '-DCONFIG_PRINT_WIKI=1'
462endif
463
Richard Hughescb973682018-12-19 11:44:22 +0000464# we can't just link_with libflashrom as we require all the internal symbols...
465executable(
466 'flashrom',
467 sources : [
468 srcs,
469 'cli_classic.c',
470 'cli_common.c',
471 'cli_output.c',
472 'flashrom.c',
473 ],
474 dependencies : [
475 deps,
476 ],
477 c_args : [
478 cargs,
Richard Hughescb973682018-12-19 11:44:22 +0000479 ],
480 install : true,
481 install_dir : sbindir,
482)
483
484subdir('util')