ar71xx: image: rework EnGenius ENS202EXT factory image
[openwrt/openwrt.git] / target / linux / ar71xx / image / common-tp-link.mk
1 DEVICE_VARS += LOADER_FLASH_OFFS TPLINK_BOARD_ID TPLINK_FLASHLAYOUT TPLINK_HEADER_VERSION TPLINK_HWID TPLINK_HWREV
2
3 define Build/copy-file
4 cat "$(1)" > "$@"
5 endef
6
7 define Build/loader-okli
8 dd if=$(KDIR)/loader-$(1).gz bs=7680 conv=sync of="$@.new"
9 cat "$@" >> "$@.new"
10 mv "$@.new" "$@"
11 endef
12
13 define Build/loader-okli-compile
14 $(call Build/loader-common,FLASH_OFFS=$(LOADER_FLASH_OFFS) FLASH_MAX=0 KERNEL_CMDLINE="$(CMDLINE)")
15 endef
16
17 # combine kernel and rootfs into one image
18 # mktplinkfw <type> <optional extra arguments to mktplinkfw binary>
19 # <type> is "sysupgrade" or "factory"
20 #
21 # -a align the rootfs start on an <align> bytes boundary
22 # -j add jffs2 end-of-filesystem markers
23 # -s strip padding from end of the image
24 # -X reserve <size> bytes in the firmware image (hexval prefixed with 0x)
25 define Build/mktplinkfw
26 -$(STAGING_DIR_HOST)/bin/mktplinkfw \
27 -H $(TPLINK_HWID) -W $(TPLINK_HWREV) -F $(TPLINK_FLASHLAYOUT) -N OpenWrt -V $(REVISION) \
28 -m $(TPLINK_HEADER_VERSION) \
29 -k $(IMAGE_KERNEL) \
30 -r $@ \
31 -o $@.new \
32 -j -X 0x40000 \
33 -a $(call rootfs_align,$(FILESYSTEM)) \
34 $(wordlist 2,$(words $(1)),$(1)) \
35 $(if $(findstring sysupgrade,$(word 1,$(1))),-s) && mv $@.new $@ || rm -f $@
36 endef
37
38 define Build/uImageArcher
39 mkimage -A $(LINUX_KARCH) \
40 -O linux -T kernel \
41 -C $(1) -a $(KERNEL_LOADADDR) -e $(if $(KERNEL_ENTRY),$(KERNEL_ENTRY),$(KERNEL_LOADADDR)) \
42 -n '$(call toupper,$(LINUX_KARCH)) OpenWrt Linux-$(LINUX_VERSION)' -d $@ $@.new
43 @mv $@.new $@
44 endef
45
46
47 define Device/tplink
48 TPLINK_HWREV := 0x1
49 TPLINK_HEADER_VERSION := 1
50 LOADER_TYPE := gz
51 KERNEL := kernel-bin | patch-cmdline | lzma
52 KERNEL_INITRAMFS := kernel-bin | patch-cmdline | lzma | tplink-v1-header
53 IMAGES := sysupgrade.bin factory.bin
54 IMAGE/sysupgrade.bin := append-rootfs | mktplinkfw sysupgrade
55 IMAGE/factory.bin := append-rootfs | mktplinkfw factory
56 endef
57
58 define Device/tplink-nolzma
59 $(Device/tplink)
60 LOADER_FLASH_OFFS := 0x22000
61 COMPILE := loader-$(1).gz
62 COMPILE/loader-$(1).gz := loader-okli-compile
63 KERNEL := copy-file $(KDIR)/vmlinux.bin.lzma | uImage lzma -M 0x4f4b4c49 | loader-okli $(1)
64 KERNEL_INITRAMFS := copy-file $(KDIR)/vmlinux-initramfs.bin.lzma | loader-kernel-cmdline | tplink-v1-header
65 endef
66
67 define Device/tplink-4m
68 $(Device/tplink-nolzma)
69 TPLINK_FLASHLAYOUT := 4M
70 IMAGE_SIZE := 3904k
71 endef
72
73 define Device/tplink-8m
74 $(Device/tplink-nolzma)
75 TPLINK_FLASHLAYOUT := 8M
76 IMAGE_SIZE := 7936k
77 endef
78
79 define Device/tplink-4mlzma
80 $(Device/tplink)
81 TPLINK_FLASHLAYOUT := 4Mlzma
82 IMAGE_SIZE := 3904k
83 endef
84
85 define Device/tplink-8mlzma
86 $(Device/tplink)
87 TPLINK_FLASHLAYOUT := 8Mlzma
88 IMAGE_SIZE := 7936k
89 endef
90
91 define Device/tplink-16mlzma
92 $(Device/tplink)
93 TPLINK_FLASHLAYOUT := 16Mlzma
94 IMAGE_SIZE := 15872k
95 endef