2009-08-30 19:15:51 +00:00
|
|
|
#
|
2011-10-31 09:23:44 +00:00
|
|
|
# Copyright (C) 2008-2011 OpenWrt.org
|
2009-08-30 19:15:51 +00:00
|
|
|
#
|
|
|
|
# This is free software, licensed under the GNU General Public License v2.
|
|
|
|
# See /LICENSE for more information.
|
|
|
|
#
|
|
|
|
include $(TOPDIR)/rules.mk
|
|
|
|
include $(INCLUDE_DIR)/image.mk
|
|
|
|
|
|
|
|
define imgname
|
2010-07-31 11:42:17 +00:00
|
|
|
$(BIN_DIR)/$(IMG_PREFIX)-$(2)-$(1)
|
2009-08-30 19:15:51 +00:00
|
|
|
endef
|
|
|
|
|
2012-02-23 19:58:03 +00:00
|
|
|
define sysupname
|
|
|
|
$(call imgname,$(1),$(2))-sysupgrade.bin
|
|
|
|
endef
|
|
|
|
|
2010-04-12 23:15:56 +00:00
|
|
|
VMLINUX:=$(IMG_PREFIX)-vmlinux
|
|
|
|
UIMAGE:=$(IMG_PREFIX)-uImage
|
2013-04-03 09:59:51 +00:00
|
|
|
|
|
|
|
define Image/Build/Initramfs
|
|
|
|
$(call Image/Build/Profile/$(PROFILE),initramfs)
|
|
|
|
endef
|
2009-08-30 19:15:51 +00:00
|
|
|
|
2016-09-13 17:23:52 +00:00
|
|
|
DEVICE_VARS += DTS IMAGE_SIZE
|
2015-01-10 15:26:53 +00:00
|
|
|
|
2015-01-10 15:26:38 +00:00
|
|
|
loadaddr-y := 0x80000000
|
|
|
|
loadaddr-$(CONFIG_TARGET_ramips_rt288x) := 0x88000000
|
|
|
|
loadaddr-$(CONFIG_TARGET_ramips_mt7621) := 0x80001000
|
2009-08-30 19:15:51 +00:00
|
|
|
|
2015-01-10 15:26:53 +00:00
|
|
|
KERNEL_LOADADDR := $(loadaddr-y)
|
|
|
|
|
|
|
|
KERNEL_DTB = kernel-bin | patch-dtb | lzma
|
|
|
|
define Device/Default
|
2016-04-09 10:24:40 +00:00
|
|
|
PROFILES = Default $$(DTS)
|
2016-01-06 18:39:06 +00:00
|
|
|
KERNEL_DEPENDS = $$(wildcard ../dts/$$(DTS).dts)
|
2015-01-10 15:26:53 +00:00
|
|
|
KERNEL := $(KERNEL_DTB) | uImage lzma
|
|
|
|
IMAGES := sysupgrade.bin
|
|
|
|
IMAGE_SIZE := $(ralink_default_fw_size_8M)
|
2016-11-17 12:02:26 +00:00
|
|
|
SUPPORTED_DEVICES = $(1)
|
|
|
|
sysupgrade_bin := append-kernel | append-rootfs | pad-rootfs
|
|
|
|
IMAGE/sysupgrade.bin := append-kernel | append-rootfs | pad-rootfs | append-metadata | check-size $$$$(IMAGE_SIZE)
|
2015-01-10 15:26:53 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
define Build/patch-dtb
|
2015-12-10 12:39:32 +00:00
|
|
|
$(call Image/BuildDTB,../dts/$(DTS).dts,$@.dtb)
|
2015-01-10 15:26:53 +00:00
|
|
|
$(STAGING_DIR_HOST)/bin/patch-dtb $@ $@.dtb
|
|
|
|
endef
|
|
|
|
|
|
|
|
define Build/trx
|
|
|
|
$(STAGING_DIR_HOST)/bin/trx \
|
|
|
|
-o $@ \
|
|
|
|
-m $(IMAGE_SIZE) \
|
2016-07-30 12:19:11 +00:00
|
|
|
-f $(IMAGE_KERNEL) \
|
|
|
|
-a 4 -f $(IMAGE_ROOTFS)
|
2015-01-10 15:26:53 +00:00
|
|
|
endef
|
|
|
|
|
2015-01-17 21:20:05 +00:00
|
|
|
define Build/relocate-kernel
|
|
|
|
( \
|
2015-05-29 11:28:10 +00:00
|
|
|
dd if=$(KDIR)/loader.bin bs=32 conv=sync && \
|
2015-01-17 21:20:05 +00:00
|
|
|
perl -e '@s = stat("$@"); print pack("V", @s[7])' && \
|
|
|
|
cat $@ \
|
|
|
|
) > $@.new
|
|
|
|
mv $@.new $@
|
|
|
|
endef
|
|
|
|
|
2012-08-17 17:56:07 +00:00
|
|
|
define MkCombineduImage
|
|
|
|
$(call PatchKernelLzma,$(2),$(3))
|
|
|
|
if [ `stat -c%s "$(KDIR)/vmlinux-$(2).bin.lzma"` -gt `expr $(4) - 64` ]; then \
|
2013-02-21 11:45:33 +00:00
|
|
|
echo "Warning: $(KDIR)/vmlinux-$(2).bin.lzma is too big" >&2; \
|
2012-08-17 17:56:07 +00:00
|
|
|
else if [ `stat -c%s "$(KDIR)/root.$(1)"` -gt $(5) ]; then \
|
2013-02-21 11:45:33 +00:00
|
|
|
echo "Warning: $(KDIR)/root.$(1) is too big" >&2; \
|
2012-08-17 17:56:07 +00:00
|
|
|
else \
|
|
|
|
( dd if=$(KDIR)/vmlinux-$(2).bin.lzma bs=`expr $(4) - 64` conv=sync ; dd if=$(KDIR)/root.$(1) ) > $(KDIR)/vmlinux-$(2).bin.lzma.combined ; \
|
|
|
|
fi ; fi
|
|
|
|
$(call MkImage,lzma,$(KDIR)/vmlinux-$(2).bin.lzma.combined,$(call sysupname,$(1),$(2)),$(6))
|
|
|
|
endef
|
|
|
|
|
2016-08-19 23:17:16 +00:00
|
|
|
define Build/umedia-header
|
|
|
|
fix-u-media-header -T 0x46 -B $(1) -i $@ -o $@.new && mv $@.new $@
|
|
|
|
endef
|
|
|
|
|
2016-09-27 05:38:08 +00:00
|
|
|
define Build/edimax-header
|
|
|
|
$(STAGING_DIR_HOST)/bin/mkedimaximg -i $@ -o $@.new $(1)
|
|
|
|
@mv $@.new $@
|
|
|
|
endef
|
|
|
|
|
2016-08-17 05:49:34 +00:00
|
|
|
define Build/senao-header
|
|
|
|
$(STAGING_DIR_HOST)/bin/mksenaofw $(1) -e $@ -o $@.new
|
|
|
|
mv $@.new $@
|
|
|
|
endef
|
|
|
|
|
2016-09-03 07:43:31 +00:00
|
|
|
define Build/seama
|
|
|
|
$(STAGING_DIR_HOST)/bin/seama -i $@ $(1)
|
|
|
|
mv $@.seama $@
|
|
|
|
endef
|
|
|
|
|
|
|
|
define Build/seama-seal
|
|
|
|
$(call Build/seama,-s $@.seama $(1))
|
|
|
|
endef
|
|
|
|
|
2013-04-03 09:59:51 +00:00
|
|
|
#
|
|
|
|
# The real magic happens inside these templates
|
|
|
|
#
|
2014-10-20 06:29:51 +00:00
|
|
|
# $(1), compression method
|
|
|
|
# $(2), filename of image data
|
|
|
|
# $(3), output filename
|
2013-04-03 09:59:51 +00:00
|
|
|
define MkImage
|
|
|
|
$(eval imagename=$(if $(4),$(4),MIPS OpenWrt Linux-$(LINUX_VERSION)))
|
2015-01-10 15:26:38 +00:00
|
|
|
-mkimage -A mips -O linux -T kernel -C $(1) -a $(loadaddr-y) -e $(loadaddr-y) \
|
2013-04-03 09:59:51 +00:00
|
|
|
-n "$(imagename)" \
|
|
|
|
-d $(2) $(3)
|
2012-12-10 14:13:01 +00:00
|
|
|
endef
|
|
|
|
|
2013-04-03 09:59:51 +00:00
|
|
|
define CompressLzma
|
|
|
|
$(STAGING_DIR_HOST)/bin/lzma e $(1) -lc1 -lp2 -pb2 $(2)
|
2012-12-10 14:13:01 +00:00
|
|
|
endef
|
|
|
|
|
2013-04-03 09:59:51 +00:00
|
|
|
define MkImageSysupgrade/squashfs
|
|
|
|
$(eval output_name=$(IMG_PREFIX)-$(2)-$(1)-$(if $(4),$(4),sysupgrade).bin)
|
|
|
|
cat $(KDIR)/vmlinux-$(2).uImage $(KDIR)/root.$(1) > $(KDIR)/$(output_name)
|
|
|
|
$(call prepare_generic_squashfs,$(KDIR)/$(output_name))
|
|
|
|
if [ `stat -c%s "$(KDIR)/$(output_name)"` -gt $(3) ]; then \
|
|
|
|
echo "Warning: $(KDIR)/$(output_name) is too big" >&2; \
|
|
|
|
else \
|
|
|
|
$(CP) $(KDIR)/$(output_name) $(BIN_DIR)/$(output_name); \
|
2012-02-23 19:58:03 +00:00
|
|
|
fi
|
2011-07-06 08:04:52 +00:00
|
|
|
endef
|
|
|
|
|
2014-10-20 06:29:51 +00:00
|
|
|
# $(1), lowercase board name like "mt7620a_v22sg"
|
|
|
|
# $(2), DTS filename without .dts extension
|
|
|
|
# $(3), optional filename suffix, e.g. "-initramfs"
|
2013-04-03 09:59:51 +00:00
|
|
|
define PatchKernelLzmaDtb
|
2013-06-29 08:41:03 +00:00
|
|
|
cp $(KDIR)/vmlinux$(3) $(KDIR)/vmlinux-$(1)$(3)
|
2016-05-10 12:42:50 +00:00
|
|
|
$(call Image/BuildDTB,../dts/$(2).dts,$(KDIR)/$(2).dtb)
|
2013-06-29 08:41:03 +00:00
|
|
|
$(STAGING_DIR_HOST)/bin/patch-dtb $(KDIR)/vmlinux-$(1)$(3) $(KDIR)/$(2).dtb
|
|
|
|
$(call CompressLzma,$(KDIR)/vmlinux-$(1)$(3),$(KDIR)/vmlinux-$(1)$(3).bin.lzma)
|
2012-08-17 17:56:05 +00:00
|
|
|
endef
|
|
|
|
|
2014-10-20 06:29:51 +00:00
|
|
|
# $(1), lowercase board name
|
|
|
|
# $(2), DTS filename without .dts extension
|
|
|
|
# $(3), ih_name field of uImage header
|
|
|
|
# $(4), optional filename suffix, e.g. "-initramfs"
|
2013-04-03 09:59:51 +00:00
|
|
|
define MkImageLzmaDtb
|
2013-06-29 08:41:03 +00:00
|
|
|
$(call PatchKernelLzmaDtb,$(1),$(2),$(4))
|
|
|
|
$(call MkImage,lzma,$(KDIR)/vmlinux-$(1)$(4).bin.lzma,$(KDIR)/vmlinux-$(1)$(4).uImage,$(3))
|
2012-07-24 20:38:43 +00:00
|
|
|
endef
|
|
|
|
|
2014-10-20 06:29:51 +00:00
|
|
|
# $(1), Rootfs type, e.g. squashfs
|
|
|
|
# $(2), lowercase board name
|
|
|
|
# $(3), DTS filename without .dts extension
|
|
|
|
# $(4), maximum size of sysupgrade image
|
|
|
|
# $(5), uImage header's ih_name field
|
2013-04-03 09:59:51 +00:00
|
|
|
define BuildFirmware/OF
|
|
|
|
$(call MkImageLzmaDtb,$(2),$(3),$(5))
|
|
|
|
$(call MkImageSysupgrade/$(1),$(1),$(2),$(4),$(6))
|
2012-07-24 20:38:43 +00:00
|
|
|
endef
|
|
|
|
|
2014-10-20 06:29:51 +00:00
|
|
|
# $(1), squashfs/initramfs
|
|
|
|
# $(2), lowercase board name
|
|
|
|
# $(3), DTS filename without .dts extension
|
|
|
|
# $(4), ih_name field of uImage header
|
2013-04-03 09:59:51 +00:00
|
|
|
define BuildFirmware/OF/initramfs
|
2013-06-29 08:41:03 +00:00
|
|
|
$(call MkImageLzmaDtb,$(2),$(3),$(4),-initramfs)
|
|
|
|
$(CP) $(KDIR)/vmlinux-$(2)-initramfs.uImage $(call imgname,$(1),$(2))-uImage.bin
|
2012-08-12 12:48:24 +00:00
|
|
|
endef
|
|
|
|
|
2013-04-03 09:59:51 +00:00
|
|
|
# Build images for default ralink layout for 4MB flash
|
|
|
|
# kernel + roots = 0x3b0000
|
|
|
|
# $(1) = squashfs/initramfs
|
|
|
|
# $(2) = lowercase board name
|
|
|
|
# $(3) = dts file
|
|
|
|
ralink_default_fw_size_4M=3866624
|
2014-01-12 12:07:40 +00:00
|
|
|
BuildFirmware/Default4M/squashfs=$(call BuildFirmware/OF,$(1),$(2),$(3),$(ralink_default_fw_size_4M),$(4))
|
|
|
|
BuildFirmware/Default4M/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3),$(4))
|
2013-04-03 09:59:51 +00:00
|
|
|
|
|
|
|
# Build images for default ralink layout for 8MB flash
|
|
|
|
# kernel + roots = 0x7b0000
|
|
|
|
# $(1) = squashfs/initramfs
|
|
|
|
# $(2) = lowercase board name
|
|
|
|
# $(3) = dts file
|
2014-10-20 06:29:51 +00:00
|
|
|
# $(4) = uImage header name field
|
2013-04-03 09:59:51 +00:00
|
|
|
ralink_default_fw_size_8M=8060928
|
2013-06-10 08:24:56 +00:00
|
|
|
BuildFirmware/Default8M/squashfs=$(call BuildFirmware/OF,$(1),$(2),$(3),$(ralink_default_fw_size_8M),$(4))
|
|
|
|
BuildFirmware/Default8M/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3),$(4))
|
2013-04-03 09:59:51 +00:00
|
|
|
|
2013-07-25 16:01:58 +00:00
|
|
|
ralink_default_fw_size_16M=16121856
|
2013-07-22 15:36:39 +00:00
|
|
|
BuildFirmware/Default16M/squashfs=$(call BuildFirmware/OF,$(1),$(2),$(3),$(ralink_default_fw_size_16M),$(4))
|
|
|
|
BuildFirmware/Default16M/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3),$(4))
|
|
|
|
|
2015-10-19 10:07:38 +00:00
|
|
|
ralink_default_fw_size_32M=33226752
|
|
|
|
BuildFirmware/Default32M/squashfs=$(call BuildFirmware/OF,$(1),$(2),$(3),$(ralink_default_fw_size_32M),$(4))
|
|
|
|
BuildFirmware/Default32M/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3),$(4))
|
|
|
|
|
2013-04-03 09:59:51 +00:00
|
|
|
# Build images for a custom sized flash layout
|
|
|
|
# $(1) = squashfs/initramfs
|
|
|
|
# $(2) = lowercase board name
|
|
|
|
# $(3) = dts file
|
|
|
|
# $(4) = kernel + rootfs size
|
|
|
|
BuildFirmware/CustomFlash/squashfs=$(call BuildFirmware/OF,$(1),$(2),$(3),$(4),$(5),$(6))
|
|
|
|
BuildFirmware/CustomFlash/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3))
|
|
|
|
|
2016-04-01 07:11:48 +00:00
|
|
|
# Some boards need a special header inside the uImage to make them bootable
|
|
|
|
define BuildFirmware/CustomFlashFactory/squashfs
|
|
|
|
$(call BuildFirmware/CustomFlash/$(1),$(1),$(2),$(3),$(4))
|
|
|
|
$(call BuildFirmware/CustomFlash/$(1),$(1),$(2),$(3),$(4),$(5),$(6))
|
|
|
|
endef
|
|
|
|
BuildFirmware/CustomFlashFactory/initramfs=$(call BuildFirmware/OF/initramfs,$(1),$(2),$(3))
|
|
|
|
|
2013-04-03 09:59:51 +00:00
|
|
|
# wrappers for boards that have 4MB and 8MB versions
|
|
|
|
define BuildFirmware/DefaultDualSize/squashfs
|
|
|
|
$(call BuildFirmware/Default4M/$(1),$(1),$(2)-4M,$(3)-4M)
|
|
|
|
$(call BuildFirmware/Default8M/$(1),$(1),$(2)-8M,$(3)-8M)
|
|
|
|
endef
|
|
|
|
define BuildFirmware/DefaultDualSize/initramfs
|
|
|
|
$(call BuildFirmware/OF/initramfs,$(1),$(2)-4M,$(3)-4M)
|
|
|
|
$(call BuildFirmware/OF/initramfs,$(1),$(2)-8M,$(3)-8M)
|
|
|
|
endef
|
|
|
|
|
2013-08-01 14:30:46 +00:00
|
|
|
define BuildFirmware/PorayDualSize/squashfs
|
|
|
|
$(call BuildFirmware/DefaultDualSize/$(1),$(1),$(2),$(3))
|
|
|
|
if [ -e "$(call sysupname,$(1),$(2)-4M)" ]; then \
|
|
|
|
mkporayfw -B $(3) -F 4M \
|
|
|
|
-f $(call sysupname,$(1),$(2)-4M) \
|
2014-10-26 17:18:45 +00:00
|
|
|
-o $(call imgname,$(1),$(2)-4M)-factory.bin; \
|
2013-08-01 14:30:46 +00:00
|
|
|
fi
|
|
|
|
if [ -e "$(call sysupname,$(1),$(2)-8M)" ]; then \
|
|
|
|
mkporayfw -B $(3) -F 8M \
|
|
|
|
-f $(call sysupname,$(1),$(2)-8M) \
|
2014-10-26 17:18:45 +00:00
|
|
|
-o $(call imgname,$(1),$(2)-8M)-factory.bin; \
|
2013-08-01 14:30:46 +00:00
|
|
|
fi
|
|
|
|
endef
|
|
|
|
BuildFirmware/PorayDualSize/initramfs=$(call BuildFirmware/DefaultDualSize/initramfs,$(1),$(2),$(3))
|
|
|
|
|
2015-02-16 21:19:18 +00:00
|
|
|
|
2013-04-03 09:59:51 +00:00
|
|
|
ifeq ($(SUBTARGET),rt288x)
|
2016-04-01 07:11:48 +00:00
|
|
|
include rt288x.mk
|
2012-02-23 19:58:15 +00:00
|
|
|
endif
|
2011-07-28 10:56:32 +00:00
|
|
|
|
2013-04-03 09:59:51 +00:00
|
|
|
ifeq ($(SUBTARGET),rt305x)
|
2016-04-01 07:11:48 +00:00
|
|
|
include rt305x.mk
|
2016-08-02 17:48:17 +00:00
|
|
|
include rt305x-legacy.mk
|
2010-04-11 17:47:28 +00:00
|
|
|
endif
|
|
|
|
|
2013-04-03 09:59:51 +00:00
|
|
|
ifeq ($(SUBTARGET),rt3883)
|
2016-04-01 07:11:48 +00:00
|
|
|
include rt3883.mk
|
2012-04-21 12:30:44 +00:00
|
|
|
endif
|
|
|
|
|
2014-11-19 09:19:38 +00:00
|
|
|
ifeq ($(SUBTARGET),mt7620)
|
2016-04-01 07:11:48 +00:00
|
|
|
include mt7620.mk
|
2013-11-16 20:28:52 +00:00
|
|
|
endif
|
|
|
|
|
2013-12-13 10:53:34 +00:00
|
|
|
ifeq ($(SUBTARGET),mt7621)
|
2016-04-01 07:11:48 +00:00
|
|
|
include mt7621.mk
|
2013-12-13 10:53:34 +00:00
|
|
|
endif
|
|
|
|
|
2014-11-06 09:31:31 +00:00
|
|
|
ifeq ($(SUBTARGET),mt7628)
|
2016-04-01 07:11:48 +00:00
|
|
|
include mt7628.mk
|
2014-11-06 09:31:31 +00:00
|
|
|
endif
|
|
|
|
|
2015-07-24 09:11:56 +00:00
|
|
|
ifeq ($(SUBTARGET),mt7688)
|
2016-04-01 07:11:48 +00:00
|
|
|
include mt7688.mk
|
2015-07-24 09:11:56 +00:00
|
|
|
endif
|
|
|
|
|
2016-08-11 15:00:36 +00:00
|
|
|
ifdef LEGACY_DEVICES
|
2013-04-03 09:59:51 +00:00
|
|
|
#
|
2015-01-10 15:26:53 +00:00
|
|
|
# Generic Targets - only needed for legacy image building code
|
2013-04-03 09:59:51 +00:00
|
|
|
#
|
|
|
|
define Image/BuildKernel
|
|
|
|
cp $(KDIR)/vmlinux.elf $(BIN_DIR)/$(VMLINUX).elf
|
|
|
|
cp $(KDIR)/vmlinux $(BIN_DIR)/$(VMLINUX).bin
|
|
|
|
$(call CompressLzma,$(KDIR)/vmlinux,$(KDIR)/vmlinux.bin.lzma)
|
|
|
|
$(call MkImage,lzma,$(KDIR)/vmlinux.bin.lzma,$(KDIR)/uImage.lzma)
|
|
|
|
cp $(KDIR)/uImage.lzma $(BIN_DIR)/$(UIMAGE).bin
|
2014-11-08 15:40:17 +00:00
|
|
|
endef
|
|
|
|
|
|
|
|
define Image/BuildKernel/Initramfs
|
2013-06-27 19:58:31 +00:00
|
|
|
cp $(KDIR)/vmlinux-initramfs.elf $(BIN_DIR)/$(VMLINUX)-initramfs.elf
|
|
|
|
cp $(KDIR)/vmlinux-initramfs $(BIN_DIR)/$(VMLINUX)-initramfs.bin
|
|
|
|
$(call CompressLzma,$(KDIR)/vmlinux-initramfs,$(KDIR)/vmlinux-initramfs.bin.lzma)
|
|
|
|
$(call MkImage,lzma,$(KDIR)/vmlinux-initramfs.bin.lzma,$(KDIR)/uImage-initramfs.lzma)
|
|
|
|
cp $(KDIR)/uImage-initramfs.lzma $(BIN_DIR)/$(UIMAGE)-initramfs.bin
|
2013-04-03 09:59:51 +00:00
|
|
|
$(call Image/Build/Initramfs)
|
|
|
|
endef
|
|
|
|
|
2009-08-30 19:15:51 +00:00
|
|
|
define Image/Build
|
|
|
|
$(call Image/Build/$(1))
|
2010-04-12 23:15:56 +00:00
|
|
|
dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1) bs=128k conv=sync
|
2009-08-30 19:15:51 +00:00
|
|
|
endef
|
2016-08-11 15:00:36 +00:00
|
|
|
|
|
|
|
define Image/Build/Profile
|
2016-09-03 08:40:11 +00:00
|
|
|
$(if $(CONFIG_TARGET_ROOTFS_INITRAMFS),$(call Image/Build/Profile/$(1),initramfs))
|
2016-08-11 15:00:36 +00:00
|
|
|
$(call Image/Build/Profile/$(1),$(2))
|
|
|
|
endef
|
|
|
|
|
2015-01-10 15:26:53 +00:00
|
|
|
endif
|
2009-08-30 19:15:51 +00:00
|
|
|
|
|
|
|
$(eval $(call BuildImage))
|