blob: b5f6f316f329229836ee874a3962410130ba72ea [file] [log] [blame]
Ollie Lho184a4042005-11-26 21:55:36 +00001#
Uwe Hermannf78cff12009-06-12 14:05:25 +00002# This file is part of the flashrom project.
3#
4# Copyright (C) 2005 coresystems GmbH <stepan@coresystems.de>
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +00005# Copyright (C) 2009,2010,2012 Carl-Daniel Hailfinger
Uwe Hermannf78cff12009-06-12 14:05:25 +00006#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; version 2 of the License.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000016
Ollie Lho184a4042005-11-26 21:55:36 +000017PROGRAM = flashrom
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000018
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000019###############################################################################
20# Defaults for the toolchain.
21
22# If you want to cross-compile, just run e.g.
23# make CC=i586-pc-msdosdjgpp-gcc
24# You may have to specify STRIP/AR/RANLIB as well.
Carl-Daniel Hailfingerb7bce8a2012-08-14 21:36:11 +000025#
26# Note for anyone editing this Makefile: gnumake will happily ignore any
27# changes in this Makefile to variables set on the command line.
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +000028STRIP ?= strip
Thomas Heijligenf579bba2021-10-12 12:48:01 +020029STRIP_ARGS = -s
Christian Ruppertdb9d9f42009-05-14 14:17:07 +000030INSTALL = install
Paul Fox05dfbe62009-06-16 21:08:06 +000031DIFF = diff
Christian Ruppertdb9d9f42009-05-14 14:17:07 +000032PREFIX ?= /usr/local
Uwe Hermann56b2cb02009-05-21 15:59:58 +000033MANDIR ?= $(PREFIX)/share/man
Nico Huber9e2dc2f2018-12-23 22:00:47 +010034CFLAGS ?= -Os -Wall -Wextra -Wno-unused-parameter -Wshadow -Wmissing-prototypes -Wwrite-strings
Carl-Daniel Hailfingera23041c2009-06-12 14:49:10 +000035EXPORTDIR ?= .
Patrick Georgi97bc95c2011-03-08 07:17:44 +000036RANLIB ?= ranlib
Stefan Tauner3f73ffe2016-01-07 17:45:59 +000037PKG_CONFIG ?= pkg-config
38BUILD_DETAILS_FILE ?= build_details.txt
Stefan Taunerbe62d3f2015-01-10 09:32:44 +000039
Stefan Taunerfd0d4132012-09-25 21:24:55 +000040# The following parameter changes the default programmer that will be used if there is no -p/--programmer
41# argument given when running flashrom. The predefined setting does not enable any default so that every
42# user has to declare the programmer he wants to use on every run. The rationale for this to be not set
43# (to e.g. the internal programmer) is that forgetting to specify this when working with another programmer
44# easily puts the system attached to the default programmer at risk (e.g. you want to flash coreboot to another
45# system attached to an external programmer while the default programmer is set to the internal programmer, and
46# you forget to use the -p parameter. This would (try to) overwrite the existing firmware of the computer
47# running flashrom). Please do not enable this without thinking about the possible consequences. Possible
Thomas Heijligen84e9c912021-06-01 16:22:14 +020048# values can be found when running 'flashrom --list-supported' under the 'Supported programmers' section.
49CONFIG_DEFAULT_PROGRAMMER_NAME ?=
Stefan Tauner265fcac2014-06-02 00:12:23 +000050# The following adds a default parameter for the default programmer set above (only).
Thomas Heijligen84e9c912021-06-01 16:22:14 +020051CONFIG_DEFAULT_PROGRAMMER_ARGS ?=
Stefan Tauner265fcac2014-06-02 00:12:23 +000052# Example: compiling with
Thomas Heijligen84e9c912021-06-01 16:22:14 +020053# make CONFIG_DEFAULT_PROGRAMMER_NAME=serprog CONFIG_DEFAULT_PROGRAMMER_ARGS="dev=/dev/ttyUSB0:1500000"
Stefan Tauner265fcac2014-06-02 00:12:23 +000054# would make executing './flashrom' (almost) equivialent to './flashrom -p serprog:dev=/dev/ttyUSB0:1500000'.
Christian Ruppertdb9d9f42009-05-14 14:17:07 +000055
Thomas Heijligen121a5b82021-10-21 12:58:07 +020056# The user can provide CPP, C and LDFLAGS and the Makefile will extend these
57override CPPFLAGS := $(CPPFLAGS)
58override CFLAGS := $(CFLAGS)
59override LDFLAGS := $(LDFLAGS)
60
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000061# If your compiler spits out excessive warnings, run make WARNERROR=no
62# You shouldn't have to change this flag.
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +000063WARNERROR ?= yes
64
65ifeq ($(WARNERROR), yes)
Thomas Heijligen121a5b82021-10-21 12:58:07 +020066override CFLAGS += -Werror
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +000067endif
68
Stefan Taunere37735a2015-01-26 22:03:35 +000069ifdef LIBS_BASE
Stefan Taunere37735a2015-01-26 22:03:35 +000070PKG_CONFIG_LIBDIR ?= $(LIBS_BASE)/lib/pkgconfig
Stefan Tauner45207062016-02-19 08:17:24 +000071override CPPFLAGS += -I$(LIBS_BASE)/include
72override LDFLAGS += -L$(LIBS_BASE)/lib -Wl,-rpath -Wl,$(LIBS_BASE)/lib
Stefan Taunere37735a2015-01-26 22:03:35 +000073endif
Stefan Taunerbe62d3f2015-01-10 09:32:44 +000074
Stefan Taunerbfb067b2016-01-07 18:13:07 +000075ifeq ($(CONFIG_STATIC),yes)
Stefan Tauner45207062016-02-19 08:17:24 +000076override PKG_CONFIG += --static
77override LDFLAGS += -static
Stefan Taunerbfb067b2016-01-07 18:13:07 +000078endif
79
Stefan Tauner1ca7c7f2016-01-14 23:05:55 +000080# Set LC_ALL=C to minimize influences of the locale.
81# However, this won't work for the majority of relevant commands because they use the $(shell) function and
Martin Rothf6c1cb12022-03-15 10:55:25 -060082# GNU make does not relay variables exported within the makefile to their environment.
Stefan Tauner1ca7c7f2016-01-14 23:05:55 +000083LC_ALL=C
84export LC_ALL
85
Stefan Tauner3f73ffe2016-01-07 17:45:59 +000086dummy_for_make_3_80:=$(shell printf "Build started on %s\n\n" "$$(date)" >$(BUILD_DETAILS_FILE))
Stefan Tauner1ca7c7f2016-01-14 23:05:55 +000087
88# Provide an easy way to execute a command, print its output to stdout and capture any error message on stderr
89# in the build details file together with the original stdout output.
Pyry Kontio89cc73b2020-07-06 12:57:35 +090090debug_shell = $(shell export LC_ALL=C ; { echo 'exec: export LC_ALL=C ; { $(subst ','\'',$(1)) ; }' >&2; \
91 { $(1) ; } | tee -a $(BUILD_DETAILS_FILE) ; echo >&2 ; } 2>>$(BUILD_DETAILS_FILE))
Stefan Tauner1ca7c7f2016-01-14 23:05:55 +000092
Thomas Heijligen121a5b82021-10-21 12:58:07 +020093include Makefile.include
94
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +000095###############################################################################
Nico Huber7f898972021-06-27 13:30:50 +020096# Dependency handling.
97
98DEPENDS_ON_SERIAL := \
99 CONFIG_BUSPIRATE_SPI \
100 CONFIG_PONY_SPI \
101 CONFIG_SERPROG \
102
103DEPENDS_ON_BITBANG_SPI := \
Nico Huber29c68342021-06-27 14:34:16 +0200104 CONFIG_DEVELOPERBOX_SPI \
Nico Huber7f898972021-06-27 13:30:50 +0200105 CONFIG_INTERNAL \
106 CONFIG_NICINTEL_SPI \
107 CONFIG_OGP_SPI \
108 CONFIG_PONY_SPI \
109 CONFIG_RAYER_SPI \
110
Thomas Heijligen96f68f72021-12-14 18:25:47 +0100111DEPENDS_ON_RAW_MEM_ACCESS := \
112 CONFIG_ATAPROMISE \
113 CONFIG_DRKAISER \
114 CONFIG_GFXNVIDIA \
115 CONFIG_INTERNAL \
116 CONFIG_IT8212 \
117 CONFIG_NICINTEL \
118 CONFIG_NICINTEL_EEPROM \
119 CONFIG_NICINTEL_SPI \
120 CONFIG_OGP_SPI \
121 CONFIG_SATAMV \
122 CONFIG_SATASII \
123
124DEPENDS_ON_X86_MSR := \
125 CONFIG_INTERNAL \
126
127DEPENDS_ON_X86_PORT_IO := \
128 CONFIG_ATAHPT \
129 CONFIG_ATAPROMISE \
130 CONFIG_ATAVIA \
131 CONFIG_DRKAISER \
132 CONFIG_GFXNVIDIA \
133 CONFIG_INTERNAL \
134 CONFIG_NIC3COM \
135 CONFIG_NICINTEL \
136 CONFIG_NICINTEL_EEPROM \
137 CONFIG_NICINTEL_SPI \
138 CONFIG_NICNATSEMI \
139 CONFIG_NICREALTEK \
140 CONFIG_OGP_SPI \
141 CONFIG_RAYER_SPI \
142 CONFIG_SATAMV \
143 CONFIG_SATASII \
144
Nico Huber7f898972021-06-27 13:30:50 +0200145DEPENDS_ON_LIBPCI := \
146 CONFIG_ATAHPT \
147 CONFIG_ATAPROMISE \
148 CONFIG_ATAVIA \
149 CONFIG_DRKAISER \
150 CONFIG_GFXNVIDIA \
151 CONFIG_INTERNAL \
152 CONFIG_IT8212 \
153 CONFIG_NIC3COM \
154 CONFIG_NICINTEL \
155 CONFIG_NICINTEL_EEPROM \
156 CONFIG_NICINTEL_SPI \
157 CONFIG_NICNATSEMI \
158 CONFIG_NICREALTEK \
159 CONFIG_OGP_SPI \
160 CONFIG_SATAMV \
161 CONFIG_SATASII \
162
163DEPENDS_ON_LIBUSB1 := \
164 CONFIG_CH341A_SPI \
165 CONFIG_DEDIPROG \
166 CONFIG_DEVELOPERBOX_SPI \
167 CONFIG_DIGILENT_SPI \
168 CONFIG_PICKIT2_SPI \
169 CONFIG_RAIDEN_DEBUG_SPI \
170 CONFIG_STLINKV3_SPI \
Jean THOMASe28d8e42022-10-11 17:54:30 +0200171 CONFIG_DIRTYJTAG_SPI \
Nico Huber7f898972021-06-27 13:30:50 +0200172
Thomas Heijligen121a5b82021-10-21 12:58:07 +0200173DEPENDS_ON_LIBFTDI1 := \
Nico Huber7f898972021-06-27 13:30:50 +0200174 CONFIG_FT2232_SPI \
175 CONFIG_USBBLASTER_SPI \
176
177DEPENDS_ON_LIBJAYLINK := \
178 CONFIG_JLINK_SPI \
179
Thomas Heijligenff63acd2021-11-05 10:19:42 +0100180DEPENDS_ON_LIB_NI845X := \
181 CONFIG_NI845X_SPI \
182
Nico Hubera54f5a42021-06-27 14:27:41 +0200183
184ifeq ($(CONFIG_ENABLE_LIBUSB1_PROGRAMMERS), no)
185$(call disable_all,$(DEPENDS_ON_LIBUSB1))
186endif
187
188ifeq ($(CONFIG_ENABLE_LIBPCI_PROGRAMMERS), no)
189$(call disable_all,$(DEPENDS_ON_LIBPCI))
190endif
191
Nico Huber7f898972021-06-27 13:30:50 +0200192###############################################################################
Stefan Tauner037cd842013-08-25 00:10:56 +0000193# General OS-specific settings.
194# 1. Prepare for later by gathering information about host and target OS
195# 2. Set compiler flags and parameters according to OSes
196# 3. Likewise verify user-supplied CONFIG_* variables.
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000197
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000198# HOST_OS is only used to work around local toolchain issues.
Stefan Tauner037cd842013-08-25 00:10:56 +0000199HOST_OS ?= $(shell uname)
Miklós Mártona75a2ed2018-01-30 20:25:00 +0100200ifeq ($(findstring MINGW, $(HOST_OS)), MINGW)
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000201# Explicitly set CC = gcc on MinGW, otherwise: "cc: command not found".
202CC = gcc
203endif
Miklós Mártona75a2ed2018-01-30 20:25:00 +0100204
Thomas Heijligen323ad352021-10-26 11:26:32 +0200205CC_WORKING := $(call c_compile_test, Makefile.d/cc_test.c)
206
Thomas Heijligen121a5b82021-10-21 12:58:07 +0200207# Configs for dependencies. Can be overwritten by commandline
Thomas Heijligenff63acd2021-11-05 10:19:42 +0100208CONFIG_LIBFTDI1_CFLAGS := $(call dependency_cflags, libftdi1)
209CONFIG_LIBFTDI1_LDFLAGS := $(call dependency_ldflags, libftdi1)
210
211# Hack to keep legacy auto detection of Program Files (x86), Only active if none of the CONFIG_ variables for ni845x are set.
212ifeq ($(CONFIG_NI845X_LIBRARY_PATH)$(CONFIG_LIB_NI845X_CFLAGS)$(CONFIG_LIB_NI845X_LDFLAGS),)
213PROGRAMFILES_X86 = $(shell env | sed -n "s/^PROGRAMFILES(X86)=//p")
214ifneq ($(PROGRAMFILES_X86),)
215ifneq ($(PROGRAMFILES_X86), ${PROGRAMFILES})
216NI854_X86_LIBRARY_PATH := '${PROGRAMFILES_X86}\National Instruments\NI-845x\MS Visual C'
217endif
218endif
219endif
220
221CONFIG_NI845X_LIBRARY_PATH := '${PROGRAMFILES}\National Instruments\NI-845x\MS Visual C'
222CONFIG_LIB_NI845X_CFLAGS := -I$(CONFIG_NI845X_LIBRARY_PATH) $(if NI854_X86_LIBRARY_PATH, -I${NI854_X86_LIBRARY_PATH})
223CONFIG_LIB_NI845X_LDFLAGS := -L$(CONFIG_NI845X_LIBRARY_PATH) $(if NI854_X86_LIBRARY_PATH, -L${NI854_X86_LIBRARY_PATH}) -lni845x
Thomas Heijligen121a5b82021-10-21 12:58:07 +0200224
Thomas Heijligen4dca8992021-11-05 10:34:31 +0100225CONFIG_LIBJAYLINK_CFLAGS := $(call dependency_cflags, libjaylink)
226CONFIG_LIBJAYLINK_LDFLAGS := $(call dependency_ldflags, libjaylink)
227
Thomas Heijligenb7c6a662021-11-05 10:47:40 +0100228CONFIG_LIBUSB1_CFLAGS := $(call dependency_cflags, libusb-1.0)
229CONFIG_LIBUSB1_LDFLAGS := $(call dependency_ldflags, libusb-1.0)
230
Thomas Heijligen282a9512021-10-12 13:30:06 +0200231# Determine the destination OS, architecture and endian
232# IMPORTANT: The following lines must be placed before TARGET_OS, ARCH or ENDIAN
233# is ever used (of course), but should come after any lines setting CC because
234# the lines below use CC itself.
Thomas Heijligen1e76dc82021-09-28 15:22:34 +0200235override TARGET_OS := $(call c_macro_test, Makefile.d/os_test.h)
Thomas Heijligen6efdfb32021-10-12 15:16:46 +0200236override ARCH := $(call c_macro_test, Makefile.d/arch_test.h)
Thomas Heijligen9a2787b2021-10-12 15:54:06 +0200237override ENDIAN := $(call c_macro_test, Makefile.d/endian_test.h)
Thomas Heijligen282a9512021-10-12 13:30:06 +0200238
Thomas Heijligen121a5b82021-10-21 12:58:07 +0200239
240HAS_LIBFTDI1 := $(call find_dependency, libftdi1)
Thomas Heijligenff63acd2021-11-05 10:19:42 +0100241HAS_LIB_NI845X := no
Thomas Heijligen4dca8992021-11-05 10:34:31 +0100242HAS_LIBJAYLINK := $(call find_dependency, libjaylink)
Thomas Heijligenb7c6a662021-11-05 10:47:40 +0100243HAS_LIBUSB1 := $(call find_dependency, libusb-1.0)
Thomas Heijligen121a5b82021-10-21 12:58:07 +0200244
245HAS_FT232H := $(call c_compile_test, Makefile.d/ft232h_test.c, $(CONFIG_LIBFTDI1_CFLAGS))
Thomas Heijligen457020a2021-10-26 12:44:36 +0200246HAS_UTSNAME := $(call c_compile_test, Makefile.d/utsname_test.c)
247HAS_CLOCK_GETTIME := $(call c_compile_test, Makefile.d/clock_gettime_test.c)
Thomas Heijligenca71c872021-10-20 22:08:24 +0200248HAS_LINUX_MTD := $(call c_compile_test, Makefile.d/linux_mtd_test.c)
249HAS_LINUX_SPI := $(call c_compile_test, Makefile.d/linux_spi_test.c)
250HAS_LINUX_I2C := $(call c_compile_test, Makefile.d/linux_i2c_test.c)
Thomas Heijligen457020a2021-10-26 12:44:36 +0200251
Thomas Heijligen0bec7b22021-10-12 13:18:15 +0200252ifeq ($(TARGET_OS), $(filter $(TARGET_OS), FreeBSD OpenBSD DragonFlyBSD))
253override CPPFLAGS += -I/usr/local/include
254override LDFLAGS += -L/usr/local/lib
255endif
256
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000257ifeq ($(TARGET_OS), Darwin)
Stefan Tauner45207062016-02-19 08:17:24 +0000258override CPPFLAGS += -I/opt/local/include -I/usr/local/include
259override LDFLAGS += -L/opt/local/lib -L/usr/local/lib
Stefan Reinauerf79edb92009-01-26 01:23:31 +0000260endif
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000261
Stefan Taunerc65b8552013-09-12 15:48:39 +0000262ifeq ($(TARGET_OS), NetBSD)
Nico Huberc0e1c4b2022-12-13 21:55:22 +0000263# Needs special `pciutils/pci.h` for older NetBSD packages
264PCIUTILS_PCI_H := $(shell [ -f /usr/pkg/include/pciutils/pci.h ] && echo -DPCIUTILS_PCI_H)
265override CPPFLAGS += -I/usr/pkg/include $(PCIUTILS_PCI_H)
Stefan Tauner45207062016-02-19 08:17:24 +0000266override LDFLAGS += -L/usr/pkg/lib
Stefan Taunerc65b8552013-09-12 15:48:39 +0000267endif
268
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000269ifeq ($(TARGET_OS), DOS)
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +0000270EXEC_SUFFIX := .exe
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000271# DJGPP has odd uint*_t definitions which cause lots of format string warnings.
Stefan Tauner45207062016-02-19 08:17:24 +0000272override CFLAGS += -Wno-format
Stefan Tauner449abe22013-09-11 23:34:57 +0000273LIBS += -lgetopt
Nico Huberba681962021-06-27 13:39:23 +0200274# Missing serial support.
275$(call mark_unsupported,$(DEPENDS_ON_SERIAL))
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +0000276endif
Ollie Lho184a4042005-11-26 21:55:36 +0000277
Thomas Heijligen847d94b2021-10-12 17:38:01 +0200278ifeq ($(TARGET_OS), $(filter $(TARGET_OS), MinGW Cygwin))
Thomas Heijligen96f68f72021-12-14 18:25:47 +0100279$(call mark_unsupported,$(DEPENDS_ON_RAW_MEM_ACCESS))
280$(call mark_unsupported,$(DEPENDS_ON_X86_PORT_IO))
281$(call mark_unsupported,$(DEPENDS_ON_X86_MSR))
Thomas Heijligen847d94b2021-10-12 17:38:01 +0200282FEATURE_CFLAGS += -D'IS_WINDOWS=1'
283else
284FEATURE_CFLAGS += -D'IS_WINDOWS=0'
285endif
286
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000287# FIXME: Should we check for Cygwin/MSVC as well?
288ifeq ($(TARGET_OS), MinGW)
289EXEC_SUFFIX := .exe
Uwe Hermannd5e85d62011-07-03 19:44:12 +0000290# MinGW doesn't have the ffs() function, but we can use gcc's __builtin_ffs().
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +0000291FLASHROM_CFLAGS += -Dffs=__builtin_ffs
Carl-Daniel Hailfinger11990da2013-07-13 23:21:05 +0000292# Some functions provided by Microsoft do not work as described in C99 specifications. This macro fixes that
Stefan Tauner23e10b82016-01-23 16:16:49 +0000293# for MinGW. See http://sourceforge.net/p/mingw-w64/wiki2/printf%20and%20scanf%20family/ */
Carl-Daniel Hailfinger11990da2013-07-13 23:21:05 +0000294FLASHROM_CFLAGS += -D__USE_MINGW_ANSI_STDIO=1
Miklós Márton2d20d6d2018-01-30 20:20:15 +0100295
Uwe Hermannd5e85d62011-07-03 19:44:12 +0000296# For now we disable all PCI-based programmers on Windows/MinGW (no libpci).
Nico Huberca621782021-06-27 13:53:49 +0200297$(call mark_unsupported,$(DEPENDS_ON_LIBPCI))
Thomas Heijligen96f68f72021-12-14 18:25:47 +0100298
299else # No MinGW
300
301# NI USB-845x only supported on Windows at the moment
302$(call mark_unsupported,CONFIG_NI845X_SPI)
303
Miklós Márton2d20d6d2018-01-30 20:20:15 +0100304endif
305
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000306ifeq ($(TARGET_OS), libpayload)
Stefan Tauner8e19b042013-08-28 09:55:04 +0000307ifeq ($(MAKECMDGOALS),)
308.DEFAULT_GOAL := libflashrom.a
309$(info Setting default goal to libflashrom.a)
310endif
Carl-Daniel Hailfingera8da2242012-08-15 23:06:32 +0000311FLASHROM_CFLAGS += -DSTANDALONE
Nico Huber71331032021-06-27 14:00:39 +0200312$(call mark_unsupported,CONFIG_DUMMY)
Stefan Taunere0168262016-02-21 11:18:24 +0000313# libpayload does not provide the romsize field in struct pci_dev that the atapromise code requires.
Nico Huber71331032021-06-27 14:00:39 +0200314$(call mark_unsupported,CONFIG_ATAPROMISE)
Carl-Daniel Hailfinger11990da2013-07-13 23:21:05 +0000315# Bus Pirate, Serprog and PonyProg are not supported with libpayload (missing serial support).
Thomas Heijligen96f68f72021-12-14 18:25:47 +0100316$(call mark_unsupported,$(DEPENDS_ON_SERIAL))
317# Dediprog, Developerbox, USB-Blaster, PICkit2, CH341A and FT2232 are not supported with libpayload (missing libusb support).
318$(call mark_unsupported,$(DEPENDS_ON_LIBUSB1) $(DEPENDS_ON_LIBFTDI) $(DEPENDS_ON_LIBJAYLINK))
Patrick Georgi97bc95c2011-03-08 07:17:44 +0000319endif
320
Thomas Heijligenca71c872021-10-20 22:08:24 +0200321ifeq ($(HAS_LINUX_MTD), no)
322$(call mark_unsupported,CONFIG_LINUX_MTD)
323endif
324
325ifeq ($(HAS_LINUX_SPI), no)
326$(call mark_unsupported,CONFIG_LINUX_SPI)
327endif
328
329ifeq ($(HAS_LINUX_I2C), no)
Nico Huberdc8e54a2021-06-27 14:17:34 +0200330$(call mark_unsupported,CONFIG_MSTARDDC_SPI)
Carl-Daniel Hailfinger601f4cd2016-02-28 22:04:51 +0000331endif
Carl-Daniel Hailfinger8541d232012-02-16 21:00:27 +0000332
Carl-Daniel Hailfinger16c0aec2016-02-20 21:43:56 +0000333ifeq ($(TARGET_OS), Android)
Nico Huberdc8e54a2021-06-27 14:17:34 +0200334# Android on x86 (currently) does not provide raw PCI port I/O operations.
Thomas Heijligen96f68f72021-12-14 18:25:47 +0100335$(call mark_unsupported,$(DEPENDS_ON_X86_PORT_IO))
Carl-Daniel Hailfinger16c0aec2016-02-20 21:43:56 +0000336endif
337
Nico Huberc8801732017-12-01 18:19:43 +0000338# Disable the internal programmer on unsupported architectures (everything but x86 and mipsel)
Thomas Heijligen485d2cd2021-10-19 16:14:55 +0200339ifneq ($(ARCH)-little, $(filter $(ARCH), x86 mips)-$(ENDIAN))
Nico Huber8945b812021-06-27 14:24:53 +0200340$(call mark_unsupported,CONFIG_INTERNAL)
Nico Huberc8801732017-12-01 18:19:43 +0000341endif
342
Thomas Heijligen121a5b82021-10-21 12:58:07 +0200343ifeq ($(HAS_LIBFTDI1), no)
344$(call mark_unsupported,$(DEPENDS_ON_LIBFTDI1))
345endif
346
Thomas Heijligenff63acd2021-11-05 10:19:42 +0100347ifeq ($(HAS_LIB_NI845X), no)
348$(call mark_unsupported,$(DEPENDS_ON_LIB_NI845X))
349endif
350
Thomas Heijligen4dca8992021-11-05 10:34:31 +0100351ifeq ($(HAS_LIBJAYLINK), no)
352$(call mark_unsupported,$(DEPENDS_ON_LIBJAYLINK))
353endif
354
Thomas Heijligenb7c6a662021-11-05 10:47:40 +0100355ifeq ($(HAS_LIBUSB1), no)
356$(call mark_unsupported,$(DEPENDS_ON_LIBUSB1))
357endif
358
Thomas Heijligend6d96c12021-10-12 16:47:43 +0200359ifeq ($(ENDIAN), little)
360FEATURE_CFLAGS += -D'__FLASHROM_LITTLE_ENDIAN__=1'
361endif
362ifeq ($(ENDIAN), big)
363FEATURE_CFLAGS += -D'__FLASHROM_BIG_ENDIAN__=1'
364endif
365
Stefan Taunerfb2d77c2015-02-10 08:03:10 +0000366# PCI port I/O support is unimplemented on PPC/MIPS/SPARC and unavailable on ARM.
David Hendricksb286da72012-02-13 00:35:35 +0000367# Right now this means the drivers below only work on x86.
368ifneq ($(ARCH), x86)
Thomas Heijligen96f68f72021-12-14 18:25:47 +0100369$(call mark_unsupported,$(DEPENDS_ON_X86_MSR))
370$(call mark_unsupported,$(DEPENDS_ON_X86_PORT_IO))
Uwe Hermann21b10c62011-07-29 12:13:01 +0000371endif
372
Nico Huber8945b812021-06-27 14:24:53 +0200373# Additionally disable all drivers needing raw access (memory, PCI, port I/O)
374# on architectures with unknown raw access properties.
Carl-Daniel Hailfinger8d0d53f2016-02-25 20:10:26 +0000375# Right now those architectures are alpha hppa m68k sh s390
Thomas Heijligen485d2cd2021-10-19 16:14:55 +0200376ifneq ($(ARCH), $(filter $(ARCH), x86 mips ppc arm sparc arc))
Thomas Heijligen96f68f72021-12-14 18:25:47 +0100377$(call mark_unsupported,$(DEPENDS_ON_RAW_MEM_ACCESS))
Carl-Daniel Hailfinger8d0d53f2016-02-25 20:10:26 +0000378endif
379
Thomas Heijligen433dc1c2021-10-12 17:58:35 +0200380ifeq ($(TARGET_OS), $(filter $(TARGET_OS), Linux Darwin NetBSD OpenBSD))
381FEATURE_CFLAGS += -D'USE_IOPL=1'
382else
383FEATURE_CFLAGS += -D'USE_IOPL=0'
384endif
385
386ifeq ($(TARGET_OS), $(filter $(TARGET_OS), FreeBSD FreeBSD-glibc DragonFlyBSD))
387FEATURE_CFLAGS += -D'USE_DEV_IO=1'
388else
389FEATURE_CFLAGS += -D'USE_DEV_IO=0'
390endif
391
392ifeq ($(TARGET_OS), $(filter $(TARGET_OS), Hurd))
393FEATURE_CFLAGS += -D'USE_IOPERM=1'
394else
395FEATURE_CFLAGS += -D'USE_IOPERM=0'
396endif
397
398
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000399###############################################################################
400# Flash chip drivers and bus support infrastructure.
401
Stefan Tauner4404f732013-09-12 08:28:56 +0000402CHIP_OBJS = jedec.o stm50.o w39.o w29ee011.o \
Carl-Daniel Hailfingera8cf3622014-08-08 08:33:01 +0000403 sst28sf040.o 82802ab.o \
Paul Kocialkowski80ae14e2018-01-15 01:07:46 +0300404 sst49lfxxxc.o sst_fwhub.o edi.o flashchips.o spi.o spi25.o spi25_statusreg.o \
Nikolai Artemievc9feb1b2021-10-21 01:35:13 +1100405 spi95.o opaque.o sfdp.o en29lv640b.o at45db.o \
406 writeprotect.o writeprotect_ranges.o
Sean Nelson5d134642009-12-24 16:54:21 +0000407
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000408###############################################################################
409# Library code.
Sean Nelson5d134642009-12-24 16:54:21 +0000410
Thomas Heijligenbbfacff2021-03-31 20:40:01 +0200411LIB_OBJS = libflashrom.o layout.o flashrom.o udelay.o programmer.o programmer_table.o helpers.o ich_descriptors.o fmap.o
Sean Nelson5d134642009-12-24 16:54:21 +0000412
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000413###############################################################################
414# Frontend related stuff.
Ollie Lho184a4042005-11-26 21:55:36 +0000415
Stefan Tauner9b32de92014-08-08 23:52:33 +0000416CLI_OBJS = cli_classic.o cli_output.o cli_common.o print.o
Ollie Lho184a4042005-11-26 21:55:36 +0000417
Stefan Taunerfa25bc32017-10-04 03:47:26 +0200418# versioninfo.inc stores metadata required to build a packaged flashrom. It is generated by the export rule and
419# imported below. If versioninfo.inc is not found and the variables are not defined by the user, the info will
420# be obtained using util/getrevision.sh, which is the common case during development.
421-include versioninfo.inc
Stefan Tauner5bf6b852017-10-04 03:46:51 +0200422VERSION ?= $(shell ./util/getrevision.sh --revision)
Stefan Tauner96209122017-10-01 16:41:35 +0200423MAN_DATE ?= $(shell ./util/getrevision.sh --date $(PROGRAM).8.tmpl 2>/dev/null)
Carl-Daniel Hailfingera23041c2009-06-12 14:49:10 +0000424
Stefan Tauner76347082016-11-27 17:45:49 +0100425SCMDEF := -D'FLASHROM_VERSION="$(VERSION)"'
Bernhard Walle201bde32008-01-21 15:24:22 +0000426
Stefan Tauner76347082016-11-27 17:45:49 +0100427# Inform user of the version string
Nico Huber26c2c4d2023-01-10 17:45:38 +0100428ifeq ($(filter branch tag,$(MAKECMDGOALS)), )
Stefan Tauner76347082016-11-27 17:45:49 +0100429$(info Replacing all version templates with $(VERSION).)
Nico Huber26c2c4d2023-01-10 17:45:38 +0100430endif
Stefan Taunerd5ff8452015-01-10 09:32:07 +0000431
Stefan Tauner037cd842013-08-25 00:10:56 +0000432###############################################################################
433# Default settings of CONFIG_* variables.
434
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000435# Always enable internal/onboard support for now.
436CONFIG_INTERNAL ?= yes
437
Stefan Tauner52b6e9d2013-04-01 00:46:05 +0000438# Always enable serprog for now.
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000439CONFIG_SERPROG ?= yes
440
Carl-Daniel Hailfingere7fdd6e2010-07-21 10:26:01 +0000441# RayeR SPIPGM hardware support
442CONFIG_RAYER_SPI ?= yes
443
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000444# PonyProg2000 SPI hardware support
445CONFIG_PONY_SPI ?= yes
446
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000447# Always enable 3Com NICs for now.
448CONFIG_NIC3COM ?= yes
449
Carl-Daniel Hailfingerbf3af292010-07-29 14:41:46 +0000450# Enable NVIDIA graphics cards. Note: write and erase do not work properly.
451CONFIG_GFXNVIDIA ?= yes
Uwe Hermann2bc98f62009-09-30 18:29:55 +0000452
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000453# Always enable SiI SATA controllers for now.
454CONFIG_SATASII ?= yes
455
Uwe Hermannddd5c9e2010-02-21 21:17:00 +0000456# Highpoint (HPT) ATA/RAID controller support.
457# IMPORTANT: This code is not yet working!
458CONFIG_ATAHPT ?= no
459
Jonathan Kollasch7f0f3fa2014-06-01 10:26:23 +0000460# VIA VT6421A LPC memory support
461CONFIG_ATAVIA ?= yes
462
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +0000463# Promise ATA controller support.
464CONFIG_ATAPROMISE ?= no
465
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000466# Always enable FT2232 SPI dongles for now.
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000467CONFIG_FT2232_SPI ?= yes
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000468
James Lairdc60de0e2013-03-27 13:00:23 +0000469# Always enable Altera USB-Blaster dongles for now.
470CONFIG_USBBLASTER_SPI ?= yes
471
Alexandre Boeglin80e64712014-12-20 20:25:19 +0000472# MSTAR DDC support needs more tests/reviews/cleanups.
473CONFIG_MSTARDDC_SPI ?= no
474
Justin Chevrier66e554b2015-02-08 21:58:10 +0000475# Always enable PICkit2 SPI dongles for now.
476CONFIG_PICKIT2_SPI ?= yes
477
Miklós Márton324929c2019-08-01 19:14:10 +0200478# Always enable STLink V3
479CONFIG_STLINKV3_SPI ?= yes
480
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000481# Always enable dummy tracing for now.
482CONFIG_DUMMY ?= yes
483
484# Always enable Dr. Kaiser for now.
485CONFIG_DRKAISER ?= yes
Carl-Daniel Hailfinger6be74112009-08-12 16:17:41 +0000486
Joerg Fischer5665ef32010-05-21 21:54:07 +0000487# Always enable Realtek NICs for now.
488CONFIG_NICREALTEK ?= yes
489
Andrew Morganc29c2e72010-06-07 22:37:54 +0000490# Disable National Semiconductor NICs until support is complete and tested.
491CONFIG_NICNATSEMI ?= no
492
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000493# Always enable Intel NICs for now.
494CONFIG_NICINTEL ?= yes
495
Idwer Vollering004f4b72010-09-03 18:21:21 +0000496# Always enable SPI on Intel NICs for now.
497CONFIG_NICINTEL_SPI ?= yes
498
Ricardo Ribalda Delgado2a41f0a2014-07-28 20:35:21 +0000499# Always enable EEPROM on Intel NICs for now.
500CONFIG_NICINTEL_EEPROM ?= yes
501
Mark Marshall90021f22010-12-03 14:48:11 +0000502# Always enable SPI on OGP cards for now.
503CONFIG_OGP_SPI ?= yes
504
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000505# Always enable Bus Pirate SPI for now.
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000506CONFIG_BUSPIRATE_SPI ?= yes
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000507
Simon Glassae616512016-01-23 23:27:58 +0000508# Always enable Dediprog SF100 for now.
509CONFIG_DEDIPROG ?= yes
Carl-Daniel Hailfingerd38fac82010-01-19 11:15:48 +0000510
Daniel Thompson45e91a22018-06-04 13:46:29 +0100511# Always enable Developerbox emergency recovery for now.
512CONFIG_DEVELOPERBOX_SPI ?= yes
513
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000514# Always enable Marvell SATA controllers for now.
515CONFIG_SATAMV ?= yes
516
David Hendricksf9a30552015-05-23 20:30:30 -0700517# Enable Linux spidev and MTD interfaces by default. We disable them on non-Linux targets.
518CONFIG_LINUX_MTD ?= yes
Carl-Daniel Hailfinger8541d232012-02-16 21:00:27 +0000519CONFIG_LINUX_SPI ?= yes
520
Kyösti Mälkki72d42f82014-06-01 23:48:31 +0000521# Always enable ITE IT8212F PATA controllers for now.
522CONFIG_IT8212 ?= yes
523
Urja Rannikko0870b022016-01-31 22:10:29 +0000524# Winchiphead CH341A
525CONFIG_CH341A_SPI ?= yes
526
Lubomir Rintelb2154e82018-01-14 17:35:33 +0100527# Digilent Development board JTAG
528CONFIG_DIGILENT_SPI ?= yes
529
Jean THOMASe28d8e42022-10-11 17:54:30 +0200530# DirtyJTAG
531CONFIG_DIRTYJTAG_SPI ?= yes
532
Marc Schink3578ec62016-03-17 16:23:03 +0100533# Disable J-Link for now.
534CONFIG_JLINK_SPI ?= no
535
Nico Huber83d52072021-06-27 00:07:13 +0200536# National Instruments USB-845x is Windows only and needs a proprietary library.
537CONFIG_NI845X_SPI ?= no
538
Carl-Daniel Hailfinger6161ff12009-11-16 21:22:24 +0000539# Disable wiki printing by default. It is only useful if you have wiki access.
Uwe Hermann2db77a02010-06-04 17:07:39 +0000540CONFIG_PRINT_WIKI ?= no
Carl-Daniel Hailfinger9c8476b2009-09-16 12:19:03 +0000541
Stefan Taunerf3503372016-02-26 23:51:21 +0000542# Disable all features if CONFIG_NOTHING=yes is given unless CONFIG_EVERYTHING was also set
543ifeq ($(CONFIG_NOTHING), yes)
544 ifeq ($(CONFIG_EVERYTHING), yes)
545 $(error Setting CONFIG_NOTHING=yes and CONFIG_EVERYTHING=yes does not make sense)
546 endif
547 $(foreach var, $(filter CONFIG_%, $(.VARIABLES)),\
548 $(if $(filter yes, $($(var))),\
549 $(eval $(var)=no)))
550endif
551
Patrick Georgiced7ab62015-01-19 19:52:34 +0000552# Enable all features if CONFIG_EVERYTHING=yes is given
553ifeq ($(CONFIG_EVERYTHING), yes)
554$(foreach var, $(filter CONFIG_%, $(.VARIABLES)),\
555 $(if $(filter no, $($(var))),\
556 $(eval $(var)=yes)))
557endif
558
Carl-Daniel Hailfinger9e3a6c42010-10-08 12:40:09 +0000559# Bitbanging SPI infrastructure, default off unless needed.
Nico Huber29c68342021-06-27 14:34:16 +0200560
561ifneq ($(call filter_deps,$(DEPENDS_ON_BITBANG_SPI)), )
Felix Singer4cbc1cb2022-07-22 23:23:28 +0200562override CONFIG_BITBANG_SPI = yes
563else
Carl-Daniel Hailfinger9e3a6c42010-10-08 12:40:09 +0000564CONFIG_BITBANG_SPI ?= no
565endif
Carl-Daniel Hailfinger9e3a6c42010-10-08 12:40:09 +0000566
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000567###############################################################################
Sean Nelson4c6d3a42013-09-11 23:35:03 +0000568# Handle CONFIG_* variables that depend on others set (and verified) above.
569
570# The external DMI decoder (dmidecode) does not work in libpayload. Bail out if the internal one got disabled.
571ifeq ($(TARGET_OS), libpayload)
572ifeq ($(CONFIG_INTERNAL), yes)
573ifeq ($(CONFIG_INTERNAL_DMI), no)
574UNSUPPORTED_FEATURES += CONFIG_INTERNAL_DMI=no
575else
576override CONFIG_INTERNAL_DMI = yes
577endif
578endif
579endif
580
581# Use internal DMI/SMBIOS decoder by default instead of relying on dmidecode.
582CONFIG_INTERNAL_DMI ?= yes
583
584###############################################################################
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000585# Programmer drivers and programmer support infrastructure.
Stefan Tauner037cd842013-08-25 00:10:56 +0000586# Depending on the CONFIG_* variables set and verified above we set compiler flags and parameters below.
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000587
Thomas Heijligen84e9c912021-06-01 16:22:14 +0200588ifdef CONFIG_DEFAULT_PROGRAMMER_NAME
589FEATURE_CFLAGS += -D'CONFIG_DEFAULT_PROGRAMMER_NAME=&programmer_$(CONFIG_DEFAULT_PROGRAMMER_NAME)'
590else
591FEATURE_CFLAGS += -D'CONFIG_DEFAULT_PROGRAMMER_NAME=NULL'
592endif
593
Stefan Tauner265fcac2014-06-02 00:12:23 +0000594FEATURE_CFLAGS += -D'CONFIG_DEFAULT_PROGRAMMER_ARGS="$(CONFIG_DEFAULT_PROGRAMMER_ARGS)"'
Stefan Taunerfd0d4132012-09-25 21:24:55 +0000595
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000596ifeq ($(CONFIG_INTERNAL), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000597FEATURE_CFLAGS += -D'CONFIG_INTERNAL=1'
Sean Nelson4c6d3a42013-09-11 23:35:03 +0000598PROGRAMMER_OBJS += processor_enable.o chipset_enable.o board_enable.o cbtable.o internal.o
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000599ifeq ($(ARCH), x86)
Edward O'Callaghan2ab6bba2022-06-24 16:48:09 +1000600PROGRAMMER_OBJS += it87spi.o sb600spi.o amd_imc.o wbsio_spi.o mcp6x_spi.o
Nico Huber305f4172013-06-14 11:55:26 +0200601PROGRAMMER_OBJS += ichspi.o dmi.o
Sean Nelson4c6d3a42013-09-11 23:35:03 +0000602ifeq ($(CONFIG_INTERNAL_DMI), yes)
603FEATURE_CFLAGS += -D'CONFIG_INTERNAL_DMI=1'
604endif
Carl-Daniel Hailfinger91199a12011-07-07 06:59:18 +0000605else
606endif
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000607endif
608
Carl-Daniel Hailfinger6be74112009-08-12 16:17:41 +0000609ifeq ($(CONFIG_SERPROG), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000610FEATURE_CFLAGS += -D'CONFIG_SERPROG=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000611PROGRAMMER_OBJS += serprog.o
Carl-Daniel Hailfingerf2daaca2016-02-17 22:25:12 +0000612NEED_SERIAL += CONFIG_SERPROG
613NEED_POSIX_SOCKETS += CONFIG_SERPROG
Carl-Daniel Hailfinger6be74112009-08-12 16:17:41 +0000614endif
615
Carl-Daniel Hailfingere7fdd6e2010-07-21 10:26:01 +0000616ifeq ($(CONFIG_RAYER_SPI), yes)
617FEATURE_CFLAGS += -D'CONFIG_RAYER_SPI=1'
618PROGRAMMER_OBJS += rayer_spi.o
Carl-Daniel Hailfinger16c0aec2016-02-20 21:43:56 +0000619NEED_RAW_ACCESS += CONFIG_RAYER_SPI
Carl-Daniel Hailfingere7fdd6e2010-07-21 10:26:01 +0000620endif
621
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000622ifeq ($(CONFIG_PONY_SPI), yes)
623FEATURE_CFLAGS += -D'CONFIG_PONY_SPI=1'
624PROGRAMMER_OBJS += pony_spi.o
Carl-Daniel Hailfingerf2daaca2016-02-17 22:25:12 +0000625NEED_SERIAL += CONFIG_PONY_SPI
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000626endif
627
Carl-Daniel Hailfinger547872b2009-09-28 13:15:16 +0000628ifeq ($(CONFIG_BITBANG_SPI), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000629FEATURE_CFLAGS += -D'CONFIG_BITBANG_SPI=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000630PROGRAMMER_OBJS += bitbang_spi.o
Carl-Daniel Hailfinger547872b2009-09-28 13:15:16 +0000631endif
632
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000633ifeq ($(CONFIG_NIC3COM), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000634FEATURE_CFLAGS += -D'CONFIG_NIC3COM=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000635PROGRAMMER_OBJS += nic3com.o
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000636endif
Carl-Daniel Hailfinger6be74112009-08-12 16:17:41 +0000637
Uwe Hermann2bc98f62009-09-30 18:29:55 +0000638ifeq ($(CONFIG_GFXNVIDIA), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000639FEATURE_CFLAGS += -D'CONFIG_GFXNVIDIA=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000640PROGRAMMER_OBJS += gfxnvidia.o
Uwe Hermann2bc98f62009-09-30 18:29:55 +0000641endif
642
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000643ifeq ($(CONFIG_SATASII), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000644FEATURE_CFLAGS += -D'CONFIG_SATASII=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000645PROGRAMMER_OBJS += satasii.o
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000646endif
647
Uwe Hermannddd5c9e2010-02-21 21:17:00 +0000648ifeq ($(CONFIG_ATAHPT), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000649FEATURE_CFLAGS += -D'CONFIG_ATAHPT=1'
Uwe Hermannddd5c9e2010-02-21 21:17:00 +0000650PROGRAMMER_OBJS += atahpt.o
Uwe Hermannddd5c9e2010-02-21 21:17:00 +0000651endif
652
Jonathan Kollasch7f0f3fa2014-06-01 10:26:23 +0000653ifeq ($(CONFIG_ATAVIA), yes)
654FEATURE_CFLAGS += -D'CONFIG_ATAVIA=1'
655PROGRAMMER_OBJS += atavia.o
Jonathan Kollasch7f0f3fa2014-06-01 10:26:23 +0000656endif
657
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +0000658ifeq ($(CONFIG_ATAPROMISE), yes)
659FEATURE_CFLAGS += -D'CONFIG_ATAPROMISE=1'
660PROGRAMMER_OBJS += atapromise.o
Joseph C. Lehnerc2644a32016-01-16 23:45:25 +0000661endif
662
Kyösti Mälkki72d42f82014-06-01 23:48:31 +0000663ifeq ($(CONFIG_IT8212), yes)
664FEATURE_CFLAGS += -D'CONFIG_IT8212=1'
665PROGRAMMER_OBJS += it8212.o
Kyösti Mälkki72d42f82014-06-01 23:48:31 +0000666endif
667
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000668ifeq ($(CONFIG_FT2232_SPI), yes)
Thomas Heijligen121a5b82021-10-21 12:58:07 +0200669FEATURE_CFLAGS += -D'CONFIG_FT2232_SPI=1'
James Lairdc60de0e2013-03-27 13:00:23 +0000670PROGRAMMER_OBJS += ft2232_spi.o
671endif
672
673ifeq ($(CONFIG_USBBLASTER_SPI), yes)
Thomas Heijligen121a5b82021-10-21 12:58:07 +0200674FEATURE_CFLAGS += -D'CONFIG_USBBLASTER_SPI=1'
James Lairdc60de0e2013-03-27 13:00:23 +0000675PROGRAMMER_OBJS += usbblaster_spi.o
676endif
677
Justin Chevrier66e554b2015-02-08 21:58:10 +0000678ifeq ($(CONFIG_PICKIT2_SPI), yes)
679FEATURE_CFLAGS += -D'CONFIG_PICKIT2_SPI=1'
680PROGRAMMER_OBJS += pickit2_spi.o
Justin Chevrier66e554b2015-02-08 21:58:10 +0000681endif
682
Miklós Márton324929c2019-08-01 19:14:10 +0200683ifeq ($(CONFIG_STLINKV3_SPI), yes)
684FEATURE_CFLAGS += -D'CONFIG_STLINKV3_SPI=1'
685PROGRAMMER_OBJS += stlinkv3_spi.o
Miklós Márton324929c2019-08-01 19:14:10 +0200686endif
687
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000688ifeq ($(CONFIG_DUMMY), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000689FEATURE_CFLAGS += -D'CONFIG_DUMMY=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000690PROGRAMMER_OBJS += dummyflasher.o
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000691endif
692
693ifeq ($(CONFIG_DRKAISER), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000694FEATURE_CFLAGS += -D'CONFIG_DRKAISER=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000695PROGRAMMER_OBJS += drkaiser.o
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000696endif
Carl-Daniel Hailfinger6be74112009-08-12 16:17:41 +0000697
Joerg Fischer5665ef32010-05-21 21:54:07 +0000698ifeq ($(CONFIG_NICREALTEK), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000699FEATURE_CFLAGS += -D'CONFIG_NICREALTEK=1'
Joerg Fischer5665ef32010-05-21 21:54:07 +0000700PROGRAMMER_OBJS += nicrealtek.o
Joerg Fischer5665ef32010-05-21 21:54:07 +0000701endif
702
Andrew Morganc29c2e72010-06-07 22:37:54 +0000703ifeq ($(CONFIG_NICNATSEMI), yes)
704FEATURE_CFLAGS += -D'CONFIG_NICNATSEMI=1'
705PROGRAMMER_OBJS += nicnatsemi.o
Andrew Morganc29c2e72010-06-07 22:37:54 +0000706endif
707
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000708ifeq ($(CONFIG_NICINTEL), yes)
709FEATURE_CFLAGS += -D'CONFIG_NICINTEL=1'
710PROGRAMMER_OBJS += nicintel.o
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000711endif
712
Idwer Vollering004f4b72010-09-03 18:21:21 +0000713ifeq ($(CONFIG_NICINTEL_SPI), yes)
714FEATURE_CFLAGS += -D'CONFIG_NICINTEL_SPI=1'
715PROGRAMMER_OBJS += nicintel_spi.o
Idwer Vollering004f4b72010-09-03 18:21:21 +0000716endif
717
Ricardo Ribalda Delgado2a41f0a2014-07-28 20:35:21 +0000718ifeq ($(CONFIG_NICINTEL_EEPROM), yes)
719FEATURE_CFLAGS += -D'CONFIG_NICINTEL_EEPROM=1'
720PROGRAMMER_OBJS += nicintel_eeprom.o
Ricardo Ribalda Delgado2a41f0a2014-07-28 20:35:21 +0000721endif
722
Mark Marshall90021f22010-12-03 14:48:11 +0000723ifeq ($(CONFIG_OGP_SPI), yes)
724FEATURE_CFLAGS += -D'CONFIG_OGP_SPI=1'
725PROGRAMMER_OBJS += ogp_spi.o
Mark Marshall90021f22010-12-03 14:48:11 +0000726endif
727
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000728ifeq ($(CONFIG_BUSPIRATE_SPI), yes)
729FEATURE_CFLAGS += -D'CONFIG_BUSPIRATE_SPI=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000730PROGRAMMER_OBJS += buspirate_spi.o
Carl-Daniel Hailfingerf2daaca2016-02-17 22:25:12 +0000731NEED_SERIAL += CONFIG_BUSPIRATE_SPI
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000732endif
733
Carl-Daniel Hailfingerd38fac82010-01-19 11:15:48 +0000734ifeq ($(CONFIG_DEDIPROG), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000735FEATURE_CFLAGS += -D'CONFIG_DEDIPROG=1'
Carl-Daniel Hailfingerd38fac82010-01-19 11:15:48 +0000736PROGRAMMER_OBJS += dediprog.o
737endif
738
Daniel Thompson45e91a22018-06-04 13:46:29 +0100739ifeq ($(CONFIG_DEVELOPERBOX_SPI), yes)
740FEATURE_CFLAGS += -D'CONFIG_DEVELOPERBOX_SPI=1'
741PROGRAMMER_OBJS += developerbox_spi.o
Daniel Thompson45e91a22018-06-04 13:46:29 +0100742endif
743
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000744ifeq ($(CONFIG_SATAMV), yes)
745FEATURE_CFLAGS += -D'CONFIG_SATAMV=1'
746PROGRAMMER_OBJS += satamv.o
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000747endif
748
David Hendricksf9a30552015-05-23 20:30:30 -0700749ifeq ($(CONFIG_LINUX_MTD), yes)
Thomas Heijligenca71c872021-10-20 22:08:24 +0200750FEATURE_CFLAGS += -D'CONFIG_LINUX_MTD=1'
David Hendricksf9a30552015-05-23 20:30:30 -0700751PROGRAMMER_OBJS += linux_mtd.o
752endif
753
Carl-Daniel Hailfinger8541d232012-02-16 21:00:27 +0000754ifeq ($(CONFIG_LINUX_SPI), yes)
Thomas Heijligenca71c872021-10-20 22:08:24 +0200755FEATURE_CFLAGS += -D'CONFIG_LINUX_SPI=1'
Carl-Daniel Hailfinger8541d232012-02-16 21:00:27 +0000756PROGRAMMER_OBJS += linux_spi.o
757endif
758
Alexandre Boeglin80e64712014-12-20 20:25:19 +0000759ifeq ($(CONFIG_MSTARDDC_SPI), yes)
Thomas Heijligenca71c872021-10-20 22:08:24 +0200760FEATURE_CFLAGS += -D'CONFIG_MSTARDDC_SPI=1'
Alexandre Boeglin80e64712014-12-20 20:25:19 +0000761PROGRAMMER_OBJS += mstarddc_spi.o
762endif
763
Urja Rannikko0870b022016-01-31 22:10:29 +0000764ifeq ($(CONFIG_CH341A_SPI), yes)
765FEATURE_CFLAGS += -D'CONFIG_CH341A_SPI=1'
766PROGRAMMER_OBJS += ch341a_spi.o
Urja Rannikko0870b022016-01-31 22:10:29 +0000767endif
768
Lubomir Rintelb2154e82018-01-14 17:35:33 +0100769ifeq ($(CONFIG_DIGILENT_SPI), yes)
770FEATURE_CFLAGS += -D'CONFIG_DIGILENT_SPI=1'
771PROGRAMMER_OBJS += digilent_spi.o
Lubomir Rintelb2154e82018-01-14 17:35:33 +0100772endif
773
Jean THOMASe28d8e42022-10-11 17:54:30 +0200774ifeq ($(CONFIG_DIRTYJTAG_SPI), yes)
775FEATURE_CFLAGS += -D'CONFIG_DIRTYJTAG_SPI=1'
776PROGRAMMER_OBJS += dirtyjtag_spi.o
777endif
778
Marc Schink3578ec62016-03-17 16:23:03 +0100779ifeq ($(CONFIG_JLINK_SPI), yes)
Marc Schink3578ec62016-03-17 16:23:03 +0100780FEATURE_CFLAGS += -D'CONFIG_JLINK_SPI=1'
781PROGRAMMER_OBJS += jlink_spi.o
782endif
783
Miklós Márton2d20d6d2018-01-30 20:20:15 +0100784ifeq ($(CONFIG_NI845X_SPI), yes)
785FEATURE_CFLAGS += -D'CONFIG_NI845X_SPI=1'
Miklós Márton2d20d6d2018-01-30 20:20:15 +0100786PROGRAMMER_OBJS += ni845x_spi.o
787endif
788
Carl-Daniel Hailfingerf2daaca2016-02-17 22:25:12 +0000789ifneq ($(NEED_SERIAL), )
Thomas Heijligen140c1262021-09-27 15:12:26 +0200790LIB_OBJS += serial.o
791ifeq ($(TARGET_OS), Linux)
792LIB_OBJS += custom_baud_linux.o
793else
794LIB_OBJS += custom_baud.o
795endif
Carl-Daniel Hailfinger5bdf2982010-06-14 12:42:05 +0000796endif
797
Carl-Daniel Hailfingerf2daaca2016-02-17 22:25:12 +0000798ifneq ($(NEED_POSIX_SOCKETS), )
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000799ifeq ($(TARGET_OS), SunOS)
Stefan Taunerfc3ecc22016-03-13 12:57:03 +0000800LIBS += -lsocket -lnsl
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000801endif
Carl-Daniel Hailfingere51ea102009-11-23 19:20:11 +0000802endif
803
Nico Huberf55ca202021-06-27 14:36:06 +0200804NEED_LIBPCI := $(call filter_deps,$(DEPENDS_ON_LIBPCI))
Carl-Daniel Hailfingerf2daaca2016-02-17 22:25:12 +0000805ifneq ($(NEED_LIBPCI), )
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +0000806CHECK_LIBPCI = yes
Carl-Daniel Hailfinger16c0aec2016-02-20 21:43:56 +0000807# This is a dirty hack, but it saves us from checking all PCI drivers and all platforms manually.
808# libpci may need raw memory, MSR or PCI port I/O on some platforms.
809# Individual drivers might have the same needs as well.
810NEED_RAW_ACCESS += $(NEED_LIBPCI)
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000811FEATURE_CFLAGS += -D'NEED_PCI=1'
Stefan Tauner3f73ffe2016-01-07 17:45:59 +0000812FEATURE_CFLAGS += $(call debug_shell,grep -q "OLD_PCI_GET_DEV := yes" .libdeps && printf "%s" "-D'OLD_PCI_GET_DEV=1'")
Stefan Tauner56734502015-02-08 21:58:04 +0000813
Carl-Daniel Hailfinger16c0aec2016-02-20 21:43:56 +0000814PROGRAMMER_OBJS += pcidev.o
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000815ifeq ($(TARGET_OS), NetBSD)
Carl-Daniel Hailfinger460b2822010-06-04 23:24:57 +0000816# The libpci we want is called libpciutils on NetBSD and needs NetBSD libpci.
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000817PCILIBS += -lpciutils -lpci
Carl-Daniel Hailfinger16c0aec2016-02-20 21:43:56 +0000818else
819PCILIBS += -lpci
820endif
821endif
822
823ifneq ($(NEED_RAW_ACCESS), )
824# Raw memory, MSR or PCI port I/O access.
825FEATURE_CFLAGS += -D'NEED_RAW_ACCESS=1'
Thomas Heijligen74b4aa02021-12-14 17:52:30 +0100826PROGRAMMER_OBJS += hwaccess.o hwaccess_physmap.o
Carl-Daniel Hailfinger16c0aec2016-02-20 21:43:56 +0000827
Nico Huber9245b882021-04-18 20:50:32 +0200828ifeq ($(ARCH), x86)
Thomas Heijligena0655202021-12-14 16:36:05 +0100829FEATURE_CFLAGS += -D'__FLASHROM_HAVE_OUTB__=1'
Thomas Heijligenb3287b42021-12-14 17:25:49 +0100830PROGRAMMER_OBJS += hwaccess_x86_io.o hwaccess_x86_msr.o
Thomas Heijligena0655202021-12-14 16:36:05 +0100831
832ifeq ($(TARGET_OS), NetBSD)
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000833PCILIBS += -l$(shell uname -p)
Nico Huber9245b882021-04-18 20:50:32 +0200834endif
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +0000835ifeq ($(TARGET_OS), OpenBSD)
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000836PCILIBS += -l$(shell uname -m)
Nico Huber9245b882021-04-18 20:50:32 +0200837endif
Thomas Heijligena0655202021-12-14 16:36:05 +0100838endif
839
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000840ifeq ($(TARGET_OS), Darwin)
841# DirectHW framework can be found in the DirectHW library.
Stefan Taunere34e3e82013-01-01 00:06:51 +0000842PCILIBS += -framework IOKit -framework DirectHW
Carl-Daniel Hailfingerb63b0672010-07-02 17:12:50 +0000843endif
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +0000844endif
Carl-Daniel Hailfinger66ef4e52009-12-13 22:28:00 +0000845
Thomas Heijligenb7c6a662021-11-05 10:47:40 +0100846USE_LIBUSB1 := $(if $(call filter_deps,$(DEPENDS_ON_LIBUSB1)),yes,no)
847ifeq ($(USE_LIBUSB1), yes)
848override CFLAGS += $(CONFIG_LIBUSB1_CFLAGS)
849override LDFLAGS += $(CONFIG_LIBUSB1_LDFLAGS)
Daniel Thompson1d507a02018-07-12 11:02:28 +0100850PROGRAMMER_OBJS += usbdev.o
Stefan Taunere49edbb2016-01-31 22:10:14 +0000851endif
852
Thomas Heijligen121a5b82021-10-21 12:58:07 +0200853USE_LIBFTDI1 := $(if $(call filter_deps,$(DEPENDS_ON_LIBFTDI1)),yes,no)
854ifeq ($(USE_LIBFTDI1), yes)
855override CFLAGS += $(CONFIG_LIBFTDI1_CFLAGS)
856override LDFLAGS += $(CONFIG_LIBFTDI1_LDFLAGS)
857ifeq ($(HAS_FT232H), yes)
858FEATURE_CFLAGS += -D'HAVE_FT232H=1'
859endif
Nico Huber09e82e22021-06-27 14:31:37 +0200860endif
861
Thomas Heijligenff63acd2021-11-05 10:19:42 +0100862USE_LIB_NI845X := $(if $(call filter_deps,$(DEPENDS_ON_LIB_NI845X)),yes,no)
863ifeq ($(USE_LIB_NI845X), yes)
864override CFLAGS += $(CONFIG_LIB_NI845X_CFLAGS)
865override LDFLAGS += $(CONFIG_LIB_NI845X_LDFLAGS)
866endif
867
Thomas Heijligen4dca8992021-11-05 10:34:31 +0100868USE_LIBJAYLINK := $(if $(call filter_deps,$(DEPENDS_ON_LIBJAYLINK)),yes,no)
869ifeq ($(USE_LIBJAYLINK), yes)
870override CFLAGS += $(CONFIG_LIBJAYLINK_CFLAGS)
871override LDFLAGS += $(CONFIG_LIBJAYLINK_LDFLAGS)
Marc Schink3578ec62016-03-17 16:23:03 +0100872endif
873
Carl-Daniel Hailfinger9c8476b2009-09-16 12:19:03 +0000874ifeq ($(CONFIG_PRINT_WIKI), yes)
Carl-Daniel Hailfinger71127722010-05-31 15:27:27 +0000875FEATURE_CFLAGS += -D'CONFIG_PRINT_WIKI=1'
Sean Nelson5d134642009-12-24 16:54:21 +0000876CLI_OBJS += print_wiki.o
Carl-Daniel Hailfinger9c8476b2009-09-16 12:19:03 +0000877endif
878
Carl-Daniel Hailfingera472b8b2009-10-03 17:08:02 +0000879# We could use PULLED_IN_LIBS, but that would be ugly.
Stefan Tauner3f73ffe2016-01-07 17:45:59 +0000880FEATURE_LIBS += $(call debug_shell,grep -q "NEEDLIBZ := yes" .libdeps && printf "%s" "-lz")
Carl-Daniel Hailfingera472b8b2009-10-03 17:08:02 +0000881
Thomas Heijligen457020a2021-10-26 12:44:36 +0200882ifeq ($(HAS_UTSNAME), yes)
883FEATURE_CFLAGS += -D'HAVE_UTSNAME=1'
884endif
885
886ifeq ($(HAS_CLOCK_GETTIME), yes)
887FEATURE_CFLAGS += -D'HAVE_CLOCK_GETTIME=1'
888FEATURE_LIBS += -lrt
889endif
Nico Huber8624e8c2012-11-05 21:46:33 +0100890
Patrick Georgi97bc95c2011-03-08 07:17:44 +0000891LIBFLASHROM_OBJS = $(CHIP_OBJS) $(PROGRAMMER_OBJS) $(LIB_OBJS)
Stefan Taunerd94d25d2012-07-28 03:17:15 +0000892OBJS = $(CLI_OBJS) $(LIBFLASHROM_OBJS)
Sean Nelson5d134642009-12-24 16:54:21 +0000893
Joerg Mayera93d9dc2013-08-29 00:38:19 +0000894all: hwlibs features $(PROGRAM)$(EXEC_SUFFIX) $(PROGRAM).8
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000895ifeq ($(ARCH), x86)
Thomas Heijligen3976b7e2021-10-20 15:55:35 +0200896 @+$(MAKE) -C util/ich_descriptors_tool/ HOST_OS=$(HOST_OS) TARGET_OS=$(TARGET_OS)
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000897endif
898
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +0000899$(PROGRAM)$(EXEC_SUFFIX): $(OBJS)
Thomas Heijligenb7c6a662021-11-05 10:47:40 +0100900 $(CC) -o $(PROGRAM)$(EXEC_SUFFIX) $(OBJS) $(LDFLAGS) $(LIBS) $(PCILIBS) $(FEATURE_LIBS)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000901
Patrick Georgi97bc95c2011-03-08 07:17:44 +0000902libflashrom.a: $(LIBFLASHROM_OBJS)
903 $(AR) rcs $@ $^
904 $(RANLIB) $@
905
Carl-Daniel Hailfinger8ef7dce2009-07-10 20:19:48 +0000906# TAROPTIONS reduces information leakage from the packager's system.
907# If other tar programs support command line arguments for setting uid/gid of
908# stored files, they can be handled here as well.
909TAROPTIONS = $(shell LC_ALL=C tar --version|grep -q GNU && echo "--owner=root --group=root")
Carl-Daniel Hailfingerb18ecbc2009-06-19 14:20:34 +0000910
Thomas Heijligen19169222021-10-20 23:26:34 +0200911%.o: %.c features
Stefan Tauner76347082016-11-27 17:45:49 +0100912 $(CC) -MMD $(CFLAGS) $(CPPFLAGS) $(FLASHROM_CFLAGS) $(FEATURE_CFLAGS) $(SCMDEF) -o $@ -c $<
Clark Rawlins02016f72008-02-14 23:22:20 +0000913
Carl-Daniel Hailfingera0020df2010-05-30 22:35:14 +0000914# Make sure to add all names of generated binaries here.
915# This includes all frontends and libflashrom.
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +0000916# We don't use EXEC_SUFFIX here because we want to clean everything.
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000917clean:
Thomas Heijligen1e76dc82021-09-28 15:22:34 +0200918 rm -f $(PROGRAM) $(PROGRAM).exe libflashrom.a $(filter-out Makefile.d, $(wildcard *.d *.o)) $(PROGRAM).8 $(PROGRAM).8.html $(BUILD_DETAILS_FILE)
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000919 @+$(MAKE) -C util/ich_descriptors_tool/ clean
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000920
Ollie Lho184a4042005-11-26 21:55:36 +0000921distclean: clean
Thomas Heijligen19169222021-10-20 23:26:34 +0200922 rm -f .libdeps
Christian Ruppertdb9d9f42009-05-14 14:17:07 +0000923
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +0000924strip: $(PROGRAM)$(EXEC_SUFFIX)
925 $(STRIP) $(STRIP_ARGS) $(PROGRAM)$(EXEC_SUFFIX)
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000926
Stefan Tauner56787082011-08-18 02:27:19 +0000927# to define test programs we use verbatim variables, which get exported
928# to environment variables and are referenced with $$<varname> later
929
Carl-Daniel Hailfinger5d3fcb92010-06-14 18:40:59 +0000930compiler: featuresavailable
Thomas Heijligen323ad352021-10-26 11:26:32 +0200931 @echo -n "C compiler found: "
932 @if [ $(CC_WORKING) = yes ]; \
933 then $(CC) --version 2>/dev/null | head -1; \
934 else echo no; echo Aborting.; exit 1; fi
Thomas Heijligen8cd366d2021-10-26 12:02:52 +0200935 @echo "Target arch: $(ARCH)"
Thomas Heijligen6efdfb32021-10-12 15:16:46 +0200936 @if [ $(ARCH) = unknown ]; then echo Aborting.; exit 1; fi
Thomas Heijligen8cd366d2021-10-26 12:02:52 +0200937 @echo "Target OS: $(TARGET_OS)"
Thomas Heijligen1e76dc82021-09-28 15:22:34 +0200938 @if [ $(TARGET_OS) = unknown ]; then echo Aborting.; exit 1; fi
Thomas Heijligen8cd366d2021-10-26 12:02:52 +0200939 @if [ $(TARGET_OS) = libpayload ] && ! $(CC) --version 2>&1 | grep -q coreboot; then \
940 echo " Warning: It seems you are not using coreboot's reference compiler."; \
941 echo " This might work but usually does not, please beware."; fi
942 @echo "Target endian: $(ENDIAN)"
Thomas Heijligen9a2787b2021-10-12 15:54:06 +0200943 @if [ $(ENDIAN) = unknown ]; then echo Aborting.; exit 1; fi
Carl-Daniel Hailfinger4cb7a962009-06-16 09:31:51 +0000944
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000945hwlibs: compiler
946 @printf "" > .libdeps
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +0000947ifeq ($(CHECK_LIBPCI), yes)
Stefan Tauner3f73ffe2016-01-07 17:45:59 +0000948 @printf "Checking for libpci headers... " | tee -a $(BUILD_DETAILS_FILE)
Stefan Tauner56787082011-08-18 02:27:19 +0000949 @echo "$$LIBPCI_TEST" > .test.c
Stefan Taunerc83ddc12016-01-24 22:37:10 +0000950 @printf "\nexec: %s\n" "$(CC) -c $(CPPFLAGS) $(CFLAGS) .test.c -o .test.o" >>$(BUILD_DETAILS_FILE)
Stefan Tauner3f73ffe2016-01-07 17:45:59 +0000951 @{ { { { { $(CC) -c $(CPPFLAGS) $(CFLAGS) .test.c -o .test.o >&2 && \
952 echo "found." || { echo "not found."; echo; \
Carl-Daniel Hailfingerf2daaca2016-02-17 22:25:12 +0000953 echo "The following features require libpci: $(NEED_LIBPCI)."; \
Carl-Daniel Hailfinger4b2b3152016-02-20 22:28:16 +0000954 echo "Please install libpci headers or disable all features"; \
955 echo "mentioned above by specifying make CONFIG_ENABLE_LIBPCI_PROGRAMMERS=no"; \
Carl-Daniel Hailfingera472b8b2009-10-03 17:08:02 +0000956 echo "See README for more information."; echo; \
Stefan Tauner3f73ffe2016-01-07 17:45:59 +0000957 rm -f .test.c .test.o; exit 1; }; } 2>>$(BUILD_DETAILS_FILE); echo $? >&3 ; } | tee -a $(BUILD_DETAILS_FILE) >&4; } 3>&1;} | { read rc ; exit ${rc}; } } 4>&1
958 @printf "Checking version of pci_get_dev... " | tee -a $(BUILD_DETAILS_FILE)
Stefan Tauner56734502015-02-08 21:58:04 +0000959 @echo "$$PCI_GET_DEV_TEST" > .test.c
Stefan Taunerc83ddc12016-01-24 22:37:10 +0000960 @printf "\nexec: %s\n" "$(CC) -c $(CPPFLAGS) $(CFLAGS) .test.c -o .test.o" >>$(BUILD_DETAILS_FILE)
Stefan Tauner3f73ffe2016-01-07 17:45:59 +0000961 @ { $(CC) -c $(CPPFLAGS) $(CFLAGS) .test.c -o .test.o >&2 && \
Stefan Tauner56734502015-02-08 21:58:04 +0000962 ( echo "new version (including PCI domain parameter)."; echo "OLD_PCI_GET_DEV := no" >> .libdeps ) || \
Stefan Tauner3f73ffe2016-01-07 17:45:59 +0000963 ( echo "old version (without PCI domain parameter)."; echo "OLD_PCI_GET_DEV := yes" >> .libdeps ) } 2>>$(BUILD_DETAILS_FILE) | tee -a $(BUILD_DETAILS_FILE)
964 @printf "Checking if libpci is present and sufficient... " | tee -a $(BUILD_DETAILS_FILE)
Stefan Taunerc83ddc12016-01-24 22:37:10 +0000965 @printf "\nexec: %s\n" "$(CC) $(LDFLAGS) .test.o -o .test$(EXEC_SUFFIX) $(LIBS) $(PCILIBS)" >>$(BUILD_DETAILS_FILE)
Stefan Tauner3f73ffe2016-01-07 17:45:59 +0000966 @{ { { { $(CC) $(LDFLAGS) .test.o -o .test$(EXEC_SUFFIX) $(LIBS) $(PCILIBS) 2>>$(BUILD_DETAILS_FILE) >&2 && \
967 echo "yes." || { echo "no."; \
968 printf "Checking if libz+libpci are present and sufficient..." ; \
Stefan Taunerc83ddc12016-01-24 22:37:10 +0000969 { printf "\nexec: %s\n" "$(CC) $(LDFLAGS) .test.o -o .test$(EXEC_SUFFIX) $(LIBS) $(PCILIBS) -lz" >>$(BUILD_DETAILS_FILE) ; \
970 $(CC) $(LDFLAGS) .test.o -o .test$(EXEC_SUFFIX) $(LIBS) $(PCILIBS) -lz >&2 && \
Stefan Tauner3f73ffe2016-01-07 17:45:59 +0000971 echo "yes." && echo "NEEDLIBZ := yes" > .libdeps } || { echo "no."; echo; \
Carl-Daniel Hailfingerf2daaca2016-02-17 22:25:12 +0000972 echo "The following features require libpci: $(NEED_LIBPCI)."; \
Carl-Daniel Hailfinger4b2b3152016-02-20 22:28:16 +0000973 echo "Please install libpci (package pciutils) and/or libz or disable all features"; \
974 echo "mentioned above by specifying make CONFIG_ENABLE_LIBPCI_PROGRAMMERS=no"; \
Carl-Daniel Hailfingera472b8b2009-10-03 17:08:02 +0000975 echo "See README for more information."; echo; \
Stefan Tauner3f73ffe2016-01-07 17:45:59 +0000976 rm -f .test.c .test.o .test$(EXEC_SUFFIX); exit 1; }; }; } 2>>$(BUILD_DETAILS_FILE); echo $? >&3 ; } | tee -a $(BUILD_DETAILS_FILE) >&4; } 3>&1;} | { read rc ; exit ${rc}; } } 4>&1
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +0000977 @rm -f .test.c .test.o .test$(EXEC_SUFFIX)
Carl-Daniel Hailfingere7a39bf2012-11-20 21:06:16 +0000978endif
Thomas Heijligenb7c6a662021-11-05 10:47:40 +0100979 @echo Dependency libusb1 found: $(HAS_LIBUSB1)
980 @if [ $(HAS_LIBUSB1) = yes ]; then \
981 echo " CFLAGS: $(CONFIG_LIBUSB1_CFLAGS)"; \
982 echo " LDFLAGS: $(CONFIG_LIBUSB1_LDFLAGS)"; \
983 fi
Thomas Heijligen4dca8992021-11-05 10:34:31 +0100984 @echo Dependency libjaylink found: $(HAS_LIBJAYLINK)
985 @if [ $(HAS_LIBJAYLINK) = yes ]; then \
986 echo " CFLAGS: $(CONFIG_LIBJAYLINK_CFLAGS)"; \
987 echo " LDFLAGS: $(CONFIG_LIBJAYLINK_LDFLAGS)"; \
988 fi
Thomas Heijligenff63acd2021-11-05 10:19:42 +0100989 @echo Dependency NI-845x found: $(HAS_LIB_NI845X)
990 @if [ $(HAS_LIB_NI845X) = yes ]; then \
991 echo " CFLAGS: $(CONFIG_LIB_NI845X_CFLAGS)"; \
992 echo " LDFLAGS: $(CONFIG_LIB_NI845X_LDFLAGS)"; \
993 fi
Thomas Heijligen121a5b82021-10-21 12:58:07 +0200994 @echo Dependency libftdi1 found: $(HAS_LIBFTDI1)
995 @if [ $(HAS_LIBFTDI1) = yes ]; then \
996 echo " Checking for \"TYPE_232H\" in \"enum ftdi_chip_type\": $(HAS_FT232H)"; \
997 echo " CFLAGS: $(CONFIG_LIBFTDI1_CFLAGS)"; \
998 echo " LDFLAGS: $(CONFIG_LIBFTDI1_LDFLAGS)"; \
999 fi
Carl-Daniel Hailfingerb18ecbc2009-06-19 14:20:34 +00001000
Carl-Daniel Hailfinger5d3fcb92010-06-14 18:40:59 +00001001# If a user does not explicitly request a non-working feature, we should
1002# silently disable it. However, if a non-working (does not compile) feature
1003# is explicitly requested, we should bail out with a descriptive error message.
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +00001004# We also have to check that at least one programmer driver is enabled.
Carl-Daniel Hailfinger5d3fcb92010-06-14 18:40:59 +00001005featuresavailable:
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +00001006ifeq ($(PROGRAMMER_OBJS),)
1007 @echo "You have to enable at least one programmer driver!"
1008 @false
1009endif
1010ifneq ($(UNSUPPORTED_FEATURES), )
Carl-Daniel Hailfinger5d3fcb92010-06-14 18:40:59 +00001011 @echo "The following features are unavailable on your machine: $(UNSUPPORTED_FEATURES)"
1012 @false
1013endif
1014
Thomas Heijligen19169222021-10-20 23:26:34 +02001015features: hwlibs
Thomas Heijligenca71c872021-10-20 22:08:24 +02001016 @echo "Checking for header \"mtd/mtd-user.h\": $(HAS_LINUX_MTD)"
1017 @echo "Checking for header \"linux/spi/spidev.h\": $(HAS_LINUX_SPI)"
1018 @echo "Checking for header \"linux/i2c-dev.h\": $(HAS_LINUX_I2C)"
1019 @echo "Checking for header \"linux/i2c.h\": $(HAS_LINUX_I2C)"
1020 @echo "Checking for header \"sys/utsname.h\": $(HAS_UTSNAME)"
1021 @echo "Checking for function \"clock_gettime\": $(HAS_CLOCK_GETTIME)"
Paul Fox05dfbe62009-06-16 21:08:06 +00001022
Stefan Tauner4c723152016-01-14 22:47:55 +00001023$(PROGRAM).8.html: $(PROGRAM).8
1024 @groff -mandoc -Thtml $< >$@
1025
Joerg Mayera93d9dc2013-08-29 00:38:19 +00001026$(PROGRAM).8: $(PROGRAM).8.tmpl
Stefan Tauner4c723152016-01-14 22:47:55 +00001027 @# Add the man page change date and version to the man page
Nico Huberac90af62022-12-18 00:22:47 +00001028 @sed -e 's#.TH FLASHROM 8 .*#.TH FLASHROM 8 "$(MAN_DATE)" "flashrom-stable-$(VERSION)" "$(MAN_DATE)"#' <$< >$@
Joerg Mayera93d9dc2013-08-29 00:38:19 +00001029
1030install: $(PROGRAM)$(EXEC_SUFFIX) $(PROGRAM).8
Uwe Hermannc2a9c9c2009-05-14 14:51:14 +00001031 mkdir -p $(DESTDIR)$(PREFIX)/sbin
Uwe Hermann56b2cb02009-05-21 15:59:58 +00001032 mkdir -p $(DESTDIR)$(MANDIR)/man8
Carl-Daniel Hailfingerddbab712010-06-14 14:44:08 +00001033 $(INSTALL) -m 0755 $(PROGRAM)$(EXEC_SUFFIX) $(DESTDIR)$(PREFIX)/sbin
Uwe Hermann56b2cb02009-05-21 15:59:58 +00001034 $(INSTALL) -m 0644 $(PROGRAM).8 $(DESTDIR)$(MANDIR)/man8
Uwe Hermannc113b572006-12-14 00:59:41 +00001035
Nico Huber454f6132012-12-10 13:34:10 +00001036libinstall: libflashrom.a libflashrom.h
1037 mkdir -p $(DESTDIR)$(PREFIX)/lib
1038 $(INSTALL) -m 0644 libflashrom.a $(DESTDIR)$(PREFIX)/lib
1039 mkdir -p $(DESTDIR)$(PREFIX)/include
1040 $(INSTALL) -m 0644 libflashrom.h $(DESTDIR)$(PREFIX)/include
1041
Nico Huber5f245a22023-01-10 17:14:47 +01001042versioninfo:
1043# Generate versioninfo.inc containing metadata that would not be available in exported sources otherwise.
1044 @[ "$(RELEASE)" ] || { echo 'Error: Must provide `RELEASE=...`'; exit 1; }
1045 @echo "VERSION = $(RELEASE)" > $@.inc
1046 @echo "MAN_DATE = $(shell ./util/getrevision.sh --date $(PROGRAM).8.tmpl 2>/dev/null)" >> $@.inc
1047
Nico Huber26c2c4d2023-01-10 17:45:38 +01001048branch: versioninfo
1049 @git checkout -b $(RELEASE)
1050 @git add -f $<.inc
1051 @git commit -sm'Update version info for $(RELEASE)'
1052
1053tag: versioninfo
1054 @git add -f $<.inc
1055 @git commit -sm'Update version info for $(RELEASE)'
1056 @git tag -s $(RELEASE)
1057
Nico Huber5f245a22023-01-10 17:14:47 +01001058# No spaces in release names unless set explicitly
Nico Huber1d58a902023-01-10 18:26:12 +01001059RELEASENAME ?= flashrom-stable-$(shell echo "$(VERSION)" | sed -e 's/ /_/')
Nico Huber5f245a22023-01-10 17:14:47 +01001060
Nico Huber1d58a902023-01-10 18:26:12 +01001061_export: EXPORT_VERSIONINFO := $(EXPORTDIR)/$(RELEASENAME)/versioninfo.inc
Stefan Tauner76347082016-11-27 17:45:49 +01001062_export: $(PROGRAM).8
Nico Huber1d58a902023-01-10 18:26:12 +01001063 @rm -rf "$(EXPORTDIR)/$(RELEASENAME)"
1064 @mkdir -p "$(EXPORTDIR)/$(RELEASENAME)"
1065 @git archive HEAD | tar -x -C "$(EXPORTDIR)/$(RELEASENAME)"
Nico Huber5f245a22023-01-10 17:14:47 +01001066# Generate fresh versioninfo.inc and compare
1067 @echo "VERSION = $(shell ./util/getrevision.sh --revision)" > "$(EXPORT_VERSIONINFO)"
1068 @echo "MAN_DATE = $(shell ./util/getrevision.sh --date $(PROGRAM).8.tmpl 2>/dev/null)" >> \
1069 "$(EXPORT_VERSIONINFO)"
1070 @if [ -f versioninfo.inc ]; then \
1071 cmp -s versioninfo.inc "$(EXPORT_VERSIONINFO)" || \
1072 { echo Error: Version info changed:; \
1073 cat "$(EXPORT_VERSIONINFO)"; \
1074 echo Update versioninfo.inc and tag accordingly.; \
1075 exit 1; \
1076 }; \
1077 fi
Stefan Taunere4136852017-10-01 15:57:25 +02001078# Restore modification date of all tracked files not marked 'export-ignore' in .gitattributes.
1079# sed is required to filter out file names having the attribute set.
1080# The sed program saves the file name in the hold buffer and then checks if the respective value is 'set'.
1081# If so it ignores the rest of the program, which otherwise restores the file name and prints it.
Stefan Tauner76347082016-11-27 17:45:49 +01001082 @git ls-tree -r -z -t --full-name --name-only HEAD | \
1083 git check-attr -z --stdin export-ignore | \
Stefan Taunere4136852017-10-01 15:57:25 +02001084 sed -zne 'x;n;n;{/^set$$/b;};x;p;' | \
Stefan Tauner76347082016-11-27 17:45:49 +01001085 xargs -0 sh -c 'for f; do \
1086 touch -d $$(git log --pretty=format:%cI -1 HEAD -- "$$f") \
Nico Huber1d58a902023-01-10 18:26:12 +01001087 "$(EXPORTDIR)/$(RELEASENAME)/$$f"; \
Stefan Taunere4136852017-10-01 15:57:25 +02001088 done' dummy_arg0
Carl-Daniel Hailfingera23041c2009-06-12 14:49:10 +00001089
Stefan Tauner76347082016-11-27 17:45:49 +01001090export: _export
Nico Huber1d58a902023-01-10 18:26:12 +01001091 @echo "Exported $(EXPORTDIR)/$(RELEASENAME)/"
Stefan Tauner76347082016-11-27 17:45:49 +01001092
1093tarball: _export
Nico Huber1d58a902023-01-10 18:26:12 +01001094 @tar -cj --format=ustar -f "$(EXPORTDIR)/$(RELEASENAME).tar.bz2" -C $(EXPORTDIR)/ \
1095 $(TAROPTIONS) "$(RELEASENAME)/"
Stefan Tauner76347082016-11-27 17:45:49 +01001096# Delete the exported directory again because it is most likely what's expected by the user.
Nico Huber1d58a902023-01-10 18:26:12 +01001097 @rm -rf "$(EXPORTDIR)/$(RELEASENAME)"
1098 @echo Created "$(EXPORTDIR)/$(RELEASENAME).tar.bz2"
Carl-Daniel Hailfingera23041c2009-06-12 14:49:10 +00001099
Carl-Daniel Hailfinger33a65a02011-12-20 00:51:44 +00001100libpayload: clean
1101 make CC="CC=i386-elf-gcc lpgcc" AR=i386-elf-ar RANLIB=i386-elf-ranlib
Carl-Daniel Hailfinger50415d22010-03-21 14:54:57 +00001102
Felix Singer9441c6e2022-10-21 12:47:11 +02001103gitconfig:
1104 ./util/getrevision.sh -c 2>/dev/null && ./util/git-hooks/install.sh
1105
Nico Huber26c2c4d2023-01-10 17:45:38 +01001106.PHONY: all install clean distclean compiler hwlibs features branch tag versioninfo _export export tarball featuresavailable libpayload gitconfig
Ollie Lho184a4042005-11-26 21:55:36 +00001107
Stefan Tauner23e10b82016-01-23 16:16:49 +00001108# Disable implicit suffixes and built-in rules (for performance and profit)
1109.SUFFIXES:
1110
Stefan Reinauere2f01582010-06-07 11:08:07 +00001111-include $(OBJS:.o=.d)