b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | include $(INCLUDE_DIR)/prereq.mk |
| 2 | |
| 3 | PKG_NAME ?= u-boot |
| 4 | |
| 5 | ifndef PKG_SOURCE_PROTO |
| 6 | PKG_SOURCE = $(PKG_NAME)-$(PKG_VERSION).tar.bz2 |
| 7 | PKG_SOURCE_URL = \ |
| 8 | https://mirror.cyberbits.eu/u-boot \ |
| 9 | https://ftp.denx.de/pub/u-boot \ |
| 10 | ftp://ftp.denx.de/pub/u-boot |
| 11 | endif |
| 12 | |
| 13 | PKG_BUILD_DIR = $(BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION) |
| 14 | |
| 15 | PKG_TARGETS := bin |
| 16 | PKG_FLAGS:=nonshared |
| 17 | |
| 18 | PKG_LICENSE:=GPL-2.0 GPL-2.0+ |
| 19 | PKG_LICENSE_FILES:=Licenses/README |
| 20 | |
| 21 | PKG_BUILD_PARALLEL ?= 1 |
| 22 | |
| 23 | ifdef UBOOT_USE_BINMAN |
| 24 | $(eval $(call TestHostCommand,python3-pyelftools, \ |
| 25 | Please install the Python3 elftools module, \ |
| 26 | $(STAGING_DIR_HOST)/bin/python3 -c 'import elftools')) |
| 27 | endif |
| 28 | |
| 29 | ifdef UBOOT_USE_INTREE_DTC |
| 30 | $(eval $(call TestHostCommand,python3-dev, \ |
| 31 | Please install the python3-dev package, \ |
| 32 | python3.11-config --includes 2>&1 | grep 'python3', \ |
| 33 | python3.10-config --includes 2>&1 | grep 'python3', \ |
| 34 | python3.9-config --includes 2>&1 | grep 'python3', \ |
| 35 | python3.8-config --includes 2>&1 | grep 'python3', \ |
| 36 | python3.7-config --includes 2>&1 | grep 'python3', \ |
| 37 | python3-config --includes 2>&1 | grep -E 'python3\.([7-9]|[0-9][0-9])\.?')) |
| 38 | |
| 39 | $(eval $(call TestHostCommand,python3-setuptools, \ |
| 40 | Please install the Python3 setuptools module, \ |
| 41 | $(STAGING_DIR_HOST)/bin/python3 -c 'import setuptools')) |
| 42 | |
| 43 | $(eval $(call TestHostCommand,swig, \ |
| 44 | Please install the swig package, \ |
| 45 | swig -version)) |
| 46 | endif |
| 47 | |
| 48 | export GCC_HONOUR_COPTS=s |
| 49 | |
| 50 | define Package/u-boot/install/default |
| 51 | $(CP) $(patsubst %,$(PKG_BUILD_DIR)/%,$(UBOOT_IMAGE)) $(1)/ |
| 52 | endef |
| 53 | |
| 54 | Package/u-boot/install = $(Package/u-boot/install/default) |
| 55 | |
| 56 | define U-Boot/Init |
| 57 | BUILD_TARGET:= |
| 58 | BUILD_SUBTARGET:= |
| 59 | BUILD_DEVICES:= |
| 60 | NAME:= |
| 61 | DEPENDS:= |
| 62 | HIDDEN:= |
| 63 | DEFAULT:= |
| 64 | VARIANT:=$(1) |
| 65 | UBOOT_CONFIG:=$(1) |
| 66 | UBOOT_IMAGE:=u-boot.bin |
| 67 | endef |
| 68 | |
| 69 | TARGET_DEP = TARGET_$(BUILD_TARGET)$(if $(BUILD_SUBTARGET),_$(BUILD_SUBTARGET)) |
| 70 | |
| 71 | UBOOT_MAKE_FLAGS = \ |
| 72 | PATH=$(STAGING_DIR_HOST)/bin:$(PATH) \ |
| 73 | HOSTCC="$(HOSTCC)" \ |
| 74 | HOSTCFLAGS="$(HOST_CFLAGS) $(HOST_CPPFLAGS) -std=gnu11" \ |
| 75 | HOSTLDFLAGS="$(HOST_LDFLAGS)" \ |
| 76 | LOCALVERSION="-OpenWrt-$(REVISION)" \ |
| 77 | STAGING_PREFIX="$(STAGING_DIR_HOST)" \ |
| 78 | PKG_CONFIG_PATH="$(STAGING_DIR_HOST)/lib/pkgconfig" \ |
| 79 | PKG_CONFIG_LIBDIR="$(STAGING_DIR_HOST)/lib/pkgconfig" \ |
| 80 | PKG_CONFIG_EXTRAARGS="--static" \ |
| 81 | $(if $(findstring c,$(OPENWRT_VERBOSE)),V=1,V='') |
| 82 | |
| 83 | define Build/U-Boot/Target |
| 84 | $(eval $(call U-Boot/Init,$(1))) |
| 85 | $(eval $(call U-Boot/Default,$(1))) |
| 86 | $(eval $(call U-Boot/$(1),$(1))) |
| 87 | |
| 88 | define Package/u-boot-$(1) |
| 89 | SECTION:=boot |
| 90 | CATEGORY:=Boot Loaders |
| 91 | TITLE:=U-Boot for $(NAME) |
| 92 | VARIANT:=$(VARIANT) |
| 93 | DEPENDS:=@!IN_SDK $(DEPENDS) |
| 94 | HIDDEN:=$(HIDDEN) |
| 95 | ifneq ($(BUILD_TARGET),) |
| 96 | DEPENDS += @$(TARGET_DEP) |
| 97 | ifneq ($(BUILD_DEVICES),) |
| 98 | DEFAULT := y if ($(TARGET_DEP)_Default \ |
| 99 | $(patsubst %,|| $(TARGET_DEP)_DEVICE_%,$(BUILD_DEVICES)) \ |
| 100 | $(patsubst %,|| $(patsubst TARGET_%,TARGET_DEVICE_%,$(TARGET_DEP))_DEVICE_%,$(BUILD_DEVICES))) |
| 101 | endif |
| 102 | endif |
| 103 | $(if $(DEFAULT),DEFAULT:=$(DEFAULT)) |
| 104 | URL:=http://www.denx.de/wiki/U-Boot |
| 105 | endef |
| 106 | |
| 107 | define Package/u-boot-$(1)/install |
| 108 | $$(Package/u-boot/install) |
| 109 | endef |
| 110 | endef |
| 111 | |
| 112 | define Build/Configure/U-Boot |
| 113 | +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) CROSS_COMPILE=$(TARGET_CROSS) $(UBOOT_CONFIGURE_VARS) $(UBOOT_CONFIG)_config |
| 114 | $(if $(strip $(UBOOT_CUSTOMIZE_CONFIG)), |
| 115 | $(PKG_BUILD_DIR)/scripts/config --file $(PKG_BUILD_DIR)/.config $(UBOOT_CUSTOMIZE_CONFIG) |
| 116 | +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) CROSS_COMPILE=$(TARGET_CROSS) $(UBOOT_CONFIGURE_VARS) oldconfig) |
| 117 | endef |
| 118 | |
| 119 | ifndef UBOOT_USE_INTREE_DTC |
| 120 | DTC=$(wildcard $(LINUX_DIR)/scripts/dtc/dtc) |
| 121 | endif |
| 122 | |
| 123 | define Build/Compile/U-Boot |
| 124 | +$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \ |
| 125 | CROSS_COMPILE=$(TARGET_CROSS) \ |
| 126 | $(if $(DTC),DTC="$(DTC)") \ |
| 127 | $(UBOOT_MAKE_FLAGS) |
| 128 | endef |
| 129 | |
| 130 | define BuildPackage/U-Boot/Defaults |
| 131 | Build/Configure/Default = $$$$(Build/Configure/U-Boot) |
| 132 | Build/Compile/Default = $$$$(Build/Compile/U-Boot) |
| 133 | endef |
| 134 | |
| 135 | define BuildPackage/U-Boot |
| 136 | $(eval $(call BuildPackage/U-Boot/Defaults)) |
| 137 | $(foreach type,$(if $(DUMP),$(UBOOT_TARGETS),$(BUILD_VARIANT)), \ |
| 138 | $(eval $(call Build/U-Boot/Target,$(type))) |
| 139 | ) |
| 140 | $(eval $(call Build/DefaultTargets)) |
| 141 | $(foreach type,$(if $(DUMP),$(UBOOT_TARGETS),$(BUILD_VARIANT)), \ |
| 142 | $(call BuildPackage,u-boot-$(type)) |
| 143 | ) |
| 144 | endef |