38877f9bcaf148a3df9cf0a2a43e2487c3b8cdf7
[openwrt/openwrt.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 include $(INCLUDE_DIR)/host.mk
8
9 DEVICE_VARS += DEVICE_PROFILE IMAGE_SIZE DTB_SIZE
10
11 define Device/Default
12 PROFILES := Default
13 KERNEL_DEPENDS = $$(wildcard ../dts/$$(DEVICE_DTS).dts)
14 DEVICE_PROFILE :=
15 DEVICE_DTS :=
16 KERNEL_ENTRY := 0x00000000
17 KERNEL_LOADADDR := 0x00000000
18 DEVICE_DTS_DIR := ../dts
19 endef
20
21 define Build/dtb
22 $(call Image/BuildDTB,../dts/$(DEVICE_DTS).dts,$@.dtb,,--space $(DTB_SIZE))
23 endef
24
25 ifeq ($(SUBTARGET),nand)
26
27 define Image/cpiogz
28 ( cd $(TARGET_DIR); find . | cpio -o -H newc | gzip -9n >$(KDIR_TMP)/$(IMG_PREFIX)-rootfs.cpio.gz )
29 endef
30
31 define Build/copy-file
32 cat "$(1)" > "$@"
33 endef
34
35 define Build/MerakiAdd-dtb
36 $(call Image/BuildDTB,../dts/$(DEVICE_DTS).dts,$@.dtb)
37 ( \
38 dd if=$@.dtb bs=$(DTB_SIZE) conv=sync; \
39 dd if=$@ bs=$(BLOCKSIZE) conv=sync; \
40 ) > $@.new
41 @mv $@.new $@
42 endef
43
44 define Build/MerakiAdd-initramfs
45 $(call Image/cpiogz)
46
47 -$(STAGING_DIR_HOST)/bin/mkimage -A $(LINUX_KARCH) -O linux -T ramdisk \
48 -C gzip -n "$(PROFILE) rootfs" \
49 -d $(KDIR_TMP)/$(IMG_PREFIX)-rootfs.cpio.gz \
50 $(KDIR_TMP)/$(IMG_PREFIX)-uramdisk.image.gz
51
52 ( \
53 dd if=$@ bs=1k conv=sync; \
54 dd if=$(KDIR_TMP)/$(IMG_PREFIX)-uramdisk.image.gz bs=$(BLOCKSIZE) conv=sync; \
55 ) > $@.new
56 @mv $@.new $@
57 endef
58
59 define Build/MerakiNAND
60 -$(STAGING_DIR_HOST)/bin/mkmerakifw \
61 -B $(DEVICE_PROFILE) -s \
62 -i $@ \
63 -o $@.new
64 @cp $@.new $@
65 endef
66
67 define Device/mr24
68 DEVICE_TITLE := Cisco Meraki MR24
69 DEVICE_PACKAGES := kmod-spi-gpio kmod-ath9k wpad-mini
70 DEVICE_PROFILE := MR24
71 DEVICE_DTS := MR24
72 BLOCKSIZE := 64512
73 IMAGES := sysupgrade.tar
74 DTB_SIZE := 64512
75 KERNEL_SIZE := 1984k
76 IMAGE_SIZE := 8191k
77 KERNEL := kernel-bin | lzma | uImage lzma | MerakiAdd-dtb | MerakiNAND
78 KERNEL_INITRAMFS := copy-file $(KDIR)/vmlinux | lzma | uImage lzma | \
79 check-size $$(KERNEL_SIZE) | \
80 MerakiAdd-dtb | pad-to 2047k | MerakiAdd-initramfs | \
81 MerakiNAND
82 IMAGE/sysupgrade.tar := sysupgrade-tar
83 endef
84 TARGET_DEVICES += mr24
85
86 define Build/create-uImage-dtb
87 # flat_dt target expect FIT image - which WNDR4700's uboot doesn't support
88 -$(STAGING_DIR_HOST)/bin/mkimage -A $(LINUX_KARCH) \
89 -O linux -T kernel -C none \
90 -n '$(call toupper,$(LINUX_KARCH)) LEDE Linux-$(LINUX_VERSION)' \
91 -d $(IMAGE_KERNEL).dtb $@.new
92 @mv $@.new $@
93 endef
94
95 define Build/append-fakerootfs
96 rm -rf $@.fakerootsquashfs $@.fakefs
97
98 # append a fake/empty rootfs to fool netgear's uboot
99 # CHECK_DNI_FIRMWARE_ROOTFS_INTEGRITY in do_chk_dniimg()
100 dd if=/dev/zero of=$@.fakerd bs=16 count=1 conv=sync
101
102 -$(STAGING_DIR_HOST)/bin/mkimage \
103 -A $(LINUX_KARCH) -O linux -T filesystem -C none \
104 -a 0x00000000 -e 0x00000000 \
105 -n '$(DEVICE_PROFILE) fakerootfs' \
106 -d $@.fakerd $@.fakefs
107
108 cat $@.fakefs >> $@
109 rm -rf $@.fakerootsquashfs $@.fakefs
110 endef
111
112 define Build/wndr4700-specialImage
113 rm -rf $@.fakerd $@.new
114
115 dd if=/dev/zero of=$@.fakerd bs=32 count=1 conv=sync
116
117 # Netgear used an old uboot that doesn't have FIT support.
118 # So we are stuck with either a full ext2/4 fs in a initrd.
119 # ... or we try to make the "multi" image approach to work
120 # for us.
121 #
122 # Sadly, the "multi" image has to consists of three
123 # "fixed" parts in the following "fixed" order:
124 # 1. The kernel which is in $@
125 # 2. The (fake) initrd which is in $@.fakerd
126 # 3. The device tree binary which is in $@.dtb
127 #
128 # Now, given that we use the function for the kernel which
129 # already has a initramfs image inside, we still have to
130 # add a "fake" initrd (which a mkimage header) in the second
131 # part of the legacy multi image. Since we need to put the
132 # device tree stuff into part 3.
133
134 -$(STAGING_DIR_HOST)/bin/mkimage -A $(LINUX_KARCH) -O linux -T multi \
135 -C $(1) -a $(KERNEL_LOADADDR) -e $(KERNEL_ENTRY) \
136 -n '$(DEVICE_PROFILE) initramfs' -d $@:$@.fakerd:$@.dtb $@.new
137 mv $@.new $@
138 rm -rf $@.fakerd
139 endef
140
141 define Device/WNDR4700
142 DEVICE_TITLE := Netgear Centria N900 WNDR4700/WNDR4720
143 DEVICE_PACKAGES := badblocks block-mount e2fsprogs \
144 kmod-ath9k kmod-dm kmod-fs-ext4 kmod-fs-vfat kmod-ledtrig-usbdev \
145 kmod-md-mod kmod-nls-cp437 kmod-nls-iso8859-1 kmod-nls-iso8859-15 \
146 kmod-nls-utf8 kmod-usb3 kmod-usb-dwc2 kmod-usb-storage \
147 partx-utils swconfig wpad-mini
148 DEVICE_NAME := wndr4700
149 DEVICE_PROFILE := wndr4700
150 DEVICE_DTS := wndr4700
151 PAGESIZE := 2048
152 SUBPAGESIZE := 512
153 BLOCKSIZE := 131072
154 DTB_SIZE := 131008
155 IMAGE_SIZE:=25559040
156 IMAGES := factory.img sysupgrade.tar
157 KERNEL_SIZE := 1920k
158 KERNEL := dtb | kernel-bin | lzma | uImage lzma | pad-offset $$(BLOCKSIZE) 64 | append-fakerootfs
159 KERNEL_INITRAMFS := kernel-bin | gzip | dtb | wndr4700-specialImage gzip
160 IMAGE/factory.img := create-uImage-dtb | append-kernel | pad-to 2M | append-ubi | \
161 netgear-dni | check-size $$$$(IMAGE_SIZE)
162 IMAGE/sysupgrade.tar := sysupgrade-tar
163 NETGEAR_BOARD_ID := WNDR4700
164 NETGEAR_HW_ID := 29763875+128+256
165 endef
166 TARGET_DEVICES += WNDR4700
167
168 endif
169
170 ifeq ($(SUBTARGET),sata)
171
172 ### Image scripts for the WD My Book Live Series ###
173 define Build/boot-script
174 $(STAGING_DIR_HOST)/bin/mkimage -A powerpc -T script -C none -n "$(PROFILE) Boot Script" \
175 -d mbl_boot.scr \
176 $@.scr
177 endef
178
179 define Build/boot-img
180 $(RM) -rf $@.bootdir
181 mkdir -p $@.bootdir/boot
182
183 $(CP) $@.scr $@.bootdir/boot/boot.scr
184 $(CP) $(IMAGE_KERNEL).dtb $@.bootdir/boot/$(DEVICE_DTB)
185 $(CP) $(IMAGE_KERNEL) $@.bootdir/boot/uImage
186
187 genext2fs --block-size $(BLOCKSIZE:%k=%Ki) --size-in-blocks $$((1024 * $(BOOT_SIZE))) --root $@.bootdir $@.boot
188
189 # convert it to revision 1 - needed for u-boot ext2load
190 $(STAGING_DIR_HOST)/bin/tune2fs -O filetype $@.boot
191 $(STAGING_DIR_HOST)/bin/e2fsck -pDf $@.boot > /dev/null
192 endef
193
194 define Build/hdd-img
195 ./mbl_gen_hdd_img.sh $@ $@.boot $(IMAGE_ROOTFS)
196 $(if $(CONFIG_TARGET_IMAGES_GZIP),gzip -9n -c $@ > $(BIN_DIR)/$(notdir $@).gz)
197 endef
198
199 define Build/uRamdisk
200 $(STAGING_DIR_HOST)/bin/mkimage \
201 -A powerpc -T ramdisk -C gzip \
202 -n "$(DEVICE_NAME) rootfs" \
203 -d $@ $@.new
204 mv $@.new $@
205 endef
206
207 define Build/recovery-tar
208 sh ./mbl_gen_recovery_tar.sh \
209 --profile $(DEVICE_PROFILE) \
210 --dtb $(IMAGE_KERNEL).dtb \
211 --dtbname $(DEVICE_DTB) \
212 --kernel $(IMAGE_KERNEL) \
213 --rootfs $@ \
214 $@
215 endef
216
217 define Build/export-dtb
218 cp $(IMAGE_KERNEL).dtb $@
219 endef
220
221 define Device/MyBookLiveDefault
222 IMAGE_SIZE := 48m
223 BLOCKSIZE := 1024
224 DTB_SIZE := 16384
225 KERNEL := kernel-bin | dtb | gzip | uImage gzip
226 BOOT_SIZE := 8
227 IMAGES := rootfs.img recovery.tar kernel.dtb
228 DEVICE_DTB := apollo3g.dtb
229 FILESYSTEMS := ext4
230 IMAGE/kernel.dtb := export-dtb
231 IMAGE/rootfs.img := boot-script | boot-img | hdd-img
232 IMAGE/recovery.tar := append-rootfs | gzip | uRamdisk | recovery-tar
233 endef
234
235 define Device/MyBookLiveSingle
236 $(Device/MyBookLiveDefault)
237 DEVICE_TITLE := Western Digital My Book Live
238 DEVICE_DTS := apollo3g
239 DEVICE_PROFILE := apollo3g
240 endef
241
242 TARGET_DEVICES += MyBookLiveSingle
243
244 define Device/MyBookLiveDuo
245 $(Device/MyBookLiveDefault)
246 DEVICE_TITLE := Western Digital My Book Live Duo
247 DEVICE_PACKAGES := kmod-usb-dwc2 kmod-ledtrig-usbdev kmod-usb-storage kmod-fs-vfat wpad-mini
248 DEVICE_DTS := apollo3g-duo
249 DEVICE_PROFILE := ap2nc
250 endef
251
252 TARGET_DEVICES += MyBookLiveDuo
253
254 endif
255
256 $(eval $(call BuildImage))