# # Copyright (C) 2023 OpenWrt.org # # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. # include $(TOPDIR)/rules.mk PKG_NAME:=mcu-firmware PKG_VERSION:=2023-03-05 PKG_RELEASE:=1 PKG_MAINTAINER:=Piotr Dymacz include $(INCLUDE_DIR)/package.mk define Package/mcu-fw-default CATEGORY:=Firmware SUBMENU:=MCU firmware SECTION:=firmware TITLE:=MCU firmware endef # Zephyr versions # 4 fields separated with underscore: # version-name_git-sha_pipeline-id_sha256-of-package ZEPHYR_VERSIONS := \ zephyr-v3.3.x_7055d10e538e_3877473859_321a0daf6328698a913c6504d19aa85a5170dfce6039b86d31d2e9162d34af7c ZEPHYR_FW_CI_URL := https://gitlab.com/pepe2k/zephyr/-/jobs/ # Zephyr 'hello_world' targets ZEPHYR_HELLO_WORLD_TARGETS := \ cig_wf196_nrf52833 \ edgecore_eap102_nrf52840 \ nrf52840dongle_nrf52840 # Zephyr 'hci_uart' targets ZEPHYR_HCI_UART_TARGETS:= \ cig_wf196_nrf52833 \ edgecore_eap102_nrf52840 \ nrf52840dongle_nrf52840 # Zephyr 'hci_usb' targets ZEPHYR_HCI_USB_TARGETS := \ edgecore_eap102_nrf52840 \ nrf52840dongle_nrf52840 word-underscore = $(word $2,$(subst _, ,$1)) define Download/zephyr-fw URL:=$(ZEPHYR_FW_CI_URL)$(call word-underscore,$(2),3)/ URL_FILE:=artifacts/download?file_type=archive FILE:=$(call word-underscore,$(2),1)-$(call word-underscore,$(2),2).zip HASH:=$(call word-underscore,$(2),4) endef $(foreach FW,$(ZEPHYR_VERSIONS),$(eval $(call Download,zephyr-fw,$(FW)))) # $(1) version (e.g zephyr-v3.3.x) # $(2) firmware name (e.g. hci_usb) # $(3) target/board name (e.g. nrf52840dongle_nrf52840) define zephyr-fw define Package/$(1)-$(2)-$(3) $(call Package/mcu-fw-default) DEPENDS:=+mcu TITLE:=Zephyr '$(2)' endef define Package/$(1)-$(2)-$(3)/description Zephyr '$(1)' based firmware '$(2)' for '$(3)' board endef define Package/$(1)-$(2)-$(3)/install $(INSTALL_DIR) $$(1)/lib/firmware/mcu/$(3)/$(1)__$(2) $(INSTALL_DATA) $(PKG_BUILD_DIR)/$(1)/$(3)/$(1)__$(2)/*.bin \ $$(1)/lib/firmware/mcu/$(3)/$(1)__$(2)/ endef endef define zephyr-fw-unzip mkdir -p $(PKG_BUILD_DIR)/$(call word-underscore,$(1),1); \ unzip -q -d $(PKG_BUILD_DIR)/$(call word-underscore,$(1),1) \ $(DL_DIR)/$(call word-underscore,$(1),1)-$(call word-underscore,$(1),2).zip; \ for fw in $(PKG_BUILD_DIR)/$(call word-underscore,$(1),1)/*.tar.gz; do \ $(TAR) -C $(PKG_BUILD_DIR)/$(call word-underscore,$(1),1) --one-top-level -xzf $$$$fw; \ rm -rf $$$$fw; \ done; endef define Build/Prepare $(foreach FW,$(ZEPHYR_VERSIONS),$(call zephyr-fw-unzip,$(FW))) endef define Build/Compile endef $(foreach VER,$(ZEPHYR_VERSIONS),\ $(foreach TARGET,$(ZEPHYR_HELLO_WORLD_TARGETS),\ $(eval $(call zephyr-fw,$(call word-underscore,$(VER),1),hello_world,$(TARGET))))) $(foreach VER,$(ZEPHYR_VERSIONS),\ $(foreach TARGET,$(ZEPHYR_HCI_UART_TARGETS),\ $(eval $(call zephyr-fw,$(call word-underscore,$(VER),1),hci_uart,$(TARGET))))) $(foreach VER,$(ZEPHYR_VERSIONS),\ $(foreach TARGET,$(ZEPHYR_HCI_USB_TARGETS),\ $(eval $(call zephyr-fw,$(call word-underscore,$(VER),1),hci_usb,$(TARGET))))) $(foreach VER,$(ZEPHYR_VERSIONS),\ $(foreach TARGET,$(ZEPHYR_HELLO_WORLD_TARGETS),\ $(eval $(call BuildPackage,$(call word-underscore,$(VER),1)-hello_world-$(TARGET))))) $(foreach VER,$(ZEPHYR_VERSIONS),\ $(foreach TARGET,$(ZEPHYR_HCI_UART_TARGETS),\ $(eval $(call BuildPackage,$(call word-underscore,$(VER),1)-hci_uart-$(TARGET))))) $(foreach VER,$(ZEPHYR_VERSIONS),\ $(foreach TARGET,$(ZEPHYR_HCI_USB_TARGETS),\ $(eval $(call BuildPackage,$(call word-underscore,$(VER),1)-hci_usb-$(TARGET)))))