blob: dceadc84e2bd61a52574c6fd2f925bf89846dd3f [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
Richard Hughescb973682018-12-19 11:44:22 +0000106need_raw_access = false
107need_serial = false
108
109# check for required symbols
110if cc.has_function('clock_gettime')
111 add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c')
112endif
113if cc.has_function('strnlen')
114 add_project_arguments('-DHAVE_STRNLEN=1', language : 'c')
115endif
116if cc.check_header('sys/utsname.h')
117 add_project_arguments('-DHAVE_UTSNAME=1', language : 'c')
118endif
119
120# some programmers require libusb
121if get_option('usb')
122 srcs += 'usbdev.c'
123 deps += dependency('libusb-1.0')
124else
125 config_ch341a_spi = false
126 config_dediprog = false
127 config_digilent_spi = false
Jean THOMASe28d8e42022-10-11 17:54:30 +0200128 config_dirtyjtag_spi = false
Richard Hughescb973682018-12-19 11:44:22 +0000129 config_developerbox_spi = false
Thomas Heijligenb221cd72019-04-05 15:08:35 +0200130 config_pickit2_spi = false
Richard Hughescb973682018-12-19 11:44:22 +0000131endif
132
133# some programmers require libpci
134if get_option('pciutils')
135 srcs += 'pcidev.c'
136 deps += dependency('libpci')
Daniel Campello924e6312021-03-17 09:14:11 -0600137 need_raw_access = true
Richard Hughescb973682018-12-19 11:44:22 +0000138 cargs += '-DNEED_PCI=1'
139else
140 config_atahpt = false
141 config_atapromise = false
142 config_atavia = false
143 config_drkaiser = false
144 config_gfxnvidia = false
145 config_internal = false
146 config_it8212 = false
147 config_nic3com = false
148 config_nicintel_eeprom = false
149 config_nicintel = false
150 config_nicintel_spi = false
151 config_nicnatsemi = false
152 config_nicrealtek = false
153 config_ogp_spi = false
Richard Hughescb973682018-12-19 11:44:22 +0000154 config_satamv = false
155 config_satasii = false
156endif
157
158# set defines for configured programmers
159if config_atahpt
160 srcs += 'atahpt.c'
161 cargs += '-DCONFIG_ATAHPT=1'
162endif
163if config_atapromise
164 srcs += 'atapromise.c'
165 cargs += '-DCONFIG_ATAPROMISE=1'
166endif
167if config_atavia
168 srcs += 'atavia.c'
169 cargs += '-DCONFIG_ATAVIA=1'
170endif
171if config_buspirate_spi
172 srcs += 'buspirate_spi.c'
173 cargs += '-DCONFIG_BUSPIRATE_SPI=1'
174 need_serial = true
175endif
176if config_ch341a_spi
177 srcs += 'ch341a_spi.c'
178 cargs += '-DCONFIG_CH341A_SPI=1'
179endif
180if config_dediprog
181 srcs += 'dediprog.c'
182 cargs += '-DCONFIG_DEDIPROG=1'
183endif
184if config_developerbox_spi
185 srcs += 'developerbox_spi.c'
186 cargs += '-DCONFIG_DEVELOPERBOX_SPI=1'
187endif
188if config_digilent_spi
189 srcs += 'digilent_spi.c'
190 cargs += '-DCONFIG_DIGILENT_SPI=1'
191endif
Jean THOMASe28d8e42022-10-11 17:54:30 +0200192if config_dirtyjtag_spi
193 srcs += 'dirtyjtag_spi.c'
194 cargs += '-DCONFIG_DIRTYJTAG_SPI=1'
195endif
Richard Hughescb973682018-12-19 11:44:22 +0000196if config_drkaiser
197 srcs += 'drkaiser.c'
198 cargs += '-DCONFIG_DRKAISER=1'
199endif
200if config_dummy
201 srcs += 'dummyflasher.c'
202 cargs += '-DCONFIG_DUMMY=1'
203endif
204if config_ft2232_spi
205 srcs += 'ft2232_spi.c'
206 cargs += '-DCONFIG_FT2232_SPI=1'
207 deps += dependency('libftdi1')
208 cargs += '-DHAVE_FT232H=1'
209endif
210if config_gfxnvidia
211 srcs += 'gfxnvidia.c'
212 cargs += '-DCONFIG_GFXNVIDIA=1'
213endif
214if config_internal
215 srcs += 'board_enable.c'
216 srcs += 'cbtable.c'
217 srcs += 'chipset_enable.c'
218 srcs += 'internal.c'
219 srcs += 'processor_enable.c'
220 if target_machine.cpu_family() == 'x86' or target_machine.cpu_family() == 'x86_64'
221 srcs += 'amd_imc.c'
222 srcs += 'dmi.c'
223 srcs += 'ichspi.c'
Richard Hughescb973682018-12-19 11:44:22 +0000224 srcs += 'it87spi.c'
225 srcs += 'mcp6x_spi.c'
226 srcs += 'sb600spi.c'
227 srcs += 'wbsio_spi.c'
228 endif
229 config_bitbang_spi = true
230 cargs += '-DCONFIG_INTERNAL=1'
231 if get_option('config_internal_dmi')
232 # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
233 cargs += '-DCONFIG_INTERNAL_DMI=1'
234 endif
235endif
236if config_it8212
237 srcs += 'it8212.c'
238 cargs += '-DCONFIG_IT8212=1'
239endif
Marc Schink7ec2d632020-12-08 22:20:50 +0100240if config_jlink_spi
241 srcs += 'jlink_spi.c'
242 cargs += '-DCONFIG_JLINK_SPI=1'
243 deps += dependency('libjaylink')
244endif
Richard Hughescb973682018-12-19 11:44:22 +0000245if config_linux_mtd
246 srcs += 'linux_mtd.c'
247 cargs += '-DCONFIG_LINUX_MTD=1'
248endif
249if config_linux_spi
250 srcs += 'linux_spi.c'
251 cargs += '-DCONFIG_LINUX_SPI=1'
252endif
253if config_mstarddc_spi
254 srcs += 'mstarddc_spi.c'
255 cargs += '-DCONFIG_MSTARDDC_SPI=1'
256endif
257if config_nic3com
258 srcs += 'nic3com.c'
259 cargs += '-DCONFIG_NIC3COM=1'
260endif
261if config_nicintel
262 srcs += 'nicintel.c'
263 cargs += '-DCONFIG_NICINTEL=1'
264endif
265if config_nicintel_eeprom
266 srcs += 'nicintel_eeprom.c'
267 cargs += '-DCONFIG_NICINTEL_EEPROM=1'
268endif
269if config_nicintel_spi
270 srcs += 'nicintel_spi.c'
271 config_bitbang_spi = true
272 cargs += '-DCONFIG_NICINTEL_SPI=1'
273endif
274if config_nicnatsemi
275 srcs += 'nicnatsemi.c'
276 cargs += '-DCONFIG_NICNATSEMI=1'
277endif
278if config_nicrealtek
279 srcs += 'nicrealtek.c'
280 cargs += '-DCONFIG_NICREALTEK=1'
281endif
282if config_ogp_spi
283 config_bitbang_spi = true
284 srcs += 'ogp_spi.c'
285 cargs += '-DCONFIG_OGP_SPI=1'
286endif
287if config_pickit2_spi
288 srcs += 'pickit2_spi.c'
289 cargs += '-DCONFIG_PICKIT2_SPI=1'
Richard Hughescb973682018-12-19 11:44:22 +0000290endif
291if config_pony_spi
292 srcs += 'pony_spi.c'
293 need_serial = true
294 config_bitbang_spi = true
295 cargs += '-DCONFIG_PONY_SPI=1'
296endif
297if config_rayer_spi
298 srcs += 'rayer_spi.c'
299 config_bitbang_spi = true
300 need_raw_access = true
301 cargs += '-DCONFIG_RAYER_SPI=1'
302endif
303if config_satamv
304 srcs += 'satamv.c'
305 cargs += '-DCONFIG_SATAMV=1'
306endif
307if config_satasii
308 srcs += 'satasii.c'
309 cargs += '-DCONFIG_SATASII=1'
310endif
311if config_serprog
312 srcs += 'serprog.c'
313 cargs += '-DCONFIG_SERPROG=1'
314 need_serial = true
315endif
316if config_usbblaster_spi
317 srcs += 'usbblaster_spi.c'
318 cargs += '-DCONFIG_USBBLASTER_SPI=1'
319endif
Miklós Márton324929c2019-08-01 19:14:10 +0200320if config_stlinkv3_spi
321 srcs += 'stlinkv3_spi.c'
322 cargs += '-DCONFIG_STLINKV3_SPI=1'
323endif
Richard Hughescb973682018-12-19 11:44:22 +0000324
325# bitbanging SPI infrastructure
326if config_bitbang_spi
327 srcs += 'bitbang_spi.c'
328 cargs += '-DCONFIG_BITBANG_SPI=1'
329endif
330
331# raw memory, MSR or PCI port I/O access
332if need_raw_access
333 srcs += 'hwaccess.c'
334 srcs += 'physmap.c'
335 cargs += '-DNEED_RAW_ACCESS=1'
336endif
337
338# raw serial IO
339if need_serial
Richard Hughescb973682018-12-19 11:44:22 +0000340 srcs += 'serial.c'
Thomas Heijligen140c1262021-09-27 15:12:26 +0200341 if host_machine.system() == 'linux'
342 srcs += 'custom_baud_linux.c'
343 else
344 srcs += 'custom_baud.c'
345 endif
Richard Hughescb973682018-12-19 11:44:22 +0000346endif
347
Richard Hughescb973682018-12-19 11:44:22 +0000348prefix = get_option('prefix')
349sbindir = join_paths(prefix, get_option('sbindir'))
350libdir = join_paths(prefix, get_option('libdir'))
Richard Hughesdad3a162020-02-17 09:57:01 +0000351mandir = join_paths(prefix, get_option('mandir'))
Richard Hughescb973682018-12-19 11:44:22 +0000352
353install_headers([
354 'libflashrom.h',
355 ],
356)
357
358# core modules needed by both the library and the CLI
359srcs += '82802ab.c'
360srcs += 'at45db.c'
361srcs += 'edi.c'
362srcs += 'en29lv640b.c'
363srcs += 'flashchips.c'
364srcs += 'flashrom.c'
365srcs += 'fmap.c'
366srcs += 'helpers.c'
367srcs += 'ich_descriptors.c'
368srcs += 'jedec.c'
369srcs += 'layout.c'
370srcs += 'libflashrom.c'
371srcs += 'opaque.c'
372srcs += 'print.c'
373srcs += 'programmer.c'
Thomas Heijligenbbfacff2021-03-31 20:40:01 +0200374srcs += 'programmer_table.c'
Richard Hughescb973682018-12-19 11:44:22 +0000375srcs += 'sfdp.c'
376srcs += 'spi25.c'
377srcs += 'spi25_statusreg.c'
David Hendricks349b5d22019-10-05 12:44:27 -0700378srcs += 'spi95.c'
Richard Hughescb973682018-12-19 11:44:22 +0000379srcs += 'spi.c'
380srcs += 'sst28sf040.c'
381srcs += 'sst49lfxxxc.c'
382srcs += 'sst_fwhub.c'
383srcs += 'stm50.c'
384srcs += 'udelay.c'
385srcs += 'w29ee011.c'
386srcs += 'w39.c'
Nikolai Artemievda1c8342021-10-21 00:58:12 +1100387srcs += 'writeprotect.c'
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100388srcs += 'writeprotect_ranges.c'
Richard Hughescb973682018-12-19 11:44:22 +0000389
390mapfile = 'libflashrom.map'
391vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile)
Daniel Campello4bcc9a32021-03-17 18:03:28 -0600392flashrom = library(
Richard Hughescb973682018-12-19 11:44:22 +0000393 'flashrom',
394 sources : [
395 srcs,
396 ],
397 soversion : lt_current,
398 version : lt_version,
399 dependencies : [
400 deps,
401 ],
402 c_args : [
403 cargs,
404 ],
405 install : true,
406 link_args : vflag,
407 link_depends : mapfile,
408)
409
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500410version = meson.project_version()
411#strip leading characters
412if version.startswith('v')
413 version = version.split('v')[1]
414endif
415if version.startswith('p')
416 version = version.split('p')[1]
417endif
418
Richard Hughescb973682018-12-19 11:44:22 +0000419pkgg = import('pkgconfig')
420pkgg.generate(
421 libraries : flashrom,
Mario Limonciellod954d5d2019-09-24 16:06:57 -0500422 version : version,
Mario Limonciello2a8d4392019-10-15 13:32:19 -0500423 name : 'flashrom',
424 filebase : 'flashrom',
425 description : 'library to interact with flashrom',
Richard Hughescb973682018-12-19 11:44:22 +0000426)
427
Richard Hughesdad3a162020-02-17 09:57:01 +0000428conf.set('VERSION', version)
Samuel R. Messner21bcfa92022-02-17 06:17:31 +0100429conf.set('MAN_DATE', run_command('util/getversion.sh', '--man-date').stdout().strip())
Richard Hughesdad3a162020-02-17 09:57:01 +0000430configure_file(
431 input : 'flashrom.8.tmpl',
432 output : 'flashrom.8',
433 configuration : conf,
434 install: true,
435 install_dir: join_paths(mandir, 'man8'),
436)
437
Richard Hughescb973682018-12-19 11:44:22 +0000438flashrom_dep = declare_dependency(
439 link_with : flashrom,
440 include_directories : include_directories('.'),
441 dependencies : deps
442)
443
Thomas Heijligen84e9c912021-06-01 16:22:14 +0200444if config_default_programmer_name != ''
445 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_' + config_default_programmer_name
446else
447 cargs += '-DCONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
448endif
449
450cargs += '-DCONFIG_DEFAULT_PROGRAMMER_ARGS="' + config_default_programmer_args + '"'
451
Daniel Campellof7a84fd2021-03-16 17:17:14 -0600452if config_print_wiki
453 srcs += 'print_wiki.c'
454 cargs += '-DCONFIG_PRINT_WIKI=1'
455endif
456
Richard Hughescb973682018-12-19 11:44:22 +0000457# we can't just link_with libflashrom as we require all the internal symbols...
458executable(
459 'flashrom',
460 sources : [
461 srcs,
462 'cli_classic.c',
463 'cli_common.c',
464 'cli_output.c',
465 'flashrom.c',
466 ],
467 dependencies : [
468 deps,
469 ],
470 c_args : [
471 cargs,
Richard Hughescb973682018-12-19 11:44:22 +0000472 ],
473 install : true,
474 install_dir : sbindir,
475)
476
477subdir('util')