1#
2# Copyright (C) 2013-2016 OpenWrt.org
3#
4# This is free software, licensed under the GNU General Public License v2.
5# See /LICENSE for more information.
6#
7include $(TOPDIR)/rules.mk
8include $(INCLUDE_DIR)/image.mk
9include $(INCLUDE_DIR)/host.mk
10
11FAT32_BLOCK_SIZE=1024
12FAT32_BLOCKS=$(shell echo $$(($(CONFIG_SUNXI_SD_BOOT_PARTSIZE)*1024*1024/$(FAT32_BLOCK_SIZE))))
13
14define Image/BuildKernel
15	-mkdir -p $(KDIR_TMP)
16
17	mkimage -A arm -O linux -T kernel -C none \
18		-a 0x40008000 -e 0x40008000 \
19		-n 'ARM OpenWrt Linux-$(LINUX_VERSION)' \
20		-d $(KDIR)/zImage $(BIN_DIR)/$(IMG_PREFIX)-uImage
21
22    ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
23	$(CP) $(KDIR)/zImage-initramfs $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs
24	echo -ne '\x00\x00\x00\x00' >> $(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs
25	$(call Image/BuildKernel/MkuImage, \
26		none, 0x40008000, 0x40008000, \
27		$(BIN_DIR)/$(IMG_PREFIX)-zImage-initramfs, \
28		$(BIN_DIR)/$(IMG_PREFIX)-uImage-initramfs \
29	)
30    endif
31endef
32
33define Image/Build/SDCard
34	rm -f $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img
35	mkdosfs $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img -C $(FAT32_BLOCKS)
36
37	mcopy -i $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img $(KDIR)/uboot-sunxi-$(PROFILE)-boot.scr ::boot.scr
38	mcopy -i $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img $(DTS_DIR)/$(2).dtb ::dtb
39	mcopy -i $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img $(BIN_DIR)/$(IMG_PREFIX)-uImage ::uImage
40
41	./gen_sunxi_sdcard_img.sh \
42		$(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-sdcard-vfat-$(1).img \
43		$(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img \
44		$(KDIR)/root.$(1) \
45		$(CONFIG_SUNXI_SD_BOOT_PARTSIZE) \
46		$(CONFIG_TARGET_ROOTFS_PARTSIZE) \
47		$(KDIR)/uboot-sunxi-$(PROFILE)-u-boot-with-spl.bin
48
49  ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
50	gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-sdcard-vfat-$(1).img
51  endif
52endef
53
54define Image/Build/Profile/A10-OLinuXino-Lime
55	$(call Image/Build/SDCard,$(1),sun4i-a10-olinuxino-lime)
56endef
57
58define Image/Build/Profile/A13-OLinuXino
59	$(call Image/Build/SDCard,$(1),sun5i-a13-olinuxino)
60endef
61
62define Image/Build/Profile/A20-OLinuXino-Lime
63	$(call Image/Build/SDCard,$(1),sun7i-a20-olinuxino-lime)
64endef
65
66define Image/Build/Profile/A20-OLinuXino_MICRO
67	$(call Image/Build/SDCard,$(1),sun7i-a20-olinuxino-micro)
68endef
69
70define Image/Build/Profile/Bananapi
71	$(call Image/Build/SDCard,$(1),sun7i-a20-bananapi)
72endef
73
74define Image/Build/Profile/Bananapro
75	$(call Image/Build/SDCard,$(1),sun7i-a20-bananapro)
76endef
77
78define Image/Build/Profile/Lamobo_R1
79	$(call Image/Build/SDCard,$(1),sun7i-a20-lamobo-r1)
80endef
81
82define Image/Build/Profile/Cubieboard
83	$(call Image/Build/SDCard,$(1),sun4i-a10-cubieboard)
84endef
85
86define Image/Build/Profile/Cubieboard2
87	$(call Image/Build/SDCard,$(1),sun7i-a20-cubieboard2)
88endef
89
90define Image/Build/Profile/Cubietruck
91	$(call Image/Build/SDCard,$(1),sun7i-a20-cubietruck)
92endef
93
94define Image/Build/Profile/OLIMEX_A13_SOM
95	$(call Image/Build/SDCard,$(1),sun5i-a13-olinuxino)
96endef
97
98define Image/Build/Profile/Mele_M9
99	$(call Image/Build/SDCard,$(1),sun6i-a31-hummingbird)
100endef
101
102define Image/Build/Profile/Linksprite_pcDuino
103	$(call Image/Build/SDCard,$(1),sun4i-a10-pcduino)
104endef
105
106define Image/Build/Profile/Linksprite_pcDuino3
107	$(call Image/Build/SDCard,$(1),sun7i-a20-pcduino3)
108endef
109
110define Image/Build/Profile/orangepi_plus
111	$(call Image/Build/SDCard,$(1),sun8i-h3-orangepi-plus)
112endef
113
114define Image/Build/Profile/orangepi_2
115	$(call Image/Build/SDCard,$(1),sun8i-h3-orangepi-2)
116endef
117
118define Image/Build/Profile/Marsboard_A10
119        $(call Image/Build/SDCard,$(1),sun4i-a10-marsboard)
120endef
121
122define Image/Build
123	$(call Image/Build/$(1),$(1))
124	$(call Image/Build/Profile/$(PROFILE),$(1))
125
126	dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1) bs=128k conv=sync
127endef
128
129$(eval $(call BuildImage))
130