From 9c4b1d0c79645c3065aa4c2f3019c14da6cb2675 Mon Sep 17 00:00:00 2001 From: Marvin Arnold Date: Mon, 18 Oct 2021 09:55:58 -0500 Subject: [PATCH] fix(build): set SPI_DEV_DIR and SPI_SPEED macros Also improved logging. --- Dockerfile | 8 +++++--- compile_libloragw.sh | 4 ++-- libloragw/Makefile | 3 ++- libloragw/src/loragw_spi.native.c | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2425703e..8c1ae9c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,14 @@ # $OUTPUT_DIR/$SPI_BUS respectively. Also copies reset_lgw.sh # to $OUTPUT_DIR. -FROM balenalib/raspberry-pi-debian:buster-build as sx1301-builder +FROM balenalib/raspberry-pi-debian:buster-build as lora-gateway-sx1301-builder ENV ROOT_DIR=/opt + +# Output built files to this location ENV OUTPUT_DIR="$ROOT_DIR/output" -# Overwirtes value in loragw_spi.native.c -# https://github.com/NebraLtd/lora_gateway/blob/971c52e3e0f953102c0b057c9fff9b1df8a84d66/libloragw/src/loragw_spi.native.c#L56 +# Used in libloragw/Makefile value and supplied to loragw_spi.native.c ENV SPI_SPEED=2000000 WORKDIR "$ROOT_DIR" @@ -16,4 +17,5 @@ WORKDIR "$ROOT_DIR" # Copy upstream source into expected location COPY . "$ROOT_DIR" +# Compile libloragw RUN . "$ROOT_DIR/compile_libloragw.sh" diff --git a/compile_libloragw.sh b/compile_libloragw.sh index d6436a3f..ed89c22a 100755 --- a/compile_libloragw.sh +++ b/compile_libloragw.sh @@ -12,11 +12,11 @@ compile_libloragw_for_spi_bus() { cd "$ROOT_DIR" cp -r "$ROOT_DIR/libloragw/" "$OUTPUT_DIR/$spi_bus" - echo "Finished building libloragw for sx1301 on $spi_bus in $ROOT_DIR" + echo "Finished building libloragw for sx1301 on $spi_bus in $OUTPUT_DIR" } compile_libloragw() { - echo "Compiling libloragw for sx1301 concentrator on all the necessary SPI buses in $ROOT_DIR" + echo "Compiling libloragw for sx1301 concentrator on all the necessary SPI buses in $OUTPUT_DIR" # Built outputs will be copied to this directory mkdir -p "$OUTPUT_DIR" diff --git a/libloragw/Makefile b/libloragw/Makefile index 53c33d90..0e28d5e1 100644 --- a/libloragw/Makefile +++ b/libloragw/Makefile @@ -10,7 +10,8 @@ CROSS_COMPILE ?= CC := $(CROSS_COMPILE)gcc AR := $(CROSS_COMPILE)ar -CFLAGS := -O2 -Wall -Wextra -std=c99 -Iinc -I. +# Modified to include SPI_DEV_PATH and SPI_SPEED macros +CFLAGS := -O2 -Wall -Wextra -std=c99 -Iinc -I. -D'SPI_DEV_PATH="${SPI_DEV_DIR}"' -D'SPI_SPEED=${SPI_SPEED}' OBJDIR = obj INCLUDES = $(wildcard inc/*.h) diff --git a/libloragw/src/loragw_spi.native.c b/libloragw/src/loragw_spi.native.c index c01ed1c1..dfb54639 100644 --- a/libloragw/src/loragw_spi.native.c +++ b/libloragw/src/loragw_spi.native.c @@ -53,8 +53,9 @@ Maintainer: Sylvain Miermont #define READ_ACCESS 0x00 #define WRITE_ACCESS 0x80 -#define SPI_SPEED 8000000 -#define SPI_DEV_PATH "/dev/spidev0.0" +// SPI_SPEED and SPI_DEV_PATH are intended to be defined as part of CFLAGS in the Makefile +// #define SPI_SPEED 8000000 +// #define SPI_DEV_PATH "/dev/spidev0.0" //#define SPI_DEV_PATH "/dev/spidev32766.0" /* -------------------------------------------------------------------------- */