blob: 3778f4d939f1276eaa82a14e6c8fe8404c6b43df [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',
8 'optimization=s',
9 'debug=false'],
Richard Hughescb973682018-12-19 11:44:22 +000010)
11
12# libtool versioning
13lt_current = '1'
14lt_revision = '0'
15lt_age = '0'
16lt_version = '@0@.@1@.@2@'.format(lt_current, lt_age, lt_revision)
17
Jacob Garber4a84ec22019-07-25 19:12:31 -060018# hide/enable some warnings
Richard Hughescb973682018-12-19 11:44:22 +000019warning_flags = [
Anastasia Klimchukcde70112021-10-25 13:20:26 +110020 '-Wshadow',
21 '-Wmissing-prototypes',
Jacob Garber4a84ec22019-07-25 19:12:31 -060022 '-Wwrite-strings',
Richard Hughescb973682018-12-19 11:44:22 +000023 '-Wno-unused-parameter',
Richard Hughescb973682018-12-19 11:44:22 +000024 '-Wno-address-of-packed-member',
25 '-Wno-enum-conversion',
Richard Hughescb973682018-12-19 11:44:22 +000026 '-Wno-missing-braces',
27]
28
29conf = configuration_data()
30
31cc = meson.get_compiler('c')
32add_project_arguments(cc.get_supported_arguments(warning_flags), language : 'c')
33add_project_arguments('-D_DEFAULT_SOURCE', language : 'c')
Rosen Penev566193f2020-07-18 12:50:16 -070034add_project_arguments('-D_POSIX_C_SOURCE=200809L', language : 'c') # required for fileno, nanosleep, and strndup
Richard Hughescb973682018-12-19 11:44:22 +000035add_project_arguments('-D_BSD_SOURCE', language : 'c') # required for glibc < v2.19
36add_project_arguments('-DFLASHROM_VERSION="' + meson.project_version() + '"', language : 'c')
37
Thomas Heijligen847d94b2021-10-12 17:38:01 +020038if host_machine.system() in ['cygwin', 'windows']
39 add_project_arguments('-DIS_WINDOWS=1', language : 'c')
40else
41 add_project_arguments('-DIS_WINDOWS=0', language : 'c')
42endif
43
Richard Hughescb973682018-12-19 11:44:22 +000044# get defaults from configure
45config_atahpt = get_option('config_atahpt')
46config_atapromise = get_option('config_atapromise')
47config_atavia = get_option('config_atavia')
48config_buspirate_spi = get_option('config_buspirate_spi')
49config_ch341a_spi = get_option('config_ch341a_spi')
50config_dediprog = get_option('config_dediprog')
51config_developerbox_spi = get_option('config_developerbox_spi')
52config_digilent_spi = get_option('config_digilent_spi')
Jean THOMASe28d8e42022-10-11 17:54:30 +020053config_dirtyjtag_spi = get_option('config_dirtyjtag_spi')
Richard Hughescb973682018-12-19 11:44:22 +000054config_drkaiser = get_option('config_drkaiser')
55config_dummy = get_option('config_dummy')
56config_ft2232_spi = get_option('config_ft2232_spi')
57config_gfxnvidia = get_option('config_gfxnvidia')
58config_internal = get_option('config_internal')
59config_it8212 = get_option('config_it8212')
Marc Schink7ec2d632020-12-08 22:20:50 +010060config_jlink_spi = get_option('config_jlink_spi')
Richard Hughescb973682018-12-19 11:44:22 +000061config_linux_mtd = get_option('config_linux_mtd')
62config_linux_spi = get_option('config_linux_spi')
63config_mstarddc_spi = get_option('config_mstarddc_spi')
64config_nic3com = get_option('config_nic3com')
65config_nicintel_eeprom = get_option('config_nicintel_eeprom')
66config_nicintel = get_option('config_nicintel')
67config_nicintel_spi = get_option('config_nicintel_spi')
68config_nicnatsemi = get_option('config_nicnatsemi')
69config_nicrealtek = get_option('config_nicrealtek')
70config_ogp_spi = get_option('config_ogp_spi')
71config_pickit2_spi = get_option('config_pickit2_spi')
72config_pony_spi = get_option('config_pony_spi')
73config_rayer_spi = get_option('config_rayer_spi')
74config_satamv = get_option('config_satamv')
75config_satasii = get_option('config_satasii')
76config_serprog = get_option('config_serprog')
77config_usbblaster_spi = get_option('config_usbblaster_spi')
Miklós Márton324929c2019-08-01 19:14:10 +020078config_stlinkv3_spi = get_option('config_stlinkv3_spi')
Thomas Heijligen84e9c912021-06-01 16:22:14 +020079config_default_programmer_name = get_option('default_programmer_name')
80config_default_programmer_args = get_option('default_programmer_args')
Daniel Campellof7a84fd2021-03-16 17:17:14 -060081config_print_wiki= get_option('print_wiki')
Richard Hughescb973682018-12-19 11:44:22 +000082
83cargs = []
84deps = []
85srcs = []
86
Peter Marheine306c8b72022-01-21 02:07:30 +000087host_is_x86 = ['x86', 'x86_64'].contains(host_machine.cpu_family())
88
89need_serial = [
90 config_buspirate_spi, config_pony_spi, config_serprog,
91].contains(true)
92need_bitbang_spi = [
93 config_internal, config_nicintel_spi, config_ogp_spi,
94 config_pony_spi, config_rayer_spi,
95].contains(true)
96need_raw_mem_access = [
97 config_atapromise, config_drkaiser, config_gfxnvidia, config_internal,
98 config_it8212, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
99 config_ogp_spi, config_satamv, config_satasii,
100].contains(true)
101# Internal programmer uses x86 features if the system is x86
102need_x86_msr = config_internal and host_is_x86
103need_x86_port_io = [
104 config_atahpt, config_atapromise, config_internal and host_is_x86,
105 config_nic3com, config_nicnatsemi, config_nicrealtek, config_rayer_spi,
106 config_satamv,
107].contains(true)
108need_libpci = [
109 config_atahpt, config_atapromise, config_atavia,
110 config_drkaiser, config_gfxnvidia, config_internal, config_it8212,
111 config_nic3com, config_nicintel, config_nicintel_eeprom, config_nicintel_spi,
112 config_nicnatsemi, config_nicrealtek, config_ogp_spi, config_satamv,
113 config_satasii,
114].contains(true)
115need_libusb1 = [
116 config_ch341a_spi, config_dediprog, config_developerbox_spi,
117 config_digilent_spi, config_dirtyjtag_spi, config_pickit2_spi,
118 config_stlinkv3_spi,
119].contains(true)
120need_libftdi1 = [
121 config_ft2232_spi, config_usbblaster_spi,
122].contains(true)
123need_libjaylink = config_jlink_spi
124
125if (need_x86_port_io or need_x86_msr) and not host_is_x86
126 error('one or more enabled programmer only supports x86 and target is not')
127endif
128
Richard Hughescb973682018-12-19 11:44:22 +0000129
130# check for required symbols
131if cc.has_function('clock_gettime')
132 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
133endif
134if cc.has_function('strnlen')
135 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
136endif
137if cc.check_header('sys/utsname.h')
138 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
139endif
140
Thomas Heijligen5194d582022-02-19 22:31:32 +0100141srcs += 'platform/memaccess.c'
142
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100143if host_machine.endian() == 'little'
Thomas Heijligenc92f94b2022-03-17 13:41:17 +0100144 srcs += 'platform/endian_little.c'
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100145 add_project_arguments('-D__FLASHROM_LITTLE_ENDIAN__=1', language : 'c')
146endif
147if host_machine.endian() == 'big'
Thomas Heijligenc92f94b2022-03-17 13:41:17 +0100148 srcs += 'platform/endian_big.c'
Thomas Heijligen5618d5b2022-02-19 21:17:44 +0100149 add_project_arguments('-D__FLASHROM_BIG_ENDIAN__=1', language : 'c')
150endif
151
Richard Hughescb973682018-12-19 11:44:22 +0000152# some programmers require libusb
153if get_option('usb')
154 srcs += 'usbdev.c'
155 deps += dependency('libusb-1.0')
Peter Marheine306c8b72022-01-21 02:07:30 +0000156elif need_libusb1
157 error('usb is disabled but one or more enabled programmer requires USB access')
Richard Hughescb973682018-12-19 11:44:22 +0000158endif
159
160# some programmers require libpci
161if get_option('pciutils')
162 srcs += 'pcidev.c'
163 deps += dependency('libpci')
Peter Marheine306c8b72022-01-21 02:07:30 +0000164elif need_libpci
165 error('pciutils is disabled but one or more enabled programmer requires PCI access')
166endif
167
168if need_libftdi1
169 deps += dependency('libftdi1')
170endif
171
172if need_libjaylink
173 deps += dependency('libjaylink')
Richard Hughescb973682018-12-19 11:44:22 +0000174endif
175
176# set defines for configured programmers
177if config_atahpt
178 srcs += 'atahpt.c'
179 cargs += '-DCONFIG_ATAHPT=1'
180endif
181if config_atapromise
182 srcs += 'atapromise.c'
183 cargs += '-DCONFIG_ATAPROMISE=1'
184endif
185if config_atavia
186 srcs += 'atavia.c'
187 cargs += '-DCONFIG_ATAVIA=1'
188endif
189if config_buspirate_spi
190 srcs += 'buspirate_spi.c'
191 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000192endif
193if config_ch341a_spi
194 srcs += 'ch341a_spi.c'
195 cargs += '-DCONFIG_CH341A_SPI=1'
196endif
197if config_dediprog
198 srcs += 'dediprog.c'
199 cargs += '-DCONFIG_DEDIPROG=1'
200endif
201if config_developerbox_spi
202 srcs += 'developerbox_spi.c'
203 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
204endif
205if config_digilent_spi
206 srcs += 'digilent_spi.c'
207 cargs += '-DCONFIG_DIGILENT_SPI=1'
208endif
Jean THOMASe28d8e42022-10-11 17:54:30 +0200209if config_dirtyjtag_spi
210 srcs += 'dirtyjtag_spi.c'
211 cargs += '-DCONFIG_DIRTYJTAG_SPI=1'
212endif
Richard Hughescb973682018-12-19 11:44:22 +0000213if config_drkaiser
214 srcs += 'drkaiser.c'
215 cargs += '-DCONFIG_DRKAISER=1'
216endif
217if config_dummy
218 srcs += 'dummyflasher.c'
219 cargs += '-DCONFIG_DUMMY=1'
220endif
221if config_ft2232_spi
222 srcs += 'ft2232_spi.c'
223 cargs += '-DCONFIG_FT2232_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000224 cargs += '-DHAVE_FT232H=1'
225endif
226if config_gfxnvidia
227 srcs += 'gfxnvidia.c'
228 cargs += '-DCONFIG_GFXNVIDIA=1'
229endif
230if config_internal
231 srcs += 'board_enable.c'
232 srcs += 'cbtable.c'
233 srcs += 'chipset_enable.c'
234 srcs += 'internal.c'
235 srcs += 'processor_enable.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000236 if host_is_x86
Richard Hughescb973682018-12-19 11:44:22 +0000237 srcs += 'amd_imc.c'
238 srcs += 'dmi.c'
239 srcs += 'ichspi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000240 srcs += 'it87spi.c'
241 srcs += 'mcp6x_spi.c'
242 srcs += 'sb600spi.c'
243 srcs += 'wbsio_spi.c'
244 endif
Richard Hughescb973682018-12-19 11:44:22 +0000245 cargs += '-DCONFIG_INTERNAL=1'
246 if get_option('config_internal_dmi')
247 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
248 cargs += '-DCONFIG_INTERNAL_DMI=1'
249 endif
250endif
251if config_it8212
252 srcs += 'it8212.c'
253 cargs += '-DCONFIG_IT8212=1'
254endif
Marc Schink7ec2d632020-12-08 22:20:50 +0100255if config_jlink_spi
256 srcs += 'jlink_spi.c'
257 cargs += '-DCONFIG_JLINK_SPI=1'
Marc Schink7ec2d632020-12-08 22:20:50 +0100258endif
Richard Hughescb973682018-12-19 11:44:22 +0000259if config_linux_mtd
260 srcs += 'linux_mtd.c'
261 cargs += '-DCONFIG_LINUX_MTD=1'
262endif
263if config_linux_spi
264 srcs += 'linux_spi.c'
265 cargs += '-DCONFIG_LINUX_SPI=1'
266endif
267if config_mstarddc_spi
268 srcs += 'mstarddc_spi.c'
269 cargs += '-DCONFIG_MSTARDDC_SPI=1'
270endif
271if config_nic3com
272 srcs += 'nic3com.c'
273 cargs += '-DCONFIG_NIC3COM=1'
274endif
275if config_nicintel
276 srcs += 'nicintel.c'
277 cargs += '-DCONFIG_NICINTEL=1'
278endif
279if config_nicintel_eeprom
280 srcs += 'nicintel_eeprom.c'
281 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
282endif
283if config_nicintel_spi
284 srcs += 'nicintel_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000285 cargs += '-DCONFIG_NICINTEL_SPI=1'
286endif
287if config_nicnatsemi
288 srcs += 'nicnatsemi.c'
289 cargs += '-DCONFIG_NICNATSEMI=1'
290endif
291if config_nicrealtek
292 srcs += 'nicrealtek.c'
293 cargs += '-DCONFIG_NICREALTEK=1'
294endif
295if config_ogp_spi
Richard Hughescb973682018-12-19 11:44:22 +0000296 srcs += 'ogp_spi.c'
297 cargs += '-DCONFIG_OGP_SPI=1'
298endif
299if config_pickit2_spi
300 srcs += 'pickit2_spi.c'
301 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000302endif
303if config_pony_spi
304 srcs += 'pony_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000305 cargs += '-DCONFIG_PONY_SPI=1'
306endif
307if config_rayer_spi
308 srcs += 'rayer_spi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000309 cargs += '-DCONFIG_RAYER_SPI=1'
310endif
311if config_satamv
312 srcs += 'satamv.c'
313 cargs += '-DCONFIG_SATAMV=1'
314endif
315if config_satasii
316 srcs += 'satasii.c'
317 cargs += '-DCONFIG_SATASII=1'
318endif
319if config_serprog
320 srcs += 'serprog.c'
321 cargs += '-DCONFIG_SERPROG=1'
Richard Hughescb973682018-12-19 11:44:22 +0000322endif
323if config_usbblaster_spi
324 srcs += 'usbblaster_spi.c'
325 cargs += '-DCONFIG_USBBLASTER_SPI=1'
326endif
Miklós Márton324929c2019-08-01 19:14:10 +0200327if config_stlinkv3_spi
328 srcs += 'stlinkv3_spi.c'
329 cargs += '-DCONFIG_STLINKV3_SPI=1'
330endif
Richard Hughescb973682018-12-19 11:44:22 +0000331
332# bitbanging SPI infrastructure
Peter Marheine306c8b72022-01-21 02:07:30 +0000333if need_bitbang_spi
Richard Hughescb973682018-12-19 11:44:22 +0000334 srcs += 'bitbang_spi.c'
335 cargs += '-DCONFIG_BITBANG_SPI=1'
336endif
337
Peter Marheine306c8b72022-01-21 02:07:30 +0000338if need_raw_mem_access
Thomas Heijligen74b4aa02021-12-14 17:52:30 +0100339 srcs += 'hwaccess_physmap.c'
Peter Marheine306c8b72022-01-21 02:07:30 +0000340endif
341
342if need_x86_port_io
343 srcs += 'hwaccess_x86_io.c'
Thomas Heijligena0655202021-12-14 16:36:05 +0100344 cargs += '-D__FLASHROM_HAVE_OUTB__=1'
Richard Hughescb973682018-12-19 11:44:22 +0000345endif
346
Peter Marheine306c8b72022-01-21 02:07:30 +0000347if need_x86_msr
348 srcs += 'hwaccess_x86_msr.c'
349endif
350
Richard Hughescb973682018-12-19 11:44:22 +0000351# raw serial IO
352if need_serial
Richard Hughescb973682018-12-19 11:44:22 +0000353 srcs += 'serial.c'
Thomas Heijligen140c1262021-09-27 15:12:26 +0200354 if host_machine.system() == 'linux'
355 srcs += 'custom_baud_linux.c'
356 else
357 srcs += 'custom_baud.c'
358 endif
Richard Hughescb973682018-12-19 11:44:22 +0000359endif
360
Richard Hughescb973682018-12-19 11:44:22 +0000361prefix = get_option('prefix')
362sbindir = join_paths(prefix, get_option('sbindir'))
363libdir = join_paths(prefix, get_option('libdir'))
Richard Hughesdad3a162020-02-17 09:57:01 +0000364mandir = join_paths(prefix, get_option('mandir'))
Richard Hughescb973682018-12-19 11:44:22 +0000365
366install_headers([
Thomas Heijligen58015c22022-04-14 13:50:55 +0200367 'include/libflashrom.h',
Richard Hughescb973682018-12-19 11:44:22 +0000368 ],
369)
370
Thomas Heijligen58015c22022-04-14 13:50:55 +0200371include_dir = include_directories('include')
372
Richard Hughescb973682018-12-19 11:44:22 +0000373# core modules needed by both the library and the CLI
374srcs += '82802ab.c'
375srcs += 'at45db.c'
376srcs += 'edi.c'
377srcs += 'en29lv640b.c'
378srcs += 'flashchips.c'
379srcs += 'flashrom.c'
380srcs += 'fmap.c'
381srcs += 'helpers.c'
382srcs += 'ich_descriptors.c'
383srcs += 'jedec.c'
384srcs += 'layout.c'
385srcs += 'libflashrom.c'
386srcs += 'opaque.c'
387srcs += 'print.c'
388srcs += 'programmer.c'
Thomas Heijligenbbfacff2021-03-31 20:40:01 +0200389srcs += 'programmer_table.c'
Richard Hughescb973682018-12-19 11:44:22 +0000390srcs += 'sfdp.c'
391srcs += 'spi25.c'
392srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700393srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000394srcs += 'spi.c'
395srcs += 'sst28sf040.c'
396srcs += 'sst49lfxxxc.c'
397srcs += 'sst_fwhub.c'
398srcs += 'stm50.c'
399srcs += 'udelay.c'
400srcs += 'w29ee011.c'
401srcs += 'w39.c'
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100402srcs += 'writeprotect.c'
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100403srcs += 'writeprotect_ranges.c'
Richard Hughescb973682018-12-19 11:44:22 +0000404
405mapfile = 'libflashrom.map'
406vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
Daniel Campello4bcc9a32021-03-17 18:03:28 -0600407flashrom = library(
Richard Hughescb973682018-12-19 11:44:22 +0000408 'flashrom',
409 sources : [
410 srcs,
411 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200412 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000413 soversion : lt_current,
414 version : lt_version,
415 dependencies : [
416 deps,
417 ],
418 c_args : [
419 cargs,
420 ],
421 install : true,
422 link_args : vflag,
423 link_depends : mapfile,
424)
425
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500426version = meson.project_version()
427#strip leading characters
428if version.startswith('v')
429 version = version.split('v')[1]
430endif
431if version.startswith('p')
432 version = version.split('p')[1]
433endif
434
Richard Hughescb973682018-12-19 11:44:22 +0000435pkgg = import('pkgconfig')
436pkgg.generate(
437 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500438 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500439 name : 'flashrom',
440 filebase : 'flashrom',
441 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000442)
443
Richard Hughesdad3a162020-02-17 09:57:01 +0000444conf.set('VERSION', version)
Samuel R. Messner21bcfa92022-02-17 06:17:31 +0100445conf.set('MAN_DATE', run_command('util/getversion.sh', '--man-date').stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000446configure_file(
447 input : 'flashrom.8.tmpl',
448 output : 'flashrom.8',
449 configuration : conf,
450 install: true,
451 install_dir: join_paths(mandir, 'man8'),
452)
453
Richard Hughescb973682018-12-19 11:44:22 +0000454flashrom_dep = declare_dependency(
455 link_with : flashrom,
Thomas Heijligen58015c22022-04-14 13:50:55 +0200456 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000457 dependencies : deps
458)
459
Thomas Heijligen84e9c912021-06-01 16:22:14 +0200460if config_default_programmer_name != ''
461 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
462else
463 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
464endif
465
466cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
467
Daniel Campellof7a84fd2021-03-16 17:17:14 -0600468if config_print_wiki
469 srcs += 'print_wiki.c'
470 cargs += '-DCONFIG_PRINT_WIKI=1'
471endif
472
Richard Hughescb973682018-12-19 11:44:22 +0000473# we can't just link_with libflashrom as we require all the internal symbols...
474executable(
475 'flashrom',
476 sources : [
477 srcs,
478 'cli_classic.c',
479 'cli_common.c',
480 'cli_output.c',
481 'flashrom.c',
482 ],
Thomas Heijligen58015c22022-04-14 13:50:55 +0200483 include_directories : include_dir,
Richard Hughescb973682018-12-19 11:44:22 +0000484 dependencies : [
485 deps,
486 ],
487 c_args : [
488 cargs,
Richard Hughescb973682018-12-19 11:44:22 +0000489 ],
490 install : true,
491 install_dir : sbindir,
492)
493
494subdir('util')