This solution is copied from ft2232_spi and is equally hacky.
Thanks to M.K. for investigating the history of <linux/spi/spidev.h>, which
led to a hopefully more robust check.

Signed-off-by: Stefan Tauner <[email protected]>
---
Andrey could you please test this patch? It should disable linux_spi
if it can not find valid headers and compilation of flashrom should then
succeed without the need of specifying CONFIG_LINUX_SPI=no.

 Makefile    |   23 ++++++++++++++++++++++-
 linux_spi.c |    5 +++++
 2 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index c921a74..4de89e0 100644
--- a/Makefile
+++ b/Makefile
@@ -485,7 +485,8 @@ NEED_PCI := yes
 endif
 
 ifeq ($(CONFIG_LINUX_SPI), yes)
-FEATURE_CFLAGS += -D'CONFIG_LINUX_SPI=1'
+# This is a totally ugly hack.
+FEATURE_CFLAGS += $(shell LC_ALL=C grep -q "LINUX_SPI_SUPPORT := yes" 
.features && printf "%s" "-D'CONFIG_LINUX_SPI=1'")
 PROGRAMMER_OBJS += linux_spi.o
 endif
 
@@ -671,6 +672,19 @@ int main(int argc, char **argv)
 endef
 export UTSNAME_TEST
 
+define LINUX_SPI_TEST
+#include <linux/types.h>
+#include <linux/spi/spidev.h>
+
+int main(int argc, char **argv)
+{
+       (void) argc;
+       (void) argv;
+       return 0;
+}
+endef
+export LINUX_SPI_TEST
+
 features: compiler
        @echo "FEATURES := yes" > .features.tmp
 ifeq ($(CONFIG_FT2232_SPI), yes)
@@ -680,6 +694,13 @@ ifeq ($(CONFIG_FT2232_SPI), yes)
                ( echo "found."; echo "FTDISUPPORT := yes" >> .features.tmp ) 
||        \
                ( echo "not found."; echo "FTDISUPPORT := no" >> .features.tmp )
 endif
+ifeq ($(CONFIG_LINUX_SPI), yes)
+       @printf "Checking if Linux SPI headers are present... "
+       @echo "$$LINUX_SPI_TEST" > .featuretest.c
+       @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o 
.featuretest$(EXEC_SUFFIX) >/dev/null 2>&1 && \
+               ( echo "yes."; echo "LINUX_SPI_SUPPORT := yes" >> .features.tmp 
) ||    \
+               ( echo "no."; echo "LINUX_SPI_SUPPORT := no" >> .features.tmp )
+endif
        @printf "Checking for utsname support... "
        @echo "$$UTSNAME_TEST" > .featuretest.c
        @$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) .featuretest.c -o 
.featuretest$(EXEC_SUFFIX) >/dev/null 2>&1 && \
diff --git a/linux_spi.c b/linux_spi.c
index 17d003e..f4d30c9 100644
--- a/linux_spi.c
+++ b/linux_spi.c
@@ -17,6 +17,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#if CONFIG_LINUX_SPI == 1
+
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -24,6 +26,7 @@
 #include <errno.h>
 #include <ctype.h>
 #include <unistd.h>
+#include <linux/types.h>
 #include <linux/spi/spidev.h>
 #include <sys/ioctl.h>
 #include "flash.h"
@@ -176,3 +179,5 @@ static int linux_spi_write_256(struct flashctx *flash, 
uint8_t *buf,
        return spi_write_chunked(flash, buf, start, len,
                                ((unsigned int)getpagesize()) - 4);
 }
+
+#endif // CONFIG_LINUX_SPI == 1
-- 
1.7.1


_______________________________________________
flashrom mailing list
[email protected]
http://www.flashrom.org/mailman/listinfo/flashrom

Reply via email to