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