archs38: Introduce images for SD-cards
[openwrt/openwrt.git] / target / linux / archs38 / image / Makefile
1 #
2 # Copyright (C) 2016 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 # On ARC initramfs is put before entry point and so entry point moves
11 # in memory from build to built. Thus we need to extract EP from vmlinux
12 # every time before generation of uImage.
13 define Build/calculate-ep
14 $(eval KERNEL_ENTRY=$(shell $(KERNEL_CROSS)readelf -h $(LINUX_DIR)/vmlinux | grep "Entry point address" | grep -o 0x.*))
15 endef
16
17 define Build/build-dtb
18 $(call Image/BuildDTB,$(DTS_DIR)/$(DEVICE_DTS).dts,$(DTS_DIR)/$(DEVICE_DTS).dtb)
19 endef
20
21 define Build/patch-dtb
22 $(STAGING_DIR_HOST)/bin/patch-dtb $@ $(DTS_DIR)/$(DEVICE_DTS).dtb
23 endef
24
25 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
26 # Root FS built-in
27 define Device/vmlinux
28 KERNEL_SUFFIX := .elf
29 KERNEL := kernel-bin | build-dtb | patch-dtb
30 KERNEL_INITRAMFS_NAME = vmlinux-initramfs.elf
31 endef
32
33 define Device/nsim_hs
34 $(call Device/vmlinux)
35 DEVICE_PROFILE := nsim_hs
36 DEVICE_DTS := nsim_hs_idu
37 endef
38 TARGET_DEVICES += nsim_hs
39 else
40 # Root FS on SD-card
41 KERNEL_LOADADDR := 0x80000000
42 DEVICE_DTS_LIST:= axs103_idu
43 FAT32_BLOCK_SIZE=1024
44 FAT32_BLOCKS=$(shell echo $$(($(CONFIG_AXS10X_SD_BOOT_PARTSIZE)*1024*1024/$(FAT32_BLOCK_SIZE))))
45
46 define Image/Build/SDCard
47 rm -f $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img
48 mkdosfs $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img -C $(FAT32_BLOCKS)
49 mkimage -C none -A arc -T script -d uEnv.txt $(BIN_DIR)/uEnv.scr
50 mcopy -i $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img $(BIN_DIR)/uEnv.scr ::boot.scr
51 mcopy -i $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img $(DTS_DIR)/*.dtb ::
52 mcopy -i $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img $(BIN_DIR)/$(IMG_PREFIX)-uImage ::uImage
53
54 ./gen_axs10x_sdcard_img.sh \
55 $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-sdcard-vfat-$(1).img \
56 $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img \
57 $(KDIR)/root.$(1) \
58 $(CONFIG_AXS10X_SD_BOOT_PARTSIZE) \
59 $(CONFIG_TARGET_ROOTFS_PARTSIZE)
60
61 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
62 gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-sdcard-vfat-$(1).img
63 endif
64 endef
65
66 define Image/BuildKernel
67 # Build unified uImage
68 $(call Build/calculate-ep)
69 $(call Image/BuildKernel/MkuImage, \
70 none, $(KERNEL_LOADADDR), $(KERNEL_ENTRY), \
71 $(KDIR)/vmlinux, \
72 $(BIN_DIR)/$(IMG_PREFIX)-uImage \
73 )
74
75 # Build .dtb for all boards we may run on
76 $(foreach DEVICE_DTS,$(shell echo $(DEVICE_DTS_LIST)), $(call Build/build-dtb))
77 endef
78
79 define Image/Build
80 $(call Image/Build/$(1),$(1))
81 $(call Image/Build/SDCard,$(1))
82 dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1) bs=128k conv=sync
83 endef
84 endif
85
86 $(eval $(call BuildImage))