diff --git a/Makefile b/Makefile index 7e18519..4f0fb69 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,38 @@ -SRC=$(wildcard src/*.c) -INCLUDE=$(wildcard src/include/*.h) -OBJ=$(patsubst src/%.c,build/%.rel,$(SRC)) +# Parameter for current board +BOARD?=galp3-c -all: build/ec.rom +# Set build directory +BUILD=build/$(BOARD) +# Default target - build the board's EC firmware +all: $(BUILD)/ec.rom + +# Target to remove build artifacts clean: rm -rf build -sim: build/ec.rom - cargo run \ - --release \ - --manifest-path ecsim/Cargo.toml \ - --no-default-features \ - -- $< +# Include common source +SRC=$(wildcard src/*.c) +INCLUDE=$(wildcard src/include/*.h) -build/ec.rom: build/ec.ihx - mkdir -p build - makebin -p < $< > $@ +# Include the board's source +BOARD_DIR=src/board/$(BOARD) +SRC+=$(wildcard $(BOARD_DIR)/*.c) +INCLUDE+=$(wildcard $(BOARD_DIR)/include/*.h) +include $(BOARD_DIR)/board.mk -build/ec.ihx: $(OBJ) - mkdir -p build - sdcc -mmcs51 -o $@ $^ +# The board will define the embedded controller +# Include the embedded controller's source +EC_DIR=src/ec/$(EC) +SRC+=$(wildcard $(EC_DIR)/*.c) +INCLUDE+=$(wildcard $(EC_DIR)/include/*.h) +include $(EC_DIR)/ec.mk -build/%.rel: src/%.c $(INCLUDE) - mkdir -p build - cd build && \ - sdcc -mmcs51 -c ../$< +# The EC will define the architecture +# Include the architecture's source +ARCH_DIR=src/arch/$(ARCH) +SRC+=$(wildcard $(ARCH_DIR)/*.c) +INCLUDE+=$(wildcard $(ARCH_DIR)/include/*.h) +include $(ARCH_DIR)/arch.mk + +# The architecture defines build targets, no more is required diff --git a/src/arch/8051/arch.mk b/src/arch/8051/arch.mk new file mode 100644 index 0000000..1f81633 --- /dev/null +++ b/src/arch/8051/arch.mk @@ -0,0 +1,25 @@ +CC=sdcc -mmcs51 +OBJ=$(patsubst src/%.c,$(BUILD)/%.rel,$(SRC)) + +# Run EC rom in simulator +sim: $(BUILD)/ec.rom + cargo run \ + --release \ + --manifest-path ecsim/Cargo.toml \ + --no-default-features \ + -- $< + +# Convert from Intel Hex format to binary +$(BUILD)/ec.rom: $(BUILD)/ec.ihx + @mkdir -p $(@D) + makebin -p < $< > $@ + +# Link object files into Intel Hex format +$(BUILD)/ec.ihx: $(OBJ) + @mkdir -p $(@D) + $(CC) -o $@ $^ + +# Compile C files into object files +$(BUILD)/%.rel: src/%.c $(INCLUDE) + @mkdir -p $(@D) + $(CC) -o $@ -c $< diff --git a/src/board/galp3-c/board.mk b/src/board/galp3-c/board.mk new file mode 100644 index 0000000..55b3b29 --- /dev/null +++ b/src/board/galp3-c/board.mk @@ -0,0 +1 @@ +EC=it8587e diff --git a/src/ec/it8587e/ec.mk b/src/ec/it8587e/ec.mk new file mode 100644 index 0000000..1aa8151 --- /dev/null +++ b/src/ec/it8587e/ec.mk @@ -0,0 +1 @@ +ARCH=8051