172eb067449d8556cbc8b4c8dbacbb53b9b2debe
[openwrt/openwrt.git] / target / linux / arc770 / image / Makefile
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # Copyright (C) 2016 OpenWrt.org
4
5 include $(TOPDIR)/rules.mk
6 include $(INCLUDE_DIR)/image.mk
7
8 # On ARC initramfs is put before entry point and so entry point moves
9 # in memory from build to built. Thus we need to extract EP from vmlinux
10 # every time before generation of uImage.
11 kernel_ep = `$(KERNEL_CROSS)readelf -h $(1) | grep "Entry point address" | grep -o 0x.*`
12
13 define Build/patch-dtb
14 $(STAGING_DIR_HOST)/bin/patch-dtb $@ $(DTS_DIR)/$(DEVICE_DTS).dtb
15 endef
16
17 ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
18 # Root FS built-in
19 define Device/vmlinux
20 KERNEL_SUFFIX := .elf
21 KERNEL := kernel-bin | patch-dtb
22 KERNEL_INITRAMFS_NAME = vmlinux-initramfs.elf
23 endef
24
25 define Device/nsim
26 $(call Device/vmlinux)
27 DEVICE_PROFILE := nsim
28 DEVICE_DTS := nsim_700
29 endef
30 TARGET_DEVICES += nsim
31 endif
32
33 # Root FS on SD-card
34 KERNEL_LOADADDR := 0x80000000
35 DEVICE_DTS_LIST:= axs101 nsim_700
36 FAT32_BLOCK_SIZE=1024
37 FAT32_BLOCKS=$(shell echo $$(($(CONFIG_AXS10X_SD_BOOT_PARTSIZE)*1024*1024/$(FAT32_BLOCK_SIZE))))
38
39 define Image/Prepare
40 # Build .dtb for all boards we may run on
41 $(foreach dts,$(DEVICE_DTS_LIST),
42 $(call Image/BuildDTB,$(DTS_DIR)/$(dts).dts,$(DTS_DIR)/$(dts).dtb)
43 )
44 endef
45
46 define Image/Build/SDCard
47 rm -f $(KDIR_TMP)/$(IMG_PREFIX)-$(PROFILE)-boot.img
48 mkfs.fat $(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 Image/BuildKernel/MkuImage, \
69 none, $(KERNEL_LOADADDR),$(call kernel_ep,$(KDIR)/vmlinux.elf) , \
70 $(KDIR)/vmlinux, \
71 $(BIN_DIR)/$(IMG_PREFIX)-uImage \
72 )
73 endef
74
75 define Image/Build
76 $(call Image/Build/$(1),$(1))
77 $(call Image/Build/SDCard,$(1))
78 dd if=$(KDIR)/root.$(1) of=$(BIN_DIR)/$(IMG_PREFIX)-root.$(1) bs=128k conv=sync
79 $(call Image/Gzip,$(BIN_DIR)/$(IMG_PREFIX)-root.$(1))
80 endef
81
82 $(eval $(call BuildImage))