brcm2708: Implement sysupgrade
[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 ### Image scripts ###
15 define Build/build-dtb
16         $(LINUX_DIR)/scripts/dtc/dtc -O dtb -o $@.dtb $(DTS_DIR)/$(DEVICE_DTS).dts
17 endef
18
19 define Build/gen-cfg
20         cat config.txt > $@.config
21         echo -e "\ndevice_tree=$(DEVICE_DTS).dtb" >> $@.config
22 endef
23
24 define Build/boot-img
25         rm -f $@.boot
26         mkfs.fat -C $@.boot $(FAT32_BLOCKS)
27         mcopy -i $@.boot $(KDIR)/bootcode.bin ::
28         mcopy -i $@.boot $(KDIR)/COPYING.linux ::
29         mcopy -i $@.boot $(KDIR)/LICENCE.broadcom ::
30         mcopy -i $@.boot $(KDIR)/start.elf ::
31         mcopy -i $@.boot $(KDIR)/start_cd.elf ::
32         mcopy -i $@.boot $(KDIR)/fixup.dat ::
33         mcopy -i $@.boot $(KDIR)/fixup_cd.dat ::
34         mcopy -i $@.boot cmdline.txt ::
35         mcopy -i $@.boot $@.config ::config.txt
36         mcopy -i $@.boot $(word 1,$^) ::kernel.img
37         mcopy -i $@.boot $@.dtb ::$(DEVICE_DTS).dtb
38 endef
39
40 define Build/sdcard-img
41         ./gen_rpi_sdcard_img.sh $@ $@.boot $(word 2,$^) \
42                 $(CONFIG_BRCM2708_SD_BOOT_PARTSIZE) $(CONFIG_TARGET_ROOTFS_PARTSIZE)
43   ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
44         gzip -k -f9 $(BIN_DIR)/$(IMG_PREFIX)-sdcard-vfat-$(1).img
45   endif
46 endef
47
48 ### Device macros ###
49 define Device/Default
50   FILESYSTEMS := ext4
51   PROFILES = Default $$(DEVICE_PROFILE)
52   KERNEL := kernel-bin
53   IMAGES := sdcard.bin
54   IMAGE/sdcard.bin := build-dtb | gen-cfg | boot-img | sdcard-img
55   DEVICE_PROFILE :=
56   DEVICE_NAME :=
57   DEVICE_DTS :=
58 endef
59 DEVICE_VARS += DEVICE_PROFILE DEVICE_NAME DEVICE_DTS
60
61 # $(1) = profile
62 # $(2) = image name
63 # $(3) = dts
64 define add_bcm2708
65   define Device/$(2)
66     DEVICE_PROFILE := $(1)
67     DEVICE_NAME := $(2)
68     DEVICE_DTS := $(3)
69   endef
70   TARGET_DEVICES += $(2)
71 endef
72
73 # Raspberry Pi Model B
74 $(eval $(call add_bcm2708,RaspberryPi,rpi-b,bcm2708-rpi-b))
75 # Raspberry Pi Model B+
76 $(eval $(call add_bcm2708,RaspberryPi,rpi-b-plus,bcm2708-rpi-b-plus))
77 # Raspberry Pi 2 Model B
78 $(eval $(call add_bcm2708,RaspberryPi2,rpi-2-b,bcm2709-rpi-2-b))
79
80 $(eval $(call BuildImage))