blob: 0151ef24bf21ed77e637d2222a1ed899f19c5170 [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',
Anastasia Klimchuk3c508432022-04-13 15:15:24 +10005 default_options : [
6 'warning_level=2',
7 'c_std=c99',
Anastasia Klimchukc676be92022-04-26 14:53:18 +10008 'werror=true',
Anastasia Klimchuk3c508432022-04-13 15:15:24 +10009 'optimization=s',
10 'debug=false'],
Richard Hughescb973682018-12-19 11:44:22 +000011)
12
13# libtool versioning
14lt_current = '1'
15lt_revision = '0'
16lt_age = '0'
17lt_version = '@0@.@1@.@2@'.format(lt_current, lt_age, lt_revision)
18
Jacob Garber4a84ec22019-07-25 19:12:31 -060019# hide/enable some warnings
Richard Hughescb973682018-12-19 11:44:22 +000020warning_flags = [
Anastasia Klimchukcde70112021-10-25 13:20:26 +110021 '-Wshadow',
22 '-Wmissing-prototypes',
Jacob Garber4a84ec22019-07-25 19:12:31 -060023 '-Wwrite-strings',
Richard Hughescb973682018-12-19 11:44:22 +000024 '-Wno-unused-parameter',
Richard Hughescb973682018-12-19 11:44:22 +000025 '-Wno-address-of-packed-member',
26 '-Wno-enum-conversion',
Richard Hughescb973682018-12-19 11:44:22 +000027 '-Wno-missing-braces',
28]
29
30conf = configuration_data()
31
32cc = meson.get_compiler('c')
33add_project_arguments(cc.get_supported_arguments(warning_flags), language : 'c')
34add_project_arguments('-D_DEFAULT_SOURCE', language : 'c')
Rosen Penev566193f2020-07-18 12:50:16 -070035add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c') # required for fileno, nanosleep, and strndup
Richard Hughescb973682018-12-19 11:44:22 +000036add_project_arguments('-D_BSD_SOURCE', language : 'c') # required for glibc < v2.19
37add_project_arguments('-DFLASHROM_VERSION="' + meson.project_version() + '"', language : 'c')
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 = []
Thomas Heijligen51208f32022-04-28 11:07:29 +020086srcs = files(
87 '82802ab.c',
88 'at45db.c',
89 'bitbang_spi.c',
90 'edi.c',
91 'en29lv640b.c',
92 'flashchips.c',
93 'flashrom.c',
94 'fmap.c',
95 'helpers.c',
96 'ich_descriptors.c',
97 'jedec.c',
98 'layout.c',
99 'libflashrom.c',
100 'opaque.c',
101 'print.c',
102 'programmer.c',
103 'programmer_table.c',
104 'sfdp.c',
105 'spi25.c',
106 'spi25_statusreg.c',
107 'spi95.c',
108 'spi.c',
109 'sst28sf040.c',
110 'sst49lfxxxc.c',
111 'sst_fwhub.c',
112 'stm50.c',
113 'udelay.c',
114 'w29ee011.c',
115 'w39.c',
116 'writeprotect.c',
117 'writeprotect_ranges.c',
118)
Richard Hughescb973682018-12-19 11:44:22 +0000119
Peter Marheine306c8b72022-01-21 02:07:30 +0000120host_is_x86 = ['x86', 'x86_64'].contains(host_machine.cpu_family())
121
122need_serial = [
123 config_buspirate_spi, config_pony_spi, config_serprog,
124].contains(true)
125need_bitbang_spi = [
126 config_internal, config_nicintel_spi, config_ogp_spi,
127 config_pony_spi, config_rayer_spi,
128].contains(true)
129need_raw_mem_access = [
130 config_atapromise, config_drkaiser, config_gfxnvidia, config_internal,
131 config_it8212, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
132 config_ogp_spi, config_satamv, config_satasii,
133].contains(true)
134# Internal programmer uses x86 features if the system is x86
135need_x86_msr = config_internal and host_is_x86
136need_x86_port_io = [
137 config_atahpt, config_atapromise, config_internal and host_is_x86,
138 config_nic3com, config_nicnatsemi, config_nicrealtek, config_rayer_spi,
139 config_satamv,
140].contains(true)
141need_libpci = [
142 config_atahpt, config_atapromise, config_atavia,
143 config_drkaiser, config_gfxnvidia, config_internal, config_it8212,
144 config_nic3com, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
145 config_nicnatsemi, config_nicrealtek, config_ogp_spi, config_satamv,
146 config_satasii,
147].contains(true)
148need_libusb1 = [
149 config_ch341a_spi, config_dediprog, config_developerbox_spi,
150 config_digilent_spi, config_dirtyjtag_spi, config_pickit2_spi,
151 config_stlinkv3_spi,
152].contains(true)
153need_libftdi1 = [
154 config_ft2232_spi, config_usbblaster_spi,
155].contains(true)
156need_libjaylink = config_jlink_spi
157
158if (need_x86_port_io or need_x86_msr) and not host_is_x86
159 error('one or more enabled programmer only supports x86 and target is not')
160endif
161
Richard Hughescb973682018-12-19 11:44:22 +0000162
163# check for required symbols
164if cc.has_function('clock_gettime')
165 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
166endif
167if cc.has_function('strnlen')
168 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
169endif
170if cc.check_header('sys/utsname.h')
171 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
172endif
173
Thomas Heijligen5194d582022-02-19 22:31:32 +0100174srcs += 'platform/memaccess.c'
175
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100176if host_machine.endian() == 'little'
Thomas Heijligenc92f94b2022-03-17 13:41:17 +0100177 srcs += 'platform/endian_little.c'
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100178 add_project_arguments('-D__FLASHROM_LITTLE_ENDIAN__=1', language : 'c')
179endif
180if host_machine.endian() == 'big'
Thomas Heijligenc92f94b2022-03-17 13:41:17 +0100181 srcs += 'platform/endian_big.c'
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100182 add_project_arguments('-D__FLASHROM_BIG_ENDIAN__=1', language : 'c')
183endif
184
Richard Hughescb973682018-12-19 11:44:22 +0000185# some programmers require libusb
186if get_option('usb')
187 srcs += 'usbdev.c'
188 deps += dependency('libusb-1.0')
Peter Marheine306c8b72022-01-21 02:07:30 +0000189elif need_libusb1
190 error('usb is disabled but one or more enabled programmer requires USB access')
Richard Hughescb973682018-12-19 11:44:22 +0000191endif
192
193# some programmers require libpci
194if get_option('pciutils')
195 srcs += 'pcidev.c'
196 deps += dependency('libpci')
Peter Marheine306c8b72022-01-21 02:07:30 +0000197elif need_libpci
198 error('pciutils is disabled but one or more enabled programmer requires PCI access')
199endif
200
201if need_libftdi1
202 deps += dependency('libftdi1')
203endif
204
205if need_libjaylink
206 deps += dependency('libjaylink')
Richard Hughescb973682018-12-19 11:44:22 +0000207endif
208
209# set defines for configured programmers
210if config_atahpt
211 srcs += 'atahpt.c'
212 cargs += '-DCONFIG_ATAHPT=1'
213endif
214if config_atapromise
215 srcs += 'atapromise.c'
216 cargs += '-DCONFIG_ATAPROMISE=1'
217endif
218if config_atavia
219 srcs += 'atavia.c'
220 cargs += '-DCONFIG_ATAVIA=1'
221endif
222if config_buspirate_spi
223 srcs += 'buspirate_spi.c'
224 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000225endif
226if config_ch341a_spi
227 srcs += 'ch341a_spi.c'
228 cargs += '-DCONFIG_CH341A_SPI=1'
229endif
230if config_dediprog
231 srcs += 'dediprog.c'
232 cargs += '-DCONFIG_DEDIPROG=1'
233endif
234if config_developerbox_spi
235 srcs += 'developerbox_spi.c'
236 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
237endif
238if config_digilent_spi
239 srcs += 'digilent_spi.c'
240 cargs += '-DCONFIG_DIGILENT_SPI=1'
241endif
Jean THOMASe28d8e42022-10-11 17:54:30 +0200242if config_dirtyjtag_spi
243 srcs += 'dirtyjtag_spi.c'
244 cargs += '-DCONFIG_DIRTYJTAG_SPI=1'
245endif
Richard Hughescb973682018-12-19 11:44:22 +0000246if config_drkaiser
247 srcs += 'drkaiser.c'
248 cargs += '-DCONFIG_DRKAISER=1'
249endif
250if config_dummy
251 srcs += 'dummyflasher.c'
252 cargs += '-DCONFIG_DUMMY=1'
253endif
254if config_ft2232_spi
255 srcs += 'ft2232_spi.c'
256 cargs += '-DCONFIG_FT2232_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000257 cargs += '-DHAVE_FT232H=1'
258endif
259if config_gfxnvidia
260 srcs += 'gfxnvidia.c'
261 cargs += '-DCONFIG_GFXNVIDIA=1'
262endif
263if config_internal
264 srcs += 'board_enable.c'
265 srcs += 'cbtable.c'
266 srcs += 'chipset_enable.c'
267 srcs += 'internal.c'
268 srcs += 'processor_enable.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000269 if host_is_x86
Richard Hughescb973682018-12-19 11:44:22 +0000270 srcs += 'amd_imc.c'
271 srcs += 'dmi.c'
272 srcs += 'ichspi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000273 srcs += 'it87spi.c'
274 srcs += 'mcp6x_spi.c'
275 srcs += 'sb600spi.c'
276 srcs += 'wbsio_spi.c'
277 endif
Richard Hughescb973682018-12-19 11:44:22 +0000278 cargs += '-DCONFIG_INTERNAL=1'
279 if get_option('config_internal_dmi')
280 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
281 cargs += '-DCONFIG_INTERNAL_DMI=1'
282 endif
283endif
284if config_it8212
285 srcs += 'it8212.c'
286 cargs += '-DCONFIG_IT8212=1'
287endif
Marc Schink7ec2d632020-12-08 22:20:50 +0100288if config_jlink_spi
289 srcs += 'jlink_spi.c'
290 cargs += '-DCONFIG_JLINK_SPI=1'
Marc Schink7ec2d632020-12-08 22:20:50 +0100291endif
Richard Hughescb973682018-12-19 11:44:22 +0000292if config_linux_mtd
293 srcs += 'linux_mtd.c'
294 cargs += '-DCONFIG_LINUX_MTD=1'
295endif
296if config_linux_spi
297 srcs += 'linux_spi.c'
298 cargs += '-DCONFIG_LINUX_SPI=1'
299endif
300if config_mstarddc_spi
301 srcs += 'mstarddc_spi.c'
302 cargs += '-DCONFIG_MSTARDDC_SPI=1'
303endif
304if config_nic3com
305 srcs += 'nic3com.c'
306 cargs += '-DCONFIG_NIC3COM=1'
307endif
308if config_nicintel
309 srcs += 'nicintel.c'
310 cargs += '-DCONFIG_NICINTEL=1'
311endif
312if config_nicintel_eeprom
313 srcs += 'nicintel_eeprom.c'
314 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
315endif
316if config_nicintel_spi
317 srcs += 'nicintel_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000318 cargs += '-DCONFIG_NICINTEL_SPI=1'
319endif
320if config_nicnatsemi
321 srcs += 'nicnatsemi.c'
322 cargs += '-DCONFIG_NICNATSEMI=1'
323endif
324if config_nicrealtek
325 srcs += 'nicrealtek.c'
326 cargs += '-DCONFIG_NICREALTEK=1'
327endif
328if config_ogp_spi
Richard Hughescb973682018-12-19 11:44:22 +0000329 srcs += 'ogp_spi.c'
330 cargs += '-DCONFIG_OGP_SPI=1'
331endif
332if config_pickit2_spi
333 srcs += 'pickit2_spi.c'
334 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000335endif
336if config_pony_spi
337 srcs += 'pony_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000338 cargs += '-DCONFIG_PONY_SPI=1'
339endif
340if config_rayer_spi
341 srcs += 'rayer_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000342 cargs += '-DCONFIG_RAYER_SPI=1'
343endif
344if config_satamv
345 srcs += 'satamv.c'
346 cargs += '-DCONFIG_SATAMV=1'
347endif
348if config_satasii
349 srcs += 'satasii.c'
350 cargs += '-DCONFIG_SATASII=1'
351endif
352if config_serprog
353 srcs += 'serprog.c'
354 cargs += '-DCONFIG_SERPROG=1'
Richard Hughescb973682018-12-19 11:44:22 +0000355endif
356if config_usbblaster_spi
357 srcs += 'usbblaster_spi.c'
358 cargs += '-DCONFIG_USBBLASTER_SPI=1'
359endif
Miklós Márton324929c2019-08-01 19:14:10 +0200360if config_stlinkv3_spi
361 srcs += 'stlinkv3_spi.c'
362 cargs += '-DCONFIG_STLINKV3_SPI=1'
363endif
Richard Hughescb973682018-12-19 11:44:22 +0000364
365# bitbanging SPI infrastructure
Peter Marheine306c8b72022-01-21 02:07:30 +0000366if need_bitbang_spi
Richard Hughescb973682018-12-19 11:44:22 +0000367 srcs += 'bitbang_spi.c'
368 cargs += '-DCONFIG_BITBANG_SPI=1'
369endif
370
Peter Marheine306c8b72022-01-21 02:07:30 +0000371if need_raw_mem_access
Thomas Heijligen74b4aa02021-12-14 17:52:30 +0100372 srcs += 'hwaccess_physmap.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000373endif
374
375if need_x86_port_io
376 srcs += 'hwaccess_x86_io.c'
Thomas Heijligena0655202021-12-14 16:36:05 +0100377 cargs += '-D__FLASHROM_HAVE_OUTB__=1'
Richard Hughescb973682018-12-19 11:44:22 +0000378endif
379
Peter Marheine306c8b72022-01-21 02:07:30 +0000380if need_x86_msr
381 srcs += 'hwaccess_x86_msr.c'
382endif
383
Richard Hughescb973682018-12-19 11:44:22 +0000384# raw serial IO
385if need_serial
Richard Hughescb973682018-12-19 11:44:22 +0000386 srcs += 'serial.c'
Thomas Heijligen140c1262021-09-27 15:12:26 +0200387 if host_machine.system() == 'linux'
388 srcs += 'custom_baud_linux.c'
389 else
390 srcs += 'custom_baud.c'
391 endif
Richard Hughescb973682018-12-19 11:44:22 +0000392endif
393
Richard Hughescb973682018-12-19 11:44:22 +0000394prefix = get_option('prefix')
395sbindir = join_paths(prefix, get_option('sbindir'))
396libdir = join_paths(prefix, get_option('libdir'))
Richard Hughesdad3a162020-02-17 09:57:01 +0000397mandir = join_paths(prefix, get_option('mandir'))
Richard Hughescb973682018-12-19 11:44:22 +0000398
399install_headers([
Thomas Heijligen58015c22022-04-14 13:50:55 +0200400 'include/libflashrom.h',
Richard Hughescb973682018-12-19 11:44:22 +0000401 ],
402)
403
Thomas Heijligen58015c22022-04-14 13:50:55 +0200404include_dir = include_directories('include')
405
Richard Hughescb973682018-12-19 11:44:22 +0000406mapfile = 'libflashrom.map'
407vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
Daniel Campello4bcc9a32021-03-17 18:03:28 -0600408flashrom = library(
Richard Hughescb973682018-12-19 11:44:22 +0000409 'flashrom',
410 sources : [
411 srcs,
412 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200413 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000414 soversion : lt_current,
415 version : lt_version,
416 dependencies : [
417 deps,
418 ],
419 c_args : [
420 cargs,
421 ],
422 install : true,
423 link_args : vflag,
424 link_depends : mapfile,
425)
426
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500427version = meson.project_version()
428#strip leading characters
429if version.startswith('v')
430 version = version.split('v')[1]
431endif
432if version.startswith('p')
433 version = version.split('p')[1]
434endif
435
Richard Hughescb973682018-12-19 11:44:22 +0000436pkgg = import('pkgconfig')
437pkgg.generate(
438 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500439 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500440 name : 'flashrom',
441 filebase : 'flashrom',
442 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000443)
444
Richard Hughesdad3a162020-02-17 09:57:01 +0000445conf.set('VERSION', version)
Samuel R. Messner21bcfa92022-02-17 06:17:31 +0100446conf.set('MAN_DATE', run_command('util/getversion.sh', '--man-date').stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000447configure_file(
448 input : 'flashrom.8.tmpl',
449 output : 'flashrom.8',
450 configuration : conf,
451 install: true,
452 install_dir: join_paths(mandir, 'man8'),
453)
454
Richard Hughescb973682018-12-19 11:44:22 +0000455flashrom_dep = declare_dependency(
456 link_with : flashrom,
Thomas Heijligen58015c22022-04-14 13:50:55 +0200457 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000458 dependencies : deps
459)
460
Thomas Heijligen84e9c912021-06-01 16:22:14 +0200461if config_default_programmer_name != ''
462 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
463else
464 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
465endif
466
467cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
468
Daniel Campellof7a84fd2021-03-16 17:17:14 -0600469if config_print_wiki
470 srcs += 'print_wiki.c'
471 cargs += '-DCONFIG_PRINT_WIKI=1'
472endif
473
Richard Hughescb973682018-12-19 11:44:22 +0000474# we can't just link_with libflashrom as we require all the internal symbols...
475executable(
476 'flashrom',
477 sources : [
478 srcs,
479 'cli_classic.c',
480 'cli_common.c',
481 'cli_output.c',
482 'flashrom.c',
483 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200484 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000485 dependencies : [
486 deps,
487 ],
488 c_args : [
489 cargs,
Richard Hughescb973682018-12-19 11:44:22 +0000490 ],
491 install : true,
492 install_dir : sbindir,
493)
494
495subdir('util')