c1cb2bcfdd4ba92b400ba42e66b071fe80802011
[openwrt/staging/chunkeey.git] / target / linux / apm821xx / image / Makefile
1 #
2 # This is free software, licensed under the GNU General Public License v2.
3 # See /LICENSE for more information.
4 #
5 include $(TOPDIR)/rules.mk
6 include $(INCLUDE_DIR)/image.mk
7
8 DEVICE_VARS += DTB_SIZE
9
10 define Build/boot-img
11 $(RM) -rf $@.bootdir
12 mkdir -p $@.bootdir/boot
13
14 $(CP) $@.scr $@.bootdir/boot/boot.scr
15 $(CP) $(IMAGE_KERNEL).dtb $@.bootdir/boot/$(DEVICE_DTB)
16 $(CP) $(IMAGE_KERNEL) $@.bootdir/boot/uImage
17
18 genext2fs --block-size $(BLOCKSIZE:%k=%Ki) \
19 --size-in-blocks $$((1024 * $(CONFIG_TARGET_KERNEL_PARTSIZE))) \
20 --root $@.bootdir $@.boot
21
22 # convert it to revision 1 - needed for u-boot ext2load
23 $(STAGING_DIR_HOST)/bin/tune2fs -O filetype $@.boot
24 $(STAGING_DIR_HOST)/bin/e2fsck -pDf $@.boot > /dev/null
25 endef
26
27 define Build/boot-script
28 $(STAGING_DIR_HOST)/bin/mkimage -A powerpc -T script -C none -n "$(PROFILE) Boot Script" \
29 -d mbl_boot.scr \
30 $@.scr
31 endef
32
33 define Build/copy-file
34 cat "$(1)" > "$@"
35 endef
36
37 define Build/dtb
38 $(call Image/BuildDTB,../dts/$(DEVICE_DTS).dts,$@.dtb,,--space $(DTB_SIZE))
39 endef
40
41 define Build/export-dtb
42 cp $(IMAGE_KERNEL).dtb $@
43 endef
44
45 define Build/MuImage-initramfs
46 rm -rf $@.fakerd $@.new
47
48 dd if=/dev/zero of=$@.fakerd bs=32 count=1 conv=sync
49
50 # Netgear used an old uboot that doesn't have FIT support.
51 # So we are stuck with either a full ext2/4 fs in a initrd.
52 # ... or we try to make the "multi" image approach to work
53 # for us.
54 #
55 # Sadly, the "multi" image has to consists of three
56 # "fixed" parts in the following "fixed" order:
57 # 1. The kernel which is in $@
58 # 2. The (fake) initrd which is in $@.fakerd
59 # 3. The device tree binary which is in $@.dtb
60 #
61 # Now, given that we use the function for the kernel which
62 # already has a initramfs image inside, we still have to
63 # add a "fake" initrd (which a mkimage header) in the second
64 # part of the legacy multi image. Since we need to put the
65 # device tree stuff into part 3.
66
67 -$(STAGING_DIR_HOST)/bin/mkimage -A $(LINUX_KARCH) -O linux -T multi \
68 -C $(1) -a $(KERNEL_LOADADDR) -e $(KERNEL_ENTRY) \
69 -n '$(BOARD_NAME) initramfs' -d $@:$@.fakerd:$@.dtb $@.new
70 mv $@.new $@
71 rm -rf $@.fakerd
72 endef
73
74 define Build/prepend-dtb
75 cat "$@.dtb.uimage" "$@" > "$@.new"
76 mv "$@.new" "$@"
77 endef
78
79 define Image/cpiogz
80 ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9n >$(KDIR_TMP)/$(IMG_PREFIX)-rootfs.cpio.gz )
81 endef
82
83 define Device/Default
84 PROFILES := Default
85 KERNEL_DEPENDS = $$(wildcard ../dts/$$(DEVICE_DTS).dts)
86 DEVICE_DTS :=
87 KERNEL_ENTRY := 0x00000000
88 KERNEL_LOADADDR := 0x00000000
89 DEVICE_DTS_DIR := ../dts
90 DEVICE_DTS = $(subst _,-,$(1))
91 endef
92
93 include $(SUBTARGET).mk
94
95 $(eval $(call BuildImage))