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