uclient: update to Git HEAD (2024-04-19)
[openwrt/openwrt.git] / target / linux / gemini / image / Makefile
1 # SPDX-License-Identifier: GPL-2.0-only
2 #
3 # Copyright (C) 2009-2018 OpenWrt.org
4
5 include $(TOPDIR)/rules.mk
6 include $(INCLUDE_DIR)/image.mk
7
8 define Build/copy-kernel.bin
9 $(call locked,$(MAKE) -C copy-kernel CROSS_COMPILE=$(TARGET_CROSS) O=$(KDIR),gemini-copy-kernel.bin)
10 endef
11
12 # Cook a "WRGG" image, this board is apparently one in the D-Link
13 # WRGG family and uses the exact same firmware format as other
14 # D-Link devices.
15 define Build/dir685-image
16 mkwrggimg -i $@ \
17 -o $@.new \
18 -d /dev/mtdblock/1 \
19 -s wrgns01_dlwbr_dir685RBWW \
20 -v 'N/A' \
21 -m dir685 \
22 -B 96bb
23
24 mv $@.new $@
25 endef
26
27 # Padding added after the rootfs to an even 128k boundary
28 # as this is 128k eraseblocks flash.
29 define Build/dir685-pad-rootfs
30 $(STAGING_DIR_HOST)/bin/padjffs2 $(IMAGE_ROOTFS) -c 128 >>$@
31 endef
32
33 # Build D-Link DNS-313 images using the special header tool.
34 # rootfs.tgz and rd.tgz contains nothing, we only need them
35 # to satisfy the boot loader on the device. The zImage is
36 # the only real content.
37 define Build/dns313-images
38 mkdir -p $@.tmp/.boot
39 chmod 755 $@.tmp/.boot
40
41 echo "dummy" > $@.tmp/dummyfile
42
43 dns313-header $@.tmp/dummyfile \
44 $@.tmp/.boot/rootfs.tgz
45 dns313-header $@.tmp/dummyfile \
46 $@.tmp/.boot/rd.gz
47 dns313-header $(IMAGE_KERNEL) \
48 $@.tmp/.boot/zImage
49
50 rm $@.tmp/dummyfile
51
52 genext2fs --block-size $(BLOCKSIZE:%k=%Ki) \
53 --size-in-blocks $$((1024 * $(CONFIG_TARGET_KERNEL_PARTSIZE))) \
54 --squash-uids \
55 --root $@.tmp $@.tmp-boot
56
57 # The device firmware needs revision 1 of EXT2
58 tune2fs -O filetype $@.tmp-boot
59 e2fsck -pDf $@.tmp-boot > /dev/null
60
61 ./dns313_gen_hdd_img.sh $@ $@.tmp-boot $(IMAGE_ROOTFS) \
62 $(CONFIG_TARGET_KERNEL_PARTSIZE) \
63 $(CONFIG_TARGET_ROOTFS_PARTSIZE)
64
65 rm -rf $@.tmp
66 endef
67
68 define Build/wiligear-image
69 $(STAGING_DIR_HOST)/bin/mkfwimage2 \
70 -m GEOS -f 0x30000000 -z \
71 -v $(1).v5.00.SL3512.OpenWrt.00000.000000.000000 \
72 -p Kernel:0x020000:0x100000:0:0:$(IMAGE_KERNEL) \
73 -p Ramdisk:0x120000:0x500000:0:0:$@ \
74 -o $@.new
75
76 mv $@.new $@
77 endef
78
79 # Create the default image format used by the StorLink reference design
80 # SL93512r, Raidsonic NAS4220B and Itian Square One SQ201
81 # with the squashfs and overlay inside the "application" partition.
82 #
83 # These devices have a hard-coded partition table that the boot loader
84 # constantly reflashes back, so we need to work around it like this:
85 #
86 # 0x000000120000-0x000000320000 : "Kern" - small copy routine and first
87 # part of the kernel goes here
88 # 0x000000320000-0x000000920000 : "Ramdisk" - second part of the kernel and
89 # some padding goes here
90 # 0x000000920000-0x000000f20000 : "Application" - rootfs goes here
91 define Build/storlink-default-images
92 mkdir -p $@.tmp
93
94 # "App" partition is the rootfs
95 mv $@ $@.tmp/hddapp.tgz
96 # 256 bytes copy routine
97 dd if=$(KDIR)/copy-kernel.bin of=$@.tmp/zImage
98 $(call Image/pad-to,$@.tmp/zImage,512)
99 # Copy first part of the kernel into zImage
100 dd if=$(IMAGE_KERNEL) of=$@.tmp/zImage bs=1 seek=512 count=2096640
101 # Put the rest of the kernel into the "ramdisk"
102 dd if=$(IMAGE_KERNEL) of=$@.tmp/rd.gz bs=1 skip=2096640 count=6144k conv=sync
103 cp ./ImageInfo-$(1) $@.tmp/ImageInfo
104
105 sed -i -e "s/DATESTR/`date +%Y%m%d $(if $(SOURCE_DATE_EPOCH),--date "@$(SOURCE_DATE_EPOCH)")`/g" $@.tmp/ImageInfo
106
107 (cd $@.tmp; tar --sort=name --owner=0 --group=0 --numeric-owner -czf $@ * \
108 $(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)"))
109
110 rm -rf $@.tmp
111 endef
112
113 # WBD-111 and WBD-222:
114 # work around the bootloader's bug with extra nops
115 # FIXME: is this really needed now that we no longer append the code
116 # to change the machine ID number? Needs testing on Wiliboard.
117 define Build/wbd-nops
118 mv $@ $@.tmp
119 echo -en "\x00\x00\xa0\xe1\x00\x00\xa0\xe1\x00\x00\xa0\xe1\x00\x00\xa0\xe1" > $@
120 cat $@.tmp >> $@
121 rm -f $@.tmp
122 endef
123
124 # All DTB files are prefixed with "gemini-"
125 define Device/Default
126 PROFILES := Default
127 KERNEL_DEPENDS = $$(wildcard $(DTS_DIR)/$$(DEVICE_DTS).dts)
128 KERNEL_NAME := zImage
129 KERNEL := kernel-bin | append-dtb
130 BLOCKSIZE := 128k
131 endef
132
133 # A reasonable set of default packages handling the NAS type
134 # of devices out of the box (former NAS42x0 IcyBox defaults)
135 GEMINI_NAS_PACKAGES := $(DEFAULT_PACKAGES.nas) \
136 kmod-md-mod kmod-md-linear kmod-md-multipath \
137 kmod-md-raid0 kmod-md-raid1 kmod-md-raid10 kmod-md-raid456 \
138 kmod-fs-btrfs kmod-fs-cifs kmod-fs-nfs \
139 kmod-fs-nfsd kmod-fs-ntfs kmod-fs-reiserfs kmod-fs-vfat \
140 kmod-nls-utf8 kmod-usb-storage-extras kmod-hwmon-drivetemp \
141 cfdisk e2fsprogs badblocks \
142 partx-utils
143
144 # The DIR-685 flash layout is kernel in WRGG format, padded and followed
145 # by the appended rootfs followed by some reasonable JFFS padding, the
146 # remainder will be used by JFFS2 through overlayfs.
147 #
148 # - For the factory image, the WRGG image includes the rootfs so that the
149 # default firmware will flash it properly as all it knows is WRGG format.
150 # - For the sysupgrade, we do not include the rootfs in the kernel image
151 # so it is not needelessly tossed into the RAM by the boot loader.
152 # This will be flashed from OpenWrt userland anyways so we only need
153 # the minimum to make the boot loader happy.
154 define Device/dlink_dir-685
155 DEVICE_VENDOR := D-Link
156 DEVICE_MODEL := DIR-685 Xtreme N Storage Router
157 DEVICE_DTS := gemini-dlink-dir-685
158 DEVICE_PACKAGES := $(GEMINI_NAS_PACKAGES) \
159 kmod-rt2800-pci
160 IMAGES := factory.bin sysupgrade.bin
161 # Pad to 128k erase blocks with 160 bytes WRGG header
162 IMAGE/factory.bin := append-kernel | pad-offset 128k 160 | append-rootfs | dir685-pad-rootfs | dir685-image
163 IMAGE/sysupgrade.bin := append-kernel | pad-offset 128k 160 | dir685-image | append-rootfs | dir685-pad-rootfs | append-metadata
164 endef
165 TARGET_DEVICES += dlink_dir-685
166
167 define Device/dlink_dns-313
168 DEVICE_VENDOR := D-Link
169 DEVICE_MODEL := DNS-313 1-Bay Network Storage Enclosure
170 DEVICE_DTS := gemini-dlink-dns-313
171 DEVICE_PACKAGES := $(GEMINI_NAS_PACKAGES)
172 BLOCKSIZE := 1k
173 FILESYSTEMS := ext4
174 IMAGES := factory.bin.gz
175 IMAGE/factory.bin.gz := dns313-images | gzip
176 endef
177 TARGET_DEVICES += dlink_dns-313
178
179 # Default images setup used by the StorLink reference designs
180 define Device/storlink-reference
181 COMPILE := copy-kernel-$(1).bin
182 COMPILE/copy-kernel-$(1).bin := copy-kernel.bin
183 IMAGES := factory.bin
184 FILESYSTEMS := squashfs
185 IMAGE/factory.bin := append-rootfs | pad-rootfs | pad-to 6144k | \
186 storlink-default-images $(1)
187 DEVICE_PACKAGES := $(GEMINI_NAS_PACKAGES)
188 endef
189
190 define Device/itian_sq201
191 $(Device/storlink-reference)
192 DEVICE_VENDOR := ITian
193 DEVICE_MODEL := Square One SQ201
194 DEVICE_DTS := gemini-sq201
195 DEVICE_PACKAGES += kmod-rt61-pci kmod-usb2-pci
196 endef
197 TARGET_DEVICES += itian_sq201
198
199 define Device/raidsonic_ib-4220-b
200 $(Device/storlink-reference)
201 DEVICE_VENDOR := Raidsonic
202 DEVICE_MODEL := NAS IB-4220-B
203 DEVICE_DTS := gemini-nas4220b
204 endef
205 TARGET_DEVICES += raidsonic_ib-4220-b
206
207 define Device/storlink_sl93512r
208 $(Device/storlink-reference)
209 DEVICE_VENDOR := StorLink
210 DEVICE_MODEL := SL93512r
211 DEVICE_DTS := gemini-sl93512r
212 endef
213 TARGET_DEVICES += storlink_sl93512r
214
215
216 # The wiliboard images need some changes to be functional and buildable.
217 #
218 # The dts would need to use the ecoscentric,redboot-fis-partitions partition
219 # parser to get the correct partition offsets and size.
220 #
221 # The mkfwimage2 call need to be adjusted to reflect the real size of kernel
222 # and rootfs. It is expected that the OEM firmware adjusts the on flash
223 # partition table with the values defined in the image header.
224 define Device/wiliboard_wbd111
225 DEVICE_VENDOR := Wiliboard
226 DEVICE_MODEL := WBD-111
227 DEVICE_DTS := gemini-wbd111
228 KERNEL := kernel-bin | append-dtb | wbd-nops
229 IMAGES := factory.bin
230 IMAGE/factory.bin := append-rootfs | pad-rootfs | wiligear-image "WILI-S.WILIBOARD"
231 endef
232
233 define Device/wiliboard_wbd222
234 DEVICE_VENDOR := Wiliboard
235 DEVICE_MODEL := WBD-222
236 DEVICE_DTS := gemini-wbd222
237 KERNEL := kernel-bin | append-dtb | wbd-nops
238 IMAGES := factory.bin
239 IMAGE/factory.bin := append-rootfs | pad-rootfs | wiligear-image "WILI-S.WBD222"
240 endef
241
242 $(eval $(call BuildImage))