blob: db6f98bf5d1e844e98b2c3d6dbd3a8ff67c36efd [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 = []
86srcs = []
87
Peter Marheine306c8b72022-01-21 02:07:30 +000088host_is_x86 = ['x86', 'x86_64'].contains(host_machine.cpu_family())
89
90need_serial = [
91 config_buspirate_spi, config_pony_spi, config_serprog,
92].contains(true)
93need_bitbang_spi = [
94 config_internal, config_nicintel_spi, config_ogp_spi,
95 config_pony_spi, config_rayer_spi,
96].contains(true)
97need_raw_mem_access = [
98 config_atapromise, config_drkaiser, config_gfxnvidia, config_internal,
99 config_it8212, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
100 config_ogp_spi, config_satamv, config_satasii,
101].contains(true)
102# Internal programmer uses x86 features if the system is x86
103need_x86_msr = config_internal and host_is_x86
104need_x86_port_io = [
105 config_atahpt, config_atapromise, config_internal and host_is_x86,
106 config_nic3com, config_nicnatsemi, config_nicrealtek, config_rayer_spi,
107 config_satamv,
108].contains(true)
109need_libpci = [
110 config_atahpt, config_atapromise, config_atavia,
111 config_drkaiser, config_gfxnvidia, config_internal, config_it8212,
112 config_nic3com, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
113 config_nicnatsemi, config_nicrealtek, config_ogp_spi, config_satamv,
114 config_satasii,
115].contains(true)
116need_libusb1 = [
117 config_ch341a_spi, config_dediprog, config_developerbox_spi,
118 config_digilent_spi, config_dirtyjtag_spi, config_pickit2_spi,
119 config_stlinkv3_spi,
120].contains(true)
121need_libftdi1 = [
122 config_ft2232_spi, config_usbblaster_spi,
123].contains(true)
124need_libjaylink = config_jlink_spi
125
126if (need_x86_port_io or need_x86_msr) and not host_is_x86
127 error('one or more enabled programmer only supports x86 and target is not')
128endif
129
Richard Hughescb973682018-12-19 11:44:22 +0000130
131# check for required symbols
132if cc.has_function('clock_gettime')
133 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
134endif
135if cc.has_function('strnlen')
136 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
137endif
138if cc.check_header('sys/utsname.h')
139 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
140endif
141
Thomas Heijligen5194d582022-02-19 22:31:32 +0100142srcs += 'platform/memaccess.c'
143
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100144if host_machine.endian() == 'little'
Thomas Heijligenc92f94b2022-03-17 13:41:17 +0100145 srcs += 'platform/endian_little.c'
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100146 add_project_arguments('-D__FLASHROM_LITTLE_ENDIAN__=1', language : 'c')
147endif
148if host_machine.endian() == 'big'
Thomas Heijligenc92f94b2022-03-17 13:41:17 +0100149 srcs += 'platform/endian_big.c'
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100150 add_project_arguments('-D__FLASHROM_BIG_ENDIAN__=1', language : 'c')
151endif
152
Richard Hughescb973682018-12-19 11:44:22 +0000153# some programmers require libusb
154if get_option('usb')
155 srcs += 'usbdev.c'
156 deps += dependency('libusb-1.0')
Peter Marheine306c8b72022-01-21 02:07:30 +0000157elif need_libusb1
158 error('usb is disabled but one or more enabled programmer requires USB access')
Richard Hughescb973682018-12-19 11:44:22 +0000159endif
160
161# some programmers require libpci
162if get_option('pciutils')
163 srcs += 'pcidev.c'
164 deps += dependency('libpci')
Peter Marheine306c8b72022-01-21 02:07:30 +0000165elif need_libpci
166 error('pciutils is disabled but one or more enabled programmer requires PCI access')
167endif
168
169if need_libftdi1
170 deps += dependency('libftdi1')
171endif
172
173if need_libjaylink
174 deps += dependency('libjaylink')
Richard Hughescb973682018-12-19 11:44:22 +0000175endif
176
177# set defines for configured programmers
178if config_atahpt
179 srcs += 'atahpt.c'
180 cargs += '-DCONFIG_ATAHPT=1'
181endif
182if config_atapromise
183 srcs += 'atapromise.c'
184 cargs += '-DCONFIG_ATAPROMISE=1'
185endif
186if config_atavia
187 srcs += 'atavia.c'
188 cargs += '-DCONFIG_ATAVIA=1'
189endif
190if config_buspirate_spi
191 srcs += 'buspirate_spi.c'
192 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000193endif
194if config_ch341a_spi
195 srcs += 'ch341a_spi.c'
196 cargs += '-DCONFIG_CH341A_SPI=1'
197endif
198if config_dediprog
199 srcs += 'dediprog.c'
200 cargs += '-DCONFIG_DEDIPROG=1'
201endif
202if config_developerbox_spi
203 srcs += 'developerbox_spi.c'
204 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
205endif
206if config_digilent_spi
207 srcs += 'digilent_spi.c'
208 cargs += '-DCONFIG_DIGILENT_SPI=1'
209endif
Jean THOMASe28d8e42022-10-11 17:54:30 +0200210if config_dirtyjtag_spi
211 srcs += 'dirtyjtag_spi.c'
212 cargs += '-DCONFIG_DIRTYJTAG_SPI=1'
213endif
Richard Hughescb973682018-12-19 11:44:22 +0000214if config_drkaiser
215 srcs += 'drkaiser.c'
216 cargs += '-DCONFIG_DRKAISER=1'
217endif
218if config_dummy
219 srcs += 'dummyflasher.c'
220 cargs += '-DCONFIG_DUMMY=1'
221endif
222if config_ft2232_spi
223 srcs += 'ft2232_spi.c'
224 cargs += '-DCONFIG_FT2232_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000225 cargs += '-DHAVE_FT232H=1'
226endif
227if config_gfxnvidia
228 srcs += 'gfxnvidia.c'
229 cargs += '-DCONFIG_GFXNVIDIA=1'
230endif
231if config_internal
232 srcs += 'board_enable.c'
233 srcs += 'cbtable.c'
234 srcs += 'chipset_enable.c'
235 srcs += 'internal.c'
236 srcs += 'processor_enable.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000237 if host_is_x86
Richard Hughescb973682018-12-19 11:44:22 +0000238 srcs += 'amd_imc.c'
239 srcs += 'dmi.c'
240 srcs += 'ichspi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000241 srcs += 'it87spi.c'
242 srcs += 'mcp6x_spi.c'
243 srcs += 'sb600spi.c'
244 srcs += 'wbsio_spi.c'
245 endif
Richard Hughescb973682018-12-19 11:44:22 +0000246 cargs += '-DCONFIG_INTERNAL=1'
247 if get_option('config_internal_dmi')
248 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
249 cargs += '-DCONFIG_INTERNAL_DMI=1'
250 endif
251endif
252if config_it8212
253 srcs += 'it8212.c'
254 cargs += '-DCONFIG_IT8212=1'
255endif
Marc Schink7ec2d632020-12-08 22:20:50 +0100256if config_jlink_spi
257 srcs += 'jlink_spi.c'
258 cargs += '-DCONFIG_JLINK_SPI=1'
Marc Schink7ec2d632020-12-08 22:20:50 +0100259endif
Richard Hughescb973682018-12-19 11:44:22 +0000260if config_linux_mtd
261 srcs += 'linux_mtd.c'
262 cargs += '-DCONFIG_LINUX_MTD=1'
263endif
264if config_linux_spi
265 srcs += 'linux_spi.c'
266 cargs += '-DCONFIG_LINUX_SPI=1'
267endif
268if config_mstarddc_spi
269 srcs += 'mstarddc_spi.c'
270 cargs += '-DCONFIG_MSTARDDC_SPI=1'
271endif
272if config_nic3com
273 srcs += 'nic3com.c'
274 cargs += '-DCONFIG_NIC3COM=1'
275endif
276if config_nicintel
277 srcs += 'nicintel.c'
278 cargs += '-DCONFIG_NICINTEL=1'
279endif
280if config_nicintel_eeprom
281 srcs += 'nicintel_eeprom.c'
282 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
283endif
284if config_nicintel_spi
285 srcs += 'nicintel_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000286 cargs += '-DCONFIG_NICINTEL_SPI=1'
287endif
288if config_nicnatsemi
289 srcs += 'nicnatsemi.c'
290 cargs += '-DCONFIG_NICNATSEMI=1'
291endif
292if config_nicrealtek
293 srcs += 'nicrealtek.c'
294 cargs += '-DCONFIG_NICREALTEK=1'
295endif
296if config_ogp_spi
Richard Hughescb973682018-12-19 11:44:22 +0000297 srcs += 'ogp_spi.c'
298 cargs += '-DCONFIG_OGP_SPI=1'
299endif
300if config_pickit2_spi
301 srcs += 'pickit2_spi.c'
302 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000303endif
304if config_pony_spi
305 srcs += 'pony_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000306 cargs += '-DCONFIG_PONY_SPI=1'
307endif
308if config_rayer_spi
309 srcs += 'rayer_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000310 cargs += '-DCONFIG_RAYER_SPI=1'
311endif
312if config_satamv
313 srcs += 'satamv.c'
314 cargs += '-DCONFIG_SATAMV=1'
315endif
316if config_satasii
317 srcs += 'satasii.c'
318 cargs += '-DCONFIG_SATASII=1'
319endif
320if config_serprog
321 srcs += 'serprog.c'
322 cargs += '-DCONFIG_SERPROG=1'
Richard Hughescb973682018-12-19 11:44:22 +0000323endif
324if config_usbblaster_spi
325 srcs += 'usbblaster_spi.c'
326 cargs += '-DCONFIG_USBBLASTER_SPI=1'
327endif
Miklós Márton324929c2019-08-01 19:14:10 +0200328if config_stlinkv3_spi
329 srcs += 'stlinkv3_spi.c'
330 cargs += '-DCONFIG_STLINKV3_SPI=1'
331endif
Richard Hughescb973682018-12-19 11:44:22 +0000332
333# bitbanging SPI infrastructure
Peter Marheine306c8b72022-01-21 02:07:30 +0000334if need_bitbang_spi
Richard Hughescb973682018-12-19 11:44:22 +0000335 srcs += 'bitbang_spi.c'
336 cargs += '-DCONFIG_BITBANG_SPI=1'
337endif
338
Peter Marheine306c8b72022-01-21 02:07:30 +0000339if need_raw_mem_access
Thomas Heijligen74b4aa02021-12-14 17:52:30 +0100340 srcs += 'hwaccess_physmap.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000341endif
342
343if need_x86_port_io
344 srcs += 'hwaccess_x86_io.c'
Thomas Heijligena0655202021-12-14 16:36:05 +0100345 cargs += '-D__FLASHROM_HAVE_OUTB__=1'
Richard Hughescb973682018-12-19 11:44:22 +0000346endif
347
Peter Marheine306c8b72022-01-21 02:07:30 +0000348if need_x86_msr
349 srcs += 'hwaccess_x86_msr.c'
350endif
351
Richard Hughescb973682018-12-19 11:44:22 +0000352# raw serial IO
353if need_serial
Richard Hughescb973682018-12-19 11:44:22 +0000354 srcs += 'serial.c'
Thomas Heijligen140c1262021-09-27 15:12:26 +0200355 if host_machine.system() == 'linux'
356 srcs += 'custom_baud_linux.c'
357 else
358 srcs += 'custom_baud.c'
359 endif
Richard Hughescb973682018-12-19 11:44:22 +0000360endif
361
Richard Hughescb973682018-12-19 11:44:22 +0000362prefix = get_option('prefix')
363sbindir = join_paths(prefix, get_option('sbindir'))
364libdir = join_paths(prefix, get_option('libdir'))
Richard Hughesdad3a162020-02-17 09:57:01 +0000365mandir = join_paths(prefix, get_option('mandir'))
Richard Hughescb973682018-12-19 11:44:22 +0000366
367install_headers([
Thomas Heijligen58015c22022-04-14 13:50:55 +0200368 'include/libflashrom.h',
Richard Hughescb973682018-12-19 11:44:22 +0000369 ],
370)
371
Thomas Heijligen58015c22022-04-14 13:50:55 +0200372include_dir = include_directories('include')
373
Richard Hughescb973682018-12-19 11:44:22 +0000374# core modules needed by both the library and the CLI
375srcs += '82802ab.c'
376srcs += 'at45db.c'
377srcs += 'edi.c'
378srcs += 'en29lv640b.c'
379srcs += 'flashchips.c'
380srcs += 'flashrom.c'
381srcs += 'fmap.c'
382srcs += 'helpers.c'
383srcs += 'ich_descriptors.c'
384srcs += 'jedec.c'
385srcs += 'layout.c'
386srcs += 'libflashrom.c'
387srcs += 'opaque.c'
388srcs += 'print.c'
389srcs += 'programmer.c'
Thomas Heijligenbbfacff2021-03-31 20:40:01 +0200390srcs += 'programmer_table.c'
Richard Hughescb973682018-12-19 11:44:22 +0000391srcs += 'sfdp.c'
392srcs += 'spi25.c'
393srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700394srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000395srcs += 'spi.c'
396srcs += 'sst28sf040.c'
397srcs += 'sst49lfxxxc.c'
398srcs += 'sst_fwhub.c'
399srcs += 'stm50.c'
400srcs += 'udelay.c'
401srcs += 'w29ee011.c'
402srcs += 'w39.c'
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100403srcs += 'writeprotect.c'
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100404srcs += 'writeprotect_ranges.c'
Richard Hughescb973682018-12-19 11:44:22 +0000405
406mapfile = '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')