sunxi: add new target
[15.05/openwrt.git] / target / linux / sunxi / image / Makefile
1 #
2 # Copyright (C) 2013 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
10 define sanitize_profile_name
11 $(shell echo $(PROFILE) | tr '[:upper:]' '[:lower:]' | sed 's/_/-/g')
12 endef
13
14 define Image/BuildKernel/Template
15
16         $(CP) $(KDIR)/zImage $(BIN_DIR)/$(IMG_PREFIX)-zImage
17         echo -ne '\x00\x00\x00\x00' >> $(BIN_DIR)/$(IMG_PREFIX)-zImage
18         $(call Image/BuildKernel/MkuImage, \
19                 none, 0x40008000, 0x40008000, \
20                 $(BIN_DIR)/$(IMG_PREFIX)-zImage, \
21                 $(BIN_DIR)/$(IMG_PREFIX)-uImage \
22         )
23
24  ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
25         $(CP) $(KDIR)/zImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs
26         echo -ne '\x00\x00\x00\x00' >> $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs
27         $(call Image/BuildKernel/MkuImage, \
28                 none, 0x40008000, 0x40008000, \
29                 $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs, \
30                 $(BIN_DIR)/$(IMG_PREFIX)-uImage-initramfs \
31         )
32  endif
33
34  ifneq ($(1),)
35         $(CP) $(LINUX_DIR)/arch/arm/boot/dts/$(1).dtb $(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb
36
37         $(CP) $(KDIR)/zImage $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-zImage
38         cat $(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb >> $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-zImage
39         $(call Image/BuildKernel/MkuImage, \
40                 none, 0x40008000, 0x40008000, \
41                 $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-zImage, \
42                 $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-uImage \
43         )
44
45   ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
46         $(CP) $(KDIR)/zImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-zImage-initramfs
47         cat $(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb >> $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-zImage-initramfs
48         $(call Image/BuildKernel/MkuImage, \
49                 none, 0x40008000, 0x40008000, \
50                 $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-zImage-initramfs, \
51                 $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-uImage-initramfs \
52         )
53   endif
54  endif
55 endef
56
57 define Image/InstallKernel/Template
58
59  ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_KERNEL),)
60         $(INSTALL_DIR) $(TARGET_DIR)/boot
61    ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_UIMAGE),)
62         $(CP) $(BIN_DIR)/$(IMG_PREFIX)-uImage $(TARGET_DIR)/boot/
63         ln -sf $(IMG_PREFIX)-uImage $(TARGET_DIR)/boot/uImage
64    endif
65    ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_ZIMAGE),)
66         $(CP) $(BIN_DIR)/$(IMG_PREFIX)-zImage $(TARGET_DIR)/boot/
67         ln -sf $(IMG_PREFIX)-zImage $(TARGET_DIR)/boot/zImage
68    endif
69  endif
70
71  ifneq ($(CONFIG_TARGET_ROOTFS_INCLUDE_DTB),)
72         $(INSTALL_DIR) $(TARGET_DIR)/boot
73   ifneq ($(1),)
74         $(CP) $(BIN_DIR)/$(IMG_PREFIX)-$(1).dtb $(TARGET_DIR)/boot/
75         ln -sf $(IMG_PREFIX)-$(1).dtb $(TARGET_DIR)/boot/$(1).dtb
76   endif
77  endif
78 endef
79
80 define Image/mkfs/targz
81
82         $(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-rootfs.tar.gz --numeric-owner --owner=0 --group=0 -C $(TARGET_DIR)/ .
83 endef
84
85 define Image/Build/ubifs
86
87  ifneq ($($(PROFILE)_UBIFS_OPTS),)
88         $(CP) $(KDIR)/root.ubifs $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-rootfs.ubifs
89  endif
90 endef
91
92 define Image/Build/ubi
93
94  ifneq ($($(PROFILE)_UBI_OPTS),)
95         $(CP) $(KDIR)/root.ubi $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-rootfs.ubi
96  endif
97 endef
98
99
100 Image/BuildKernel/Template/generic=$(call Image/BuildKernel/Template)
101 Image/InstallKernel/Template/generic=$(call Image/InstallKernel/Template)
102
103 Image/BuildKernel/Template/CUBIEBOARD=$(call Image/BuildKernel/Template,sun4i-a10-cubieboard)
104 Image/InstallKernel/Template/CUBIEBOARD=$(call Image/InstallKernel/Template,sun4i-a10-cubieboard)
105
106 define Image/BuildKernel
107         $(call Image/BuildKernel/Template/$(PROFILE))
108 endef
109
110 define Image/InstallKernel
111         $(call Image/InstallKernel/Template/$(PROFILE))
112 endef
113
114 define Image/Build
115         $(if $(Image/Build/$(1)), \
116                 $(call Image/Build/$(1),$(1)), \
117                 $(CP) $(KDIR)/root.$(1) $(BIN_DIR)/$(IMG_PREFIX)-$(call sanitize_profile_name)-$(1).img \
118         )
119 endef
120
121 $(eval $(call BuildImage))