brcm2708: add support for device tree overlays
[openwrt.git] / target / linux / brcm2708 / image / Makefile
1
2 # Copyright (C) 2012-2015 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7 include $(TOPDIR)/rules.mk
8 include $(INCLUDE_DIR)/image.mk
9 include $(INCLUDE_DIR)/host.mk
10
11 FAT32_BLOCK_SIZE=1024
12 FAT32_BLOCKS=$(shell echo $$(($(CONFIG_BRCM2708_SD_BOOT_PARTSIZE)*1024*1024/$(FAT32_BLOCK_SIZE))))
13
14 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
15   define Image/gzip
16     gzip -9n -c $(1) > $(1).gz
17     mv $(1).gz $(BIN_DIR)
18   endef
19 else
20   define Image/gzip
21   endef
22 endif
23
24 define Image/Prepare
25         rm -rf $(KDIR)/overlays
26         mkdir -p $(KDIR)/overlays
27         $(CP) $(DTS_DIR)/overlays/*.dtb $(KDIR)/overlays/
28 endef
29
30 ### Image scripts ###
31 define Build/gen-cfg
32         cat config.txt > $@.config
33         echo -e "\ndevice_tree=$(DEVICE_DTS).dtb" >> $@.config
34 endef
35
36 define Build/boot-img
37         rm -f $@.boot
38         mkfs.fat -C $@.boot $(FAT32_BLOCKS)
39         mcopy -i $@.boot $(KDIR)/bootcode.bin ::
40         mcopy -i $@.boot $(KDIR)/COPYING.linux ::
41         mcopy -i $@.boot $(KDIR)/LICENCE.broadcom ::
42         mcopy -i $@.boot $(KDIR)/start.elf ::
43         mcopy -i $@.boot $(KDIR)/start_cd.elf ::
44         mcopy -i $@.boot $(KDIR)/fixup.dat ::
45         mcopy -i $@.boot $(KDIR)/fixup_cd.dat ::
46         mcopy -i $@.boot cmdline.txt ::
47         mcopy -i $@.boot $@.config ::config.txt
48         mcopy -i $@.boot $(word 1,$^) ::kernel.img
49         mcopy -i $@.boot $(DTS_DIR)/$(DEVICE_DTS).dtb ::$(DEVICE_DTS).dtb
50         mcopy -s -i $@.boot $(KDIR)/overlays ::
51 endef
52
53 define Build/sdcard-img
54         ./gen_rpi_sdcard_img.sh $@ $@.boot $(word 2,$^) \
55                 $(CONFIG_BRCM2708_SD_BOOT_PARTSIZE) $(CONFIG_TARGET_ROOTFS_PARTSIZE)
56         $(call Image/gzip,$@)
57 endef
58
59 ### Device macros ###
60 define Device/Default
61   FILESYSTEMS := ext4
62   PROFILES = Default $$(DEVICE_PROFILE)
63   KERNEL := kernel-bin
64   IMAGES := sdcard.bin
65   IMAGE/sdcard.bin := gen-cfg | boot-img | sdcard-img
66   DEVICE_PROFILE :=
67   DEVICE_DTS :=
68 endef
69 DEVICE_VARS += DEVICE_PROFILE DEVICE_DTS
70
71 # $(1) = profile
72 # $(2) = image name
73 # $(3) = dts
74 define add_bcm2708
75   define Device/$(2)
76     DEVICE_PROFILE := $(1)
77     DEVICE_DTS := $(3)
78   endef
79   TARGET_DEVICES += $(2)
80 endef
81
82 ### BCM2708/BCM2835 ###
83 ifeq ($(SUBTARGET),bcm2708)
84   # Raspberry Pi Model B
85   $(eval $(call add_bcm2708,RaspberryPi_B,rpi-b,bcm2708-rpi-b))
86   # Raspberry Pi Model B+
87   $(eval $(call add_bcm2708,RaspberryPi_BPlus,rpi-b-plus,bcm2708-rpi-b-plus))
88   # Raspberry Pi Compute Module
89   $(eval $(call add_bcm2708,RaspberryPi_CM,rpi-cm,bcm2708-rpi-cm))
90 endif
91
92 ### BCM2709/BCM2836 ###
93 ifeq ($(SUBTARGET),bcm2709)
94   # Raspberry Pi 2 Model B
95   $(eval $(call add_bcm2708,RaspberryPi_2,rpi-2-b,bcm2709-rpi-2-b))
96 endif
97
98 $(eval $(call BuildImage))