de222f08019e2f6d3e17a1032b3bc22db0251e28
[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 ### Image scripts ###
25 define Build/build-dtb
26         $(call Image/BuildDTB,$(DTS_DIR)/$(DEVICE_DTS).dts,$@.dtb)
27 endef
28
29 define Build/gen-cfg
30         cat config.txt > $@.config
31         echo -e "\ndevice_tree=$(DEVICE_DTS).dtb" >> $@.config
32 endef
33
34 define Build/boot-img
35         rm -f $@.boot
36         mkfs.fat -C $@.boot $(FAT32_BLOCKS)
37         mcopy -i $@.boot $(KDIR)/bootcode.bin ::
38         mcopy -i $@.boot $(KDIR)/COPYING.linux ::
39         mcopy -i $@.boot $(KDIR)/LICENCE.broadcom ::
40         mcopy -i $@.boot $(KDIR)/start.elf ::
41         mcopy -i $@.boot $(KDIR)/start_cd.elf ::
42         mcopy -i $@.boot $(KDIR)/fixup.dat ::
43         mcopy -i $@.boot $(KDIR)/fixup_cd.dat ::
44         mcopy -i $@.boot cmdline.txt ::
45         mcopy -i $@.boot $@.config ::config.txt
46         mcopy -i $@.boot $(word 1,$^) ::kernel.img
47         mcopy -i $@.boot $@.dtb ::$(DEVICE_DTS).dtb
48 endef
49
50 define Build/sdcard-img
51         ./gen_rpi_sdcard_img.sh $@ $@.boot $(word 2,$^) \
52                 $(CONFIG_BRCM2708_SD_BOOT_PARTSIZE) $(CONFIG_TARGET_ROOTFS_PARTSIZE)
53         $(call Image/gzip,$@)
54 endef
55
56 ### Device macros ###
57 define Device/Default
58   FILESYSTEMS := ext4
59   PROFILES = Default $$(DEVICE_PROFILE)
60   KERNEL := kernel-bin
61   IMAGES := sdcard.bin
62   IMAGE/sdcard.bin := build-dtb | gen-cfg | boot-img | sdcard-img
63   DEVICE_PROFILE :=
64   DEVICE_DTS :=
65 endef
66 DEVICE_VARS += DEVICE_PROFILE DEVICE_DTS
67
68 # $(1) = profile
69 # $(2) = image name
70 # $(3) = dts
71 define add_bcm2708
72   define Device/$(2)
73     DEVICE_PROFILE := $(1)
74     DEVICE_DTS := $(3)
75   endef
76   TARGET_DEVICES += $(2)
77 endef
78
79 ### BCM2708/BCM2835 ###
80 ifeq ($(SUBTARGET),bcm2708)
81   # Raspberry Pi Model B
82   $(eval $(call add_bcm2708,RaspberryPi_B,rpi-b,bcm2708-rpi-b))
83   # Raspberry Pi Model B+
84   $(eval $(call add_bcm2708,RaspberryPi_BPlus,rpi-b-plus,bcm2708-rpi-b-plus))
85   # Raspberry Pi Compute Module
86   $(eval $(call add_bcm2708,RaspberryPi_CM,rpi-cm,bcm2708-rpi-cm))
87 endif
88
89 ### BCM2709/BCM2836 ###
90 ifeq ($(SUBTARGET),bcm2709)
91   # Raspberry Pi 2 Model B
92   $(eval $(call add_bcm2708,RaspberryPi_2,rpi-2-b,bcm2709-rpi-2-b))
93 endif
94
95 $(eval $(call BuildImage))