ramips: add support for PCI based OHCI/EHCI support for F5D8235 V1
[lede.git] / include / image-commands.mk
1 # Build commands that can be called from Device/* templates
2
3 IMAGE_KERNEL = $(word 1,$^)
4 IMAGE_ROOTFS = $(word 2,$^)
5
6 define Build/uImage
7         mkimage -A $(LINUX_KARCH) \
8                 -O linux -T kernel \
9                 -C $(1) -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
10                 -n '$(if $(UIMAGE_NAME),$(UIMAGE_NAME),$(call toupper,$(LINUX_KARCH)) LEDE Linux-$(LINUX_VERSION))' -d $@ $@.new
11         @mv $@.new $@
12 endef
13
14 define Build/netgear-chk
15         $(STAGING_DIR_HOST)/bin/mkchkimg \
16                 -o $@.new \
17                 -k $@ \
18                 -b $(NETGEAR_BOARD_ID) \
19                 -r $(NETGEAR_REGION)
20         mv $@.new $@
21 endef
22
23 define Build/netgear-dni
24         $(STAGING_DIR_HOST)/bin/mkdniimg \
25                 -B $(NETGEAR_BOARD_ID) -v LEDE.$(REVISION) \
26                 $(if $(NETGEAR_HW_ID),-H $(NETGEAR_HW_ID)) \
27                 -r "$(1)" \
28                 -i $@ -o $@.new
29         mv $@.new $@
30 endef
31
32 define Build/tplink-safeloader
33        -$(STAGING_DIR_HOST)/bin/tplink-safeloader \
34                 -B $(TPLINK_BOARD_NAME) \
35                 -V $(REVISION) \
36                 -k $(IMAGE_KERNEL) \
37                 -r $@ \
38                 -o $@.new \
39                 -j \
40                 $(wordlist 2,$(words $(1)),$(1)) \
41                 $(if $(findstring sysupgrade,$(word 1,$(1))),-S) && mv $@.new $@ || rm -f $@
42 endef
43
44 define Build/append-dtb
45         $(call Image/BuildDTB,$(if $(DEVICE_DTS_DIR),$(DEVICE_DTS_DIR),$(DTS_DIR))/$(DEVICE_DTS).dts,$@.dtb)
46         cat $@.dtb >> $@
47 endef
48
49 define Build/install-dtb
50         $(foreach dts,$(DEVICE_DTS), \
51                 $(CP) \
52                         $(DTS_DIR)/$(dts).dtb \
53                         $(BIN_DIR)/$(IMG_PREFIX)-$(dts).dtb; \
54         )
55 endef
56
57 define Build/fit
58         $(TOPDIR)/scripts/mkits.sh \
59                 -D $(DEVICE_NAME) -o $@.its -k $@ \
60                 $(if $(word 2,$(1)),-d $(word 2,$(1))) -C $(word 1,$(1)) \
61                 -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
62                 -A $(ARCH) -v $(LINUX_VERSION)
63         PATH=$(LINUX_DIR)/scripts/dtc:$(PATH) mkimage -f $@.its $@.new
64         @mv $@.new $@
65 endef
66
67 define Build/lzma
68         $(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
69 endef
70
71 define Build/lzma-no-dict
72         $(STAGING_DIR_HOST)/bin/lzma e $@ $(1) $@.new
73         @mv $@.new $@
74 endef
75
76 define Build/gzip
77         gzip -9n -c $@ $(1) > $@.new
78         @mv $@.new $@
79 endef
80
81 define Build/jffs2
82         rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 && \
83                 mkdir -p $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$$(dirname $(1)) && \
84                 cp $@ $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/$(1) && \
85                 $(STAGING_DIR_HOST)/bin/mkfs.jffs2 --pad \
86                         $(if $(CONFIG_BIG_ENDIAN),--big-endian,--little-endian) \
87                         --squash-uids -v -e $(patsubst %k,%KiB,$(BLOCKSIZE)) \
88                         -o $@.new \
89                         -d $(KDIR_TMP)/$(DEVICE_NAME)/jffs2 \
90                         2>&1 1>/dev/null | awk '/^.+$$$$/' && \
91                 $(STAGING_DIR_HOST)/bin/padjffs2 $@.new -J $(patsubst %k,,$(BLOCKSIZE))
92         -rm -rf $(KDIR_TMP)/$(DEVICE_NAME)/jffs2/
93         @mv $@.new $@
94 endef
95
96 define Build/kernel-bin
97         rm -f $@
98         cp $< $@
99 endef
100
101 define Build/patch-cmdline
102         $(STAGING_DIR_HOST)/bin/patch-cmdline $@ '$(CMDLINE)'
103 endef
104
105 define Build/append-kernel
106         dd if=$(IMAGE_KERNEL) >> $@
107 endef
108
109 define Build/append-rootfs
110         dd if=$(IMAGE_ROOTFS) >> $@
111 endef
112
113 define Build/append-ubi
114         sh $(TOPDIR)/scripts/ubinize-image.sh \
115                 $(if $(UBOOTENV_IN_UBI),--uboot-env) \
116                 $(if $(KERNEL_IN_UBI),--kernel $(IMAGE_KERNEL)) \
117                 $(foreach part,$(UBINIZE_PARTS),--part $(part)) \
118                 $(IMAGE_ROOTFS) \
119                 $@.tmp \
120                 -p $(BLOCKSIZE:%k=%KiB) -m $(PAGESIZE) \
121                 $(if $(SUBPAGESIZE),-s $(SUBPAGESIZE)) \
122                 $(if $(VID_HDR_OFFSET),-O $(VID_HDR_OFFSET)) \
123                 $(UBINIZE_OPTS)
124         cat $@.tmp >> $@
125         rm $@.tmp
126 endef
127
128 define Build/pad-to
129         dd if=$@ of=$@.new bs=$(1) conv=sync
130         mv $@.new $@
131 endef
132
133 define Build/pad-extra
134         dd if=/dev/zero bs=$(1) count=1 >> $@
135 endef
136
137 define Build/pad-rootfs
138         $(STAGING_DIR_HOST)/bin/padjffs2 $@ $(1) \
139                 $(if $(BLOCKSIZE),$(BLOCKSIZE:%k=%),4 8 16 64 128 256)
140 endef
141
142 define Build/pad-offset
143         let \
144                 size="$$(stat -c%s $@)" \
145                 pad="$(subst k,* 1024,$(word 1, $(1)))" \
146                 offset="$(subst k,* 1024,$(word 2, $(1)))" \
147                 pad="(pad - ((size + offset) % pad)) % pad" \
148                 newsize='size + pad'; \
149                 dd if=$@ of=$@.new bs=$$newsize count=1 conv=sync
150         mv $@.new $@
151 endef
152
153 define Build/check-size
154         @[ $$(($(subst k,* 1024,$(subst m, * 1024k,$(1))))) -ge "$$(stat -c%s $@)" ] || { \
155                 echo "WARNING: Image file $@ is too big" >&2; \
156                 rm -f $@; \
157         }
158 endef
159
160 define Build/combined-image
161         -sh $(TOPDIR)/scripts/combined-image.sh \
162                 "$(IMAGE_KERNEL)" \
163                 "$@" \
164                 "$@.new"
165         @mv $@.new $@
166 endef
167
168 define Build/sysupgrade-tar
169         sh $(TOPDIR)/scripts/sysupgrade-tar.sh \
170                 --board $(if $(BOARD_NAME),$(BOARD_NAME),$(DEVICE_NAME)) \
171                 --kernel $(call param_get_default,kernel,$(1),$(IMAGE_KERNEL)) \
172                 --rootfs $(call param_get_default,rootfs,$(1),$(IMAGE_ROOTFS)) \
173                 $@
174 endef
175
176 json_quote=$(subst ','\'',$(subst ",\",$(1)))
177 #")')
178 metadata_devices=$(if $(1),$(subst "$(space)","$(comma)",$(strip $(foreach v,$(1),"$(call json_quote,$(v))"))))
179 metadata_json = \
180         '{ $(if $(IMAGE_METADATA),$(IMAGE_METADATA)$(comma)) \
181                 "supported_devices":[$(call metadata_devices,$(1))], \
182                 "version": { \
183                         "dist": "$(call json_quote,$(VERSION_DIST))", \
184                         "version": "$(call json_quote,$(VERSION_NUMBER))", \
185                         "revision": "$(call json_quote,$(REVISION))", \
186                         "board": "$(call json_quote,$(BOARD))" \
187                 } \
188         }'
189
190 define Build/append-metadata
191         $(if $(SUPPORTED_DEVICES),echo $(call metadata_json,$(SUPPORTED_DEVICES)) | fwtool -I - $@)
192 endef