Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 1 | project('flashromutils', 'c', |
Nico Huber | 2f6936b | 2019-09-24 18:31:38 +0200 | [diff] [blame] | 2 | version : run_command('util/getversion.sh', '-v').stdout().strip(), |
Nico Huber | b417c0c | 2019-09-24 22:12:40 +0200 | [diff] [blame] | 3 | license : 'GPL-2.0', |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 4 | meson_version : '>=0.47.0', |
| 5 | default_options : ['warning_level=2', 'c_std=c99'], |
| 6 | ) |
| 7 | |
| 8 | # libtool versioning |
| 9 | lt_current = '1' |
| 10 | lt_revision = '0' |
| 11 | lt_age = '0' |
| 12 | lt_version = '@0@.@1@.@2@'.format(lt_current, lt_age, lt_revision) |
| 13 | |
Jacob Garber | 4a84ec2 | 2019-07-25 19:12:31 -0600 | [diff] [blame] | 14 | # hide/enable some warnings |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 15 | warning_flags = [ |
Jacob Garber | 4a84ec2 | 2019-07-25 19:12:31 -0600 | [diff] [blame] | 16 | '-Wwrite-strings', |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 17 | '-Wno-unused-parameter', |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 18 | '-Wno-address-of-packed-member', |
| 19 | '-Wno-enum-conversion', |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 20 | '-Wno-missing-braces', |
| 21 | ] |
| 22 | |
| 23 | conf = configuration_data() |
| 24 | |
| 25 | cc = meson.get_compiler('c') |
| 26 | add_project_arguments(cc.get_supported_arguments(warning_flags), language : 'c') |
| 27 | add_project_arguments('-D_DEFAULT_SOURCE', language : 'c') |
| 28 | add_project_arguments('-D_POSIX_C_SOURCE', language : 'c') # required for fileno |
| 29 | add_project_arguments('-D_BSD_SOURCE', language : 'c') # required for glibc < v2.19 |
| 30 | add_project_arguments('-DFLASHROM_VERSION="' + meson.project_version() + '"', language : 'c') |
| 31 | |
| 32 | # get defaults from configure |
| 33 | config_atahpt = get_option('config_atahpt') |
| 34 | config_atapromise = get_option('config_atapromise') |
| 35 | config_atavia = get_option('config_atavia') |
| 36 | config_buspirate_spi = get_option('config_buspirate_spi') |
| 37 | config_ch341a_spi = get_option('config_ch341a_spi') |
| 38 | config_dediprog = get_option('config_dediprog') |
| 39 | config_developerbox_spi = get_option('config_developerbox_spi') |
| 40 | config_digilent_spi = get_option('config_digilent_spi') |
| 41 | config_drkaiser = get_option('config_drkaiser') |
| 42 | config_dummy = get_option('config_dummy') |
| 43 | config_ft2232_spi = get_option('config_ft2232_spi') |
| 44 | config_gfxnvidia = get_option('config_gfxnvidia') |
| 45 | config_internal = get_option('config_internal') |
| 46 | config_it8212 = get_option('config_it8212') |
| 47 | config_linux_mtd = get_option('config_linux_mtd') |
| 48 | config_linux_spi = get_option('config_linux_spi') |
| 49 | config_mstarddc_spi = get_option('config_mstarddc_spi') |
| 50 | config_nic3com = get_option('config_nic3com') |
| 51 | config_nicintel_eeprom = get_option('config_nicintel_eeprom') |
| 52 | config_nicintel = get_option('config_nicintel') |
| 53 | config_nicintel_spi = get_option('config_nicintel_spi') |
| 54 | config_nicnatsemi = get_option('config_nicnatsemi') |
| 55 | config_nicrealtek = get_option('config_nicrealtek') |
| 56 | config_ogp_spi = get_option('config_ogp_spi') |
| 57 | config_pickit2_spi = get_option('config_pickit2_spi') |
| 58 | config_pony_spi = get_option('config_pony_spi') |
| 59 | config_rayer_spi = get_option('config_rayer_spi') |
| 60 | config_satamv = get_option('config_satamv') |
| 61 | config_satasii = get_option('config_satasii') |
| 62 | config_serprog = get_option('config_serprog') |
| 63 | config_usbblaster_spi = get_option('config_usbblaster_spi') |
Miklós Márton | 324929c | 2019-08-01 19:14:10 +0200 | [diff] [blame] | 64 | config_stlinkv3_spi = get_option('config_stlinkv3_spi') |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 65 | |
| 66 | cargs = [] |
| 67 | deps = [] |
| 68 | srcs = [] |
| 69 | |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 70 | need_raw_access = false |
| 71 | need_serial = false |
| 72 | |
| 73 | # check for required symbols |
| 74 | if cc.has_function('clock_gettime') |
| 75 | add_project_arguments('-DHAVE_CLOCK_GETTIME=1', language : 'c') |
| 76 | endif |
| 77 | if cc.has_function('strnlen') |
| 78 | add_project_arguments('-DHAVE_STRNLEN=1', language : 'c') |
| 79 | endif |
| 80 | if cc.check_header('sys/utsname.h') |
| 81 | add_project_arguments('-DHAVE_UTSNAME=1', language : 'c') |
| 82 | endif |
| 83 | |
| 84 | # some programmers require libusb |
| 85 | if get_option('usb') |
| 86 | srcs += 'usbdev.c' |
| 87 | deps += dependency('libusb-1.0') |
| 88 | else |
| 89 | config_ch341a_spi = false |
| 90 | config_dediprog = false |
| 91 | config_digilent_spi = false |
| 92 | config_developerbox_spi = false |
Thomas Heijligen | b221cd7 | 2019-04-05 15:08:35 +0200 | [diff] [blame] | 93 | config_pickit2_spi = false |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 94 | endif |
| 95 | |
| 96 | # some programmers require libpci |
| 97 | if get_option('pciutils') |
| 98 | srcs += 'pcidev.c' |
| 99 | deps += dependency('libpci') |
| 100 | cargs += '-DNEED_PCI=1' |
| 101 | else |
| 102 | config_atahpt = false |
| 103 | config_atapromise = false |
| 104 | config_atavia = false |
| 105 | config_drkaiser = false |
| 106 | config_gfxnvidia = false |
| 107 | config_internal = false |
| 108 | config_it8212 = false |
| 109 | config_nic3com = false |
| 110 | config_nicintel_eeprom = false |
| 111 | config_nicintel = false |
| 112 | config_nicintel_spi = false |
| 113 | config_nicnatsemi = false |
| 114 | config_nicrealtek = false |
| 115 | config_ogp_spi = false |
| 116 | config_rayer_spi = false |
| 117 | config_satamv = false |
| 118 | config_satasii = false |
| 119 | endif |
| 120 | |
| 121 | # set defines for configured programmers |
| 122 | if config_atahpt |
| 123 | srcs += 'atahpt.c' |
| 124 | cargs += '-DCONFIG_ATAHPT=1' |
| 125 | endif |
| 126 | if config_atapromise |
| 127 | srcs += 'atapromise.c' |
| 128 | cargs += '-DCONFIG_ATAPROMISE=1' |
| 129 | endif |
| 130 | if config_atavia |
| 131 | srcs += 'atavia.c' |
| 132 | cargs += '-DCONFIG_ATAVIA=1' |
| 133 | endif |
| 134 | if config_buspirate_spi |
| 135 | srcs += 'buspirate_spi.c' |
| 136 | cargs += '-DCONFIG_BUSPIRATE_SPI=1' |
| 137 | need_serial = true |
| 138 | endif |
| 139 | if config_ch341a_spi |
| 140 | srcs += 'ch341a_spi.c' |
| 141 | cargs += '-DCONFIG_CH341A_SPI=1' |
| 142 | endif |
| 143 | if config_dediprog |
| 144 | srcs += 'dediprog.c' |
| 145 | cargs += '-DCONFIG_DEDIPROG=1' |
| 146 | endif |
| 147 | if config_developerbox_spi |
| 148 | srcs += 'developerbox_spi.c' |
| 149 | cargs += '-DCONFIG_DEVELOPERBOX_SPI=1' |
| 150 | endif |
| 151 | if config_digilent_spi |
| 152 | srcs += 'digilent_spi.c' |
| 153 | cargs += '-DCONFIG_DIGILENT_SPI=1' |
| 154 | endif |
| 155 | if config_drkaiser |
| 156 | srcs += 'drkaiser.c' |
| 157 | cargs += '-DCONFIG_DRKAISER=1' |
| 158 | endif |
| 159 | if config_dummy |
| 160 | srcs += 'dummyflasher.c' |
| 161 | cargs += '-DCONFIG_DUMMY=1' |
| 162 | endif |
| 163 | if config_ft2232_spi |
| 164 | srcs += 'ft2232_spi.c' |
| 165 | cargs += '-DCONFIG_FT2232_SPI=1' |
| 166 | deps += dependency('libftdi1') |
| 167 | cargs += '-DHAVE_FT232H=1' |
| 168 | endif |
| 169 | if config_gfxnvidia |
| 170 | srcs += 'gfxnvidia.c' |
| 171 | cargs += '-DCONFIG_GFXNVIDIA=1' |
| 172 | endif |
| 173 | if config_internal |
| 174 | srcs += 'board_enable.c' |
| 175 | srcs += 'cbtable.c' |
| 176 | srcs += 'chipset_enable.c' |
| 177 | srcs += 'internal.c' |
| 178 | srcs += 'processor_enable.c' |
| 179 | if target_machine.cpu_family() == 'x86' or target_machine.cpu_family() == 'x86_64' |
| 180 | srcs += 'amd_imc.c' |
| 181 | srcs += 'dmi.c' |
| 182 | srcs += 'ichspi.c' |
| 183 | srcs += 'it85spi.c' |
| 184 | srcs += 'it87spi.c' |
| 185 | srcs += 'mcp6x_spi.c' |
| 186 | srcs += 'sb600spi.c' |
| 187 | srcs += 'wbsio_spi.c' |
| 188 | endif |
| 189 | config_bitbang_spi = true |
| 190 | cargs += '-DCONFIG_INTERNAL=1' |
| 191 | if get_option('config_internal_dmi') |
| 192 | # Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode. |
| 193 | cargs += '-DCONFIG_INTERNAL_DMI=1' |
| 194 | endif |
| 195 | endif |
| 196 | if config_it8212 |
| 197 | srcs += 'it8212.c' |
| 198 | cargs += '-DCONFIG_IT8212=1' |
| 199 | endif |
| 200 | if config_linux_mtd |
| 201 | srcs += 'linux_mtd.c' |
| 202 | cargs += '-DCONFIG_LINUX_MTD=1' |
| 203 | endif |
| 204 | if config_linux_spi |
| 205 | srcs += 'linux_spi.c' |
| 206 | cargs += '-DCONFIG_LINUX_SPI=1' |
| 207 | endif |
| 208 | if config_mstarddc_spi |
| 209 | srcs += 'mstarddc_spi.c' |
| 210 | cargs += '-DCONFIG_MSTARDDC_SPI=1' |
| 211 | endif |
| 212 | if config_nic3com |
| 213 | srcs += 'nic3com.c' |
| 214 | cargs += '-DCONFIG_NIC3COM=1' |
| 215 | endif |
| 216 | if config_nicintel |
| 217 | srcs += 'nicintel.c' |
| 218 | cargs += '-DCONFIG_NICINTEL=1' |
| 219 | endif |
| 220 | if config_nicintel_eeprom |
| 221 | srcs += 'nicintel_eeprom.c' |
| 222 | cargs += '-DCONFIG_NICINTEL_EEPROM=1' |
| 223 | endif |
| 224 | if config_nicintel_spi |
| 225 | srcs += 'nicintel_spi.c' |
| 226 | config_bitbang_spi = true |
| 227 | cargs += '-DCONFIG_NICINTEL_SPI=1' |
| 228 | endif |
| 229 | if config_nicnatsemi |
| 230 | srcs += 'nicnatsemi.c' |
| 231 | cargs += '-DCONFIG_NICNATSEMI=1' |
| 232 | endif |
| 233 | if config_nicrealtek |
| 234 | srcs += 'nicrealtek.c' |
| 235 | cargs += '-DCONFIG_NICREALTEK=1' |
| 236 | endif |
| 237 | if config_ogp_spi |
| 238 | config_bitbang_spi = true |
| 239 | srcs += 'ogp_spi.c' |
| 240 | cargs += '-DCONFIG_OGP_SPI=1' |
| 241 | endif |
| 242 | if config_pickit2_spi |
| 243 | srcs += 'pickit2_spi.c' |
| 244 | cargs += '-DCONFIG_PICKIT2_SPI=1' |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 245 | endif |
| 246 | if config_pony_spi |
| 247 | srcs += 'pony_spi.c' |
| 248 | need_serial = true |
| 249 | config_bitbang_spi = true |
| 250 | cargs += '-DCONFIG_PONY_SPI=1' |
| 251 | endif |
| 252 | if config_rayer_spi |
| 253 | srcs += 'rayer_spi.c' |
| 254 | config_bitbang_spi = true |
| 255 | need_raw_access = true |
| 256 | cargs += '-DCONFIG_RAYER_SPI=1' |
| 257 | endif |
| 258 | if config_satamv |
| 259 | srcs += 'satamv.c' |
| 260 | cargs += '-DCONFIG_SATAMV=1' |
| 261 | endif |
| 262 | if config_satasii |
| 263 | srcs += 'satasii.c' |
| 264 | cargs += '-DCONFIG_SATASII=1' |
| 265 | endif |
| 266 | if config_serprog |
| 267 | srcs += 'serprog.c' |
| 268 | cargs += '-DCONFIG_SERPROG=1' |
| 269 | need_serial = true |
| 270 | endif |
| 271 | if config_usbblaster_spi |
| 272 | srcs += 'usbblaster_spi.c' |
| 273 | cargs += '-DCONFIG_USBBLASTER_SPI=1' |
| 274 | endif |
Miklós Márton | 324929c | 2019-08-01 19:14:10 +0200 | [diff] [blame] | 275 | if config_stlinkv3_spi |
| 276 | srcs += 'stlinkv3_spi.c' |
| 277 | cargs += '-DCONFIG_STLINKV3_SPI=1' |
| 278 | endif |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 279 | |
| 280 | # bitbanging SPI infrastructure |
| 281 | if config_bitbang_spi |
| 282 | srcs += 'bitbang_spi.c' |
| 283 | cargs += '-DCONFIG_BITBANG_SPI=1' |
| 284 | endif |
| 285 | |
| 286 | # raw memory, MSR or PCI port I/O access |
| 287 | if need_raw_access |
| 288 | srcs += 'hwaccess.c' |
| 289 | srcs += 'physmap.c' |
| 290 | cargs += '-DNEED_RAW_ACCESS=1' |
| 291 | endif |
| 292 | |
| 293 | # raw serial IO |
| 294 | if need_serial |
| 295 | srcs += 'custom_baud.c' |
| 296 | srcs += 'serial.c' |
| 297 | endif |
| 298 | |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 299 | prefix = get_option('prefix') |
| 300 | sbindir = join_paths(prefix, get_option('sbindir')) |
| 301 | libdir = join_paths(prefix, get_option('libdir')) |
| 302 | |
| 303 | install_headers([ |
| 304 | 'libflashrom.h', |
| 305 | ], |
| 306 | ) |
| 307 | |
| 308 | # core modules needed by both the library and the CLI |
| 309 | srcs += '82802ab.c' |
| 310 | srcs += 'at45db.c' |
| 311 | srcs += 'edi.c' |
| 312 | srcs += 'en29lv640b.c' |
| 313 | srcs += 'flashchips.c' |
| 314 | srcs += 'flashrom.c' |
| 315 | srcs += 'fmap.c' |
| 316 | srcs += 'helpers.c' |
| 317 | srcs += 'ich_descriptors.c' |
| 318 | srcs += 'jedec.c' |
| 319 | srcs += 'layout.c' |
| 320 | srcs += 'libflashrom.c' |
| 321 | srcs += 'opaque.c' |
| 322 | srcs += 'print.c' |
| 323 | srcs += 'programmer.c' |
| 324 | srcs += 'sfdp.c' |
| 325 | srcs += 'spi25.c' |
| 326 | srcs += 'spi25_statusreg.c' |
David Hendricks | 349b5d2 | 2019-10-05 12:44:27 -0700 | [diff] [blame] | 327 | srcs += 'spi95.c' |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 328 | srcs += 'spi.c' |
| 329 | srcs += 'sst28sf040.c' |
| 330 | srcs += 'sst49lfxxxc.c' |
| 331 | srcs += 'sst_fwhub.c' |
| 332 | srcs += 'stm50.c' |
| 333 | srcs += 'udelay.c' |
| 334 | srcs += 'w29ee011.c' |
| 335 | srcs += 'w39.c' |
Nikolai Artemiev | da1c834 | 2021-10-21 00:58:12 +1100 | [diff] [blame] | 336 | srcs += 'writeprotect.c' |
Nikolai Artemiev | c9feb1b | 2021-10-21 01:35:13 +1100 | [diff] [blame] | 337 | srcs += 'writeprotect_ranges.c' |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 338 | |
| 339 | mapfile = 'libflashrom.map' |
| 340 | vflag = '-Wl,--version-script,@0@/@1@'.format(meson.current_source_dir(), mapfile) |
| 341 | flashrom = shared_library( |
| 342 | 'flashrom', |
| 343 | sources : [ |
| 344 | srcs, |
| 345 | ], |
| 346 | soversion : lt_current, |
| 347 | version : lt_version, |
| 348 | dependencies : [ |
| 349 | deps, |
| 350 | ], |
| 351 | c_args : [ |
| 352 | cargs, |
| 353 | ], |
| 354 | install : true, |
| 355 | link_args : vflag, |
| 356 | link_depends : mapfile, |
| 357 | ) |
| 358 | |
Mario Limonciello | d954d5d | 2019-09-24 16:06:57 -0500 | [diff] [blame] | 359 | version = meson.project_version() |
| 360 | #strip leading characters |
| 361 | if version.startswith('v') |
| 362 | version = version.split('v')[1] |
| 363 | endif |
| 364 | if version.startswith('p') |
| 365 | version = version.split('p')[1] |
| 366 | endif |
| 367 | |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 368 | pkgg = import('pkgconfig') |
| 369 | pkgg.generate( |
| 370 | libraries : flashrom, |
Mario Limonciello | d954d5d | 2019-09-24 16:06:57 -0500 | [diff] [blame] | 371 | version : version, |
Mario Limonciello | 2a8d439 | 2019-10-15 13:32:19 -0500 | [diff] [blame] | 372 | name : 'flashrom', |
| 373 | filebase : 'flashrom', |
| 374 | description : 'library to interact with flashrom', |
Richard Hughes | cb97368 | 2018-12-19 11:44:22 +0000 | [diff] [blame] | 375 | ) |
| 376 | |
| 377 | flashrom_dep = declare_dependency( |
| 378 | link_with : flashrom, |
| 379 | include_directories : include_directories('.'), |
| 380 | dependencies : deps |
| 381 | ) |
| 382 | |
| 383 | # we can't just link_with libflashrom as we require all the internal symbols... |
| 384 | executable( |
| 385 | 'flashrom', |
| 386 | sources : [ |
| 387 | srcs, |
| 388 | 'cli_classic.c', |
| 389 | 'cli_common.c', |
| 390 | 'cli_output.c', |
| 391 | 'flashrom.c', |
| 392 | ], |
| 393 | dependencies : [ |
| 394 | deps, |
| 395 | ], |
| 396 | c_args : [ |
| 397 | cargs, |
| 398 | '-DSTANDALONE', |
| 399 | '-DCONFIG_DEFAULT_PROGRAMMER=PROGRAMMER_INVALID', |
| 400 | '-DCONFIG_DEFAULT_PROGRAMMER_ARGS=""', |
| 401 | ], |
| 402 | install : true, |
| 403 | install_dir : sbindir, |
| 404 | ) |
| 405 | |
| 406 | subdir('util') |