Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentDary committed Jan 26, 2024
0 parents commit f3a36e8
Show file tree
Hide file tree
Showing 30 changed files with 3,820 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
archives/
builds/
src/
tools/
releases/
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Open Firmware Dataset Builder (OFDB)

Copyright 2023-2024 Vincent Dary
238 changes: 238 additions & 0 deletions README.md

Large diffs are not rendered by default.

116 changes: 116 additions & 0 deletions builders/FRDM-K64F-MK64FN1M0VLL12-riot-os-demo-shell/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
################################################################################
#
# Copyright 2023-2024 Vincent Dary
#
# This file is part of open-firmware-dataset-builder (OFDB).
#
# open-firmware-dataset-builder is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# open-firmware-dataset-builder is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# open-firmware-dataset-builder. If not, see <https://www.gnu.org/licenses/>.
#
################################################################################
#
# firmware code:
# - https://github.com/RIOT-OS/RIOT
#
################################################################################

ROOT_DIR_NAME := $(notdir $(realpath $(dir $(lastword $(MAKEFILE_LIST)))))

include ../constant.mk

SRC := $(ENV_SRC_DIR)/$(ROOT_DIR_NAME)
BUILD := $(ENV_BUILDS_DIR)/$(ROOT_DIR_NAME)

OBJCOPY = $(TOOLCHAIN_ARM_GNU_13_2_REL1_OBJCOPY)
READELF := $(TOOLCHAIN_ARM_GNU_13_2_REL1_READELF)

GIT_TAG_RIOT_OS_RIOT := 2018.04
GIT_COMMIT_RIOT_OS_RIOT := 99b170d8e8788edc49aa23248effbaeb1a1183d5
TARGET := default
FW_ELF := $(BUILD)/$(TARGET).elf


.PHONY: all firmware_build firmware_metadata_gen clean_src clean release


all: firmware_build firmware_metadata_gen clean_src


release: all


firmware_build:
mkdir -p $(BUILD) $(SRC)

# Firmware source code bootstrap.
$(SCRIPT_BOOTSTRAP_GIT_ARCHIVE) \
$(ENV_ARCHIVES_DIR)/$(REPO_RIOT_OS_RIOT).tar.gz $(SRC) $(GIT_TAG_RIOT_OS_RIOT)

# Firmware build.
rm -rf $(SRC)/$(REPO_RIOT_OS_RIOT)/examples/default/bin
cd $(SRC)/$(REPO_RIOT_OS_RIOT)/examples/default \
&& $(MAKE) WERROR=0 BOARD=frdm-k64f PATH=$(TOOLCHAIN_ARM_GNU_13_2_REL1_PATH_BASE):$(PATH)
cp -v $(SRC)/$(REPO_RIOT_OS_RIOT)/examples/default/bin/frdm-k64f/$(TARGET).* $(BUILD)
$(OBJCOPY) -O binary $(BUILD)/$(TARGET).elf $(BUILD)/default.bin


firmware_metadata_gen: $(FW_ELF)
variant=$$($(READELF) -A $(FW_ELF) |tr -d ' '|grep -Po '(?<=Tag_CPU_arch:).*'); \
entry_point=$$($(READELF) -h $(FW_ELF) |grep 'Entry point address:' |grep -Po '0x[0-9a-fA-F]*'); \
blob_size=$$(stat --printf=%s $(BUILD)/$(TARGET).bin); \
blob_base_addr=0x$$($(READELF) -s $(FW_ELF) |grep '\.vector' |grep -Po '[0-9a-fA-F]{8}'); \
blob_endian=$$($(READELF) -h $(FW_ELF) |grep 'Data:' |grep -Po '(little|big) endian' |grep -Po '(little|big)'); \
blob_sha1=$$(sha1sum $(BUILD)/$(TARGET).bin |cut -d " " -f 1) \
; \
$(PYTHON) $(SCRIPT_FW_JSON_META_PY) \
firmware_load_meta \
--processor-id main \
--processor arm \
--processor-variant $$variant \
--processor-model MK64FN1M0VLL12 \
--entry-point $$entry_point \
--load $(TARGET).bin 0x0 $$blob_size $$blob_base_addr \
--out $(BUILD)/firmware_load_metadata.json \
; \
$(PYTHON) $(SCRIPT_FW_JSON_META_PY) \
firmware_build_meta \
--filename $(TARGET).bin \
--file-size $$blob_size \
--sha1 $$blob_sha1 \
--endian $$blob_endian \
--operating-system RIOT \
--compiler gcc \
--toolchain $(TOOLCHAIN_ARM_GNU_13_2_REL1) \
--processor arm \
--processor-variant $$variant \
--processor-model MK64FN1M0VLL12 \
--entry-point $$entry_point \
--src "$(REPO_RIOT_OS_RIOT_URL)" $(GIT_COMMIT_RIOT_OS_RIOT) \
--out $(BUILD)/$(TARGET).json

$(PYTHON) $(SCRIPT_FW_JSON_META_PY) \
firmware_all_meta \
--board frdm-64-MK64FN1M0VLL12 \
--load-meta-file $(BUILD)/firmware_load_metadata.json \
--firmware-build-meta-file $(BUILD)/$(TARGET).json \
--out $(BUILD)/firmware_metadata.json

rm -f $(BUILD)/firmware_load_metadata.json $(BUILD)/$(TARGET).json


clean_src:
rm -rf $(SRC)


clean:
rm -rf $(BUILD) $(SRC)
61 changes: 61 additions & 0 deletions builders/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
################################################################################
#
# Copyright 2023-2024 Vincent Dary
#
# This file is part of open-firmware-dataset-builder (OFDB).
#
# open-firmware-dataset-builder is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# open-firmware-dataset-builder is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# open-firmware-dataset-builder. If not, see <https://www.gnu.org/licenses/>.
#
################################################################################

RELEASE_BASE_DIR := ../releases
RELEASE_VER := 1.0.0
RELEASE_DIR_NAME := open-firmware-dataset-V$(RELEASE_VER)
RELEASE_DIR := $(RELEASE_BASE_DIR)/$(RELEASE_DIR_NAME)
RELEASE_ARCHIVE_NAME := $(RELEASE_DIR_NAME).tar.gz
RELEASE_NOTE_FILE := $(RELEASE_DIR)/README.txt
RELEASE_LICENCE := ../data/odf_cc_by-nc-nd_4.0_legalcode.txt
RELEASE_NOTE := ../data/ofd_release_notes.txt
RELEASE_VERSION_BANNER := "\n\nOpen Firmware Dataset (OFD) - version $(RELEASE_VER)"


SUB_DIRS := $(shell find . -type d -not -path ".")


all: $(SUB_DIRS)


clean: $(SUB_DIRS)


release: $(RELEASE_BASE_DIR)/$(RELEASE_ARCHIVE_NAME)


$(RELEASE_BASE_DIR)/$(RELEASE_ARCHIVE_NAME): $(SUB_DIRS)
rm -rf $(RELEASE_DIR)
mkdir $(RELEASE_DIR)
mv ../builds $(RELEASE_DIR)
mkdir ../builds
echo -e $(RELEASE_VERSION_BANNER) > $(RELEASE_NOTE_FILE)
cat $(RELEASE_NOTE) >> $(RELEASE_NOTE_FILE)
cp -v $(RELEASE_LICENCE) $(RELEASE_DIR)/License
cd $(RELEASE_BASE_DIR) && tar -czf $(RELEASE_ARCHIVE_NAME) $(RELEASE_DIR_NAME)
cd $(RELEASE_BASE_DIR) && rm -rf $(RELEASE_DIR_NAME)


$(SUB_DIRS):
$(MAKE) -C $@ $(MAKECMDGOALS)


.PHONY: all clean $(SUB_DIRS)
115 changes: 115 additions & 0 deletions builders/STM32F4DISCOVERY-STM32F407VG-grbl-stm32f4/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
################################################################################
#
# Copyright 2023-2024 Vincent Dary
#
# This file is part of open-firmware-dataset-builder (OFDB).
#
# open-firmware-dataset-builder is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# open-firmware-dataset-builder is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# open-firmware-dataset-builder. If not, see <https://www.gnu.org/licenses/>.
#
################################################################################
#
# firmware code:
# - https://github.com/deadsy/grbl_stm32f4
#
################################################################################

ROOT_DIR_NAME := $(notdir $(realpath $(dir $(lastword $(MAKEFILE_LIST)))))

include ../constant.mk

SRC := $(ENV_SRC_DIR)/$(ROOT_DIR_NAME)
BUILD := $(ENV_BUILDS_DIR)/$(ROOT_DIR_NAME)

READELF := $(TOOLCHAIN_ARM_GNU_13_2_REL1_READELF)

GIT_COMMIT_DEADSY_GRBL_STM32F4 := a5246c935380178df1b362e61eefd32acd6c8024
TARGET := grbl_stm32f4
FW_ELF := $(BUILD)/$(TARGET).elf


.PHONY: all firmware_build firmware_metadata_gen clean_src clean release


all: firmware_build firmware_metadata_gen clean_src


release: all


firmware_build:
mkdir -p $(BUILD) $(SRC)

$(SCRIPT_BOOTSTRAP_GIT_ARCHIVE) \
$(ENV_ARCHIVES_DIR)/$(REPO_DEADSY_GRBL_STM32F4).tar.gz $(SRC) \
$(GIT_COMMIT_DEADSY_GRBL_STM32F4)

cd $(SRC)/$(REPO_DEADSY_GRBL_STM32F4) \
&& awk 'NR==3 {$$0="XTOOLS_DIR = ../$(TOOLCHAIN_ARM_GNU_13_2_REL1_PATH)"} { print }' Makefile \
> Makefile_PATCH.mk

cd $(SRC)/$(REPO_DEADSY_GRBL_STM32F4) && make -f Makefile_PATCH.mk

cp -v $(SRC)/$(REPO_DEADSY_GRBL_STM32F4)/$(TARGET)* $(BUILD)
mv $(BUILD)/$(TARGET) $(FW_ELF)


firmware_metadata_gen: $(FW_ELF)
variant=$$($(READELF) -A $(FW_ELF) |tr -d ' '|grep -Po '(?<=Tag_CPU_arch:).*'); \
entry_point=$$($(READELF) -h $(FW_ELF) |grep 'Entry point address:' |grep -Po '0x[0-9a-fA-F]*'); \
blob_size=$$(stat --printf=%s $(BUILD)/$(TARGET).bin); \
blob_base_addr=0x$$($(READELF) -s $(FW_ELF) |grep '\.isr_vector' |grep -Po '[0-9a-fA-F]{8}'); \
blob_endian=$$($(READELF) -h $(FW_ELF) |grep 'Data:' |grep -Po '(little|big) endian' |grep -Po '(little|big)'); \
blob_sha1=$$(sha1sum $(BUILD)/$(TARGET).bin |cut -d " " -f 1) \
; \
$(PYTHON) $(SCRIPT_FW_JSON_META_PY) \
firmware_load_meta \
--processor-id main \
--processor arm \
--processor-variant $$variant \
--processor-model STM32F407VG \
--entry-point $$entry_point \
--load $(TARGET).bin 0x0 $$blob_size $$blob_base_addr \
--out $(BUILD)/firmware_load_metadata.json \
; \
$(PYTHON) $(SCRIPT_FW_JSON_META_PY) \
firmware_build_meta \
--filename $(TARGET).bin \
--file-size $$blob_size \
--sha1 $$blob_sha1 \
--endian $$blob_endian \
--compiler gcc \
--toolchain $(TOOLCHAIN_ARM_GNU_13_2_REL1_READELF) \
--processor arm \
--processor-variant $$variant \
--processor-model STM32F407VG \
--entry-point $$entry_point \
--src "$(REPO_DEADSY_GRBL_STM32F4_URL)" $(GIT_COMMIT_DEADSY_GRBL_STM32F4) \
--out $(BUILD)/$(TARGET).json

$(PYTHON) $(SCRIPT_FW_JSON_META_PY) \
firmware_all_meta \
--board STM32F4DISCOVERY \
--load-meta-file $(BUILD)/firmware_load_metadata.json \
--firmware-build-meta-file $(BUILD)/$(TARGET).json \
--out $(BUILD)/firmware_metadata.json

rm -f $(BUILD)/firmware_load_metadata.json $(BUILD)/$(TARGET).json


clean_src:
rm -rf $(SRC)


clean:
rm -rf $(BUILD) $(SRC)
Loading

0 comments on commit f3a36e8

Please sign in to comment.