4475aa8eab617cc8a1db423b4c479138d01f34e8
[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 include $(INCLUDE_DIR)/host.mk
10
11 FAT32_BLOCK_SIZE=1024
12 FAT32_BLOCKS=$(shell echo $$(($(CONFIG_SUNXI_SD_BOOT_PARTSIZE)*1024*1024/$(FAT32_BLOCK_SIZE))))
13
14 BOARDS:= \
15         sun4i-a10-cubieboard \
16         sun4i-a10-olinuxino-lime \
17         sun4i-a10-pcduino \
18         sun5i-a13-olinuxino \
19         sun6i-a31-colombus \
20         sun6i-a31-m9 \
21         sun7i-a20-bananapi \
22         sun7i-a20-bananapro \
23         sun7i-a20-cubieboard2 \
24         sun7i-a20-cubietruck \
25         sun7i-a20-olinuxino-lime \
26         sun7i-a20-olinuxino-micro \
27         sun7i-a20-pcduino3
28
29 define Image/BuildKernel
30         mkimage -A arm -O linux -T kernel -C none \
31                 -a 0x40008000 -e 0x40008000 \
32                 -n 'ARM OpenWrt Linux-$(LINUX_VERSION)' \
33                 -d $(KDIR)/zImage $(BIN_DIR)/$(IMG_PREFIX)-uImage
34         
35     ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
36         $(CP) $(KDIR)/zImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs
37         echo -ne '\x00\x00\x00\x00' >> $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs
38         $(call Image/BuildKernel/MkuImage, \
39                 none, 0x40008000, 0x40008000, \
40                 $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs, \
41                 $(BIN_DIR)/$(IMG_PREFIX)-uImage-initramfs \
42         )
43     endif
44
45         $(foreach board,$(BOARDS),
46                 $(CP) $(DTS_DIR)/$(board).dtb $(BIN_DIR)/
47         )
48 endef
49
50 define Image/Build/SDCard
51         rm -f $(KDIR)/boot.img
52         mkdosfs $(KDIR)/boot.img -C $(FAT32_BLOCKS)
53         
54         mcopy -i $(KDIR)/boot.img $(BIN_DIR)/uboot-sunxi-$(PROFILE)/openwrt-sunxi-$(PROFILE)-boot.scr ::boot.scr
55         mcopy -i $(KDIR)/boot.img $(BIN_DIR)/$(2).dtb ::dtb
56         mcopy -i $(KDIR)/boot.img $(BIN_DIR)/$(IMG_PREFIX)-uImage ::uImage
57         
58         ./gen_sunxi_sdcard_img.sh \
59                 $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-sdcard-vfat-$(1).img \
60                 $(KDIR)/boot.img \
61                 $(KDIR)/root.$(1) \
62                 $(CONFIG_SUNXI_SD_BOOT_PARTSIZE) \
63                 $(CONFIG_TARGET_ROOTFS_PARTSIZE) \
64                 $(BIN_DIR)/uboot-sunxi-$(PROFILE)/openwrt-sunxi-$(PROFILE)-u-boot-with-spl.bin
65 endef
66
67 define Image/Build/Profile/A10-OLinuXino-Lime
68         $(call Image/Build/SDCard,$(1),sun4i-a10-olinuxino-lime)
69 endef
70
71 define Image/Build/Profile/A13-OLinuXino
72         $(call Image/Build/SDCard,$(1),sun5i-a13-olinuxino)
73 endef
74
75 define Image/Build/Profile/A20-OLinuXino_Lime
76         $(call Image/Build/SDCard,$(1),sun7i-a20-olinuxino-lime)
77 endef
78
79 define Image/Build/Profile/A20-OLinuXino_MICRO
80         $(call Image/Build/SDCard,$(1),sun7i-a20-olinuxino-micro)
81 endef
82
83 define Image/Build/Profile/Bananapi
84         $(call Image/Build/SDCard,$(1),sun7i-a20-bananapi)
85 endef
86
87 define Image/Build/Profile/Bananapro
88         $(call Image/Build/SDCard,$(1),sun7i-a20-bananapro)
89 endef
90
91 define Image/Build/Profile/Cubieboard
92         $(call Image/Build/SDCard,$(1),sun4i-a10-cubieboard)
93 endef
94
95 define Image/Build/Profile/Cubieboard2
96         $(call Image/Build/SDCard,$(1),sun7i-a20-cubieboard2)
97 endef
98
99 define Image/Build/Profile/Cubietruck
100         $(call Image/Build/SDCard,$(1),sun7i-a20-cubietruck)
101 endef
102
103 define Image/Build/Profile/OLIMEX_A13_SOM
104         $(call Image/Build/SDCard,$(1),sun5i-a13-olinuxino)
105 endef
106
107 define Image/Build/Profile/Mele_M9
108         $(call Image/Build/SDCard,$(1),sun6i-a31-hummingbird)
109 endef
110
111 define Image/Build/Profile/Linksprite_pcDuino
112         $(call Image/Build/SDCard,$(1),sun4i-a10-pcduino)
113 endef
114
115 define Image/Build/Profile/Linksprite_pcDuino3
116         $(call Image/Build/SDCard,$(1),sun7i-a20-pcduino3)
117 endef
118
119 define Image/Build
120         $(call Image/Build/$(1),$(1))
121         $(call Image/Build/Profile/$(PROFILE),$(1))
122         
123         dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/openwrt-$(BOARD)-root.$(1) bs=128k conv=sync
124 endef
125
126 $(eval $(call BuildImage))