260757845ea99b9c7c3d631b0fcda0ce0ad4310b
[openwrt/staging/yousong.git] / target / linux / arc770 / 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 kernel_ep = `$(KERNEL_CROSS)readelf -h $(1) | grep "Entry point address" | grep -o 0x.*`
14
15 define Build/patch-dtb
16 $(STAGING_DIR_HOST)/bin/patch-dtb $@ $(DTS_DIR)/$(DEVICE_DTS).dtb
17 endef
18
19 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
20 # Root FS built-in
21 define Device/vmlinux
22 KERNEL_SUFFIX := .elf
23 KERNEL := kernel-bin | patch-dtb
24 KERNEL_INITRAMFS_NAME = vmlinux-initramfs.elf
25 endef
26
27 define Device/nsim
28 $(call Device/vmlinux)
29 DEVICE_PROFILE := nsim
30 DEVICE_DTS := nsim_700
31 endef
32 TARGET_DEVICES += nsim
33 endif
34
35 # Root FS on SD-card
36 KERNEL_LOADADDR := 0x80000000
37 DEVICE_DTS_LIST:= axs101 nsim_700
38 FAT32_BLOCK_SIZE=1024
39 FAT32_BLOCKS=$(shell echo $$(($(CONFIG_AXS10X_SD_BOOT_PARTSIZE)*1024*1024/$(FAT32_BLOCK_SIZE))))
40
41 define Image/Prepare
42 # Build .dtb for all boards we may run on
43 $(foreach dts,$(DEVICE_DTS_LIST),
44 $(call Image/BuildDTB,$(DTS_DIR)/$(dts).dts,$(DTS_DIR)/$(dts).dtb)
45 )
46 endef
47
48 define Image/Build/SDCard
49 rm -f $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img
50 mkfs.fat $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img -C $(FAT32_BLOCKS)
51 mkimage -C none -A arc -T script -d uEnv.txt $(BIN_DIR)/uEnv.scr
52 mcopy -i $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img $(BIN_DIR)/uEnv.scr ::boot.scr
53 mcopy -i $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img $(DTS_DIR)/*.dtb ::
54 mcopy -i $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img $(BIN_DIR)/$(IMG_PREFIX)-uImage ::uImage
55
56 ./gen_axs10x_sdcard_img.sh \
57 $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-sdcard-vfat-$(1).img \
58 $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img \
59 $(KDIR)/root.$(1) \
60 $(CONFIG_AXS10X_SD_BOOT_PARTSIZE) \
61 $(CONFIG_TARGET_ROOTFS_PARTSIZE)
62
63 ifneq ($(CONFIG_TARGET_IMAGES_GZIP),)
64 gzip -f9n $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-sdcard-vfat-$(1).img
65 endif
66 endef
67
68 define Image/BuildKernel
69 # Build unified uImage
70 $(call Image/BuildKernel/MkuImage, \
71 none, $(KERNEL_LOADADDR),$(call kernel_ep,$(KDIR)/vmlinux.elf) , \
72 $(KDIR)/vmlinux, \
73 $(BIN_DIR)/$(IMG_PREFIX)-uImage \
74 )
75 endef
76
77 define Image/Build
78 $(call Image/Build/$(1),$(1))
79 $(call Image/Build/SDCard,$(1))
80 dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1) bs=128k conv=sync
81 $(call Image/Gzip,$(BIN_DIR)/$(IMG_PREFIX)-root.$(1))
82 endef
83
84 $(eval $(call BuildImage))