mediatek: mt7623: add back needed build steps for U7623 board
[openwrt/openwrt.git] / target / linux / mediatek / image / mt7623.mk
1 KERNEL_LOADADDR := 0x80008000
2 DEVICE_VARS += UBOOT_TARGET UBOOT_OFFSET UBOOT_ENVSIZE
3
4 # The bootrom of MT7623 expects legacy MediaTek headers present in
5 # exactly the location also used for the primary GPT partition table.
6 # (*MMC_BOOT and BRLYT)
7 # Hence only MSDOS/MBR partitioning can work here.
8 #
9 # ------------------------ Sector Offset
10 # | MBR + SDMMC_BOOT | 0 0x0
11 # |----------------------|
12 # | BRLYT header | 1 0x200
13 # |----------------------|
14 # . .
15 # . .
16 # |----------------------|
17 # | | 4 0x800
18 # | |
19 # | Preloader |
20 # . .
21 # . .
22 # | | 639
23 # |----------------------|
24 # | MBR partition #1 | 640 0x50000
25 # | |
26 # | U-Boot |
27 # . .
28 # . .
29 # | | 1663
30 # |----------------------|
31 # | MBR partition #2 |
32 # | |
33 # | Recovery |
34 # . .
35 # . (uImage.FIT) .
36 # | |
37 # |----------------------|
38 # | MBR partition #3 |
39 # | |
40 # | Production |
41 # | |
42 # | (uImage.FIT, |
43 # . rootfs_Data.) .
44 # . .
45 # | |
46 # ------------------------
47 #
48 # For eMMC boot, everything up to and including the preloader must be
49 # written to /dev/mmcblk0boot0, with the SDMMC_BOOT header changed to
50 # read EMMC_BOOT\0 instead.
51 #
52 # The contents of the main eMMC are identical to the SD card layout,
53 # with the preloader loading 512KiB of U-Boot starting at 0x50000.
54
55 define Build/mt7623-mbr
56 cp $@ $@.tmp 2>/dev/null || true
57 ptgen -o $@.tmp -h 4 -s 63 -a 0 -l 1024 \
58 -t 0x41 -N uboot -p 3584k@320k \
59 -t 0xea -N recovery -p 40M@4M \
60 $(if $(findstring sdmmc,$1), \
61 -t 0x2e -N production -p 208M@48M \
62 ) \
63 $(if $(findstring emmc,$1), \
64 -t 0x2e -N production -p 976M@48M \
65 )
66
67 echo -en \
68 $(if $(findstring sdmmc,$1),"SDMMC_BOOT\x00\x00\x01\x00\x00\x00\x00\x02\x00\x00") \
69 $(if $(findstring emmc,$1),"EMMC_BOOT\x00\x00\x00\x01\x00\x00\x00\x00\x02\x00\x00") \
70 | dd bs=1 of="$@.tmp" seek=0 conv=notrunc
71
72 echo -en "BRLYT\x00\x00\x00\x01\x00\x00\x00\x00\x08\x00\x00\x00\x08\x00\x00\x42\x42\x42\x42\x08\x00\x01\x00\x00\x08\x00\x00\x00\x08\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"\
73 | dd bs=1 of="$@.tmp" seek=512 conv=notrunc
74
75 cat $@.tmp >> $@
76 rm $@.tmp
77 endef
78
79 define Build/append-preloader
80 cat $(STAGING_DIR_IMAGE)/$1-preloader.bin >> $@
81 endef
82
83 define Build/append-bootloader
84 cat $(STAGING_DIR_IMAGE)/$1-u-boot.bin >> $@
85 endef
86
87 define Device/bananapi_bpi-r2
88 DEVICE_VENDOR := Bananapi
89 DEVICE_MODEL := BPi-R2
90 DEVICE_DTS := mt7623n-bananapi-bpi-r2
91 DEVICE_PACKAGES := mkf2fs e2fsprogs kmod-usb3 kmod-ata-ahci
92 UBOOT_ENVSIZE := 0x10000
93 UBOOT_OFFSET := 320k
94 UBOOT_TARGET := mt7623n_bpir2
95 UBOOT_PATH := $(STAGING_DIR_IMAGE)/mt7623n_bpir2-u-boot.bin
96 IMAGES := sysupgrade.itb
97 KERNEL := kernel-bin | gzip
98 KERNEL_INITRAMFS_SUFFIX := -recovery.itb
99 KERNEL_INITRAMFS := kernel-bin | gzip | fit gzip $$(DTS_DIR)/$$(DEVICE_DTS).dtb with-initrd
100 IMAGE/sysupgrade.itb := append-kernel | fit gzip $$(DTS_DIR)/$$(DEVICE_DTS).dtb external-static-with-rootfs | append-metadata
101 ARTIFACT/preloader.bin := append-preloader $$(UBOOT_TARGET)
102 ARTIFACT/u-boot.bin := append-uboot
103 ARTIFACT/sdcard.img.gz := mt7623-mbr sdmmc |\
104 pad-to 2k | append-preloader $$(UBOOT_TARGET) |\
105 pad-to 320k | append-bootloader $$(UBOOT_TARGET) |\
106 pad-to 4092k | mt7623-mbr emmc |\
107 pad-to 4M | append-image-stage initramfs-recovery.itb |\
108 pad-to 48M | append-image squashfs-sysupgrade.itb |\
109 gzip
110 ARTIFACTS = u-boot.bin preloader.bin scatter.txt sdcard.img.gz
111 SUPPORTED_DEVICES := bananapi,bpi-r2
112 endef
113 TARGET_DEVICES += bananapi_bpi-r2
114
115
116 define Build/mtk-mmc-img
117 rm -f $@.boot
118 mkfs.fat -C $@.boot $(BOOTFS_BLOCKS)
119
120 if [ -r $(STAGING_DIR_IMAGE)/$(UBOOT_TARGET)-preloader.bin ]; then \
121 ./gen_mtk_mmc_img.sh emmc $@.emmc \
122 $(STAGING_DIR_IMAGE)/$(UBOOT_TARGET)-preloader.bin; \
123 mcopy -i $@.boot $@.emmc ::eMMCboot.bin; \
124 fi
125 mkenvimage -s $(UBOOT_ENVSIZE) -o $(STAGING_DIR_IMAGE)/$(UBOOT_TARGET)-uboot.env $(UBOOT_TARGET)-uEnv.txt
126 mcopy -i $@.boot $(STAGING_DIR_IMAGE)/$(UBOOT_TARGET)-uboot.env ::uboot.env
127 mcopy -i $@.boot $(IMAGE_KERNEL) ::uImage
128 ./gen_mtk_mmc_img.sh sd $@ \
129 $(STAGING_DIR_IMAGE)/$(UBOOT_TARGET)-preloader.bin \
130 $(STAGING_DIR_IMAGE)/$(UBOOT_TARGET)-u-boot*.bin \
131 $(UBOOT_OFFSET) \
132 $@.boot \
133 $(IMAGE_ROOTFS) \
134 $(CONFIG_MTK_BOOT_PARTSIZE) \
135 $(CONFIG_TARGET_ROOTFS_PARTSIZE)
136 endef
137
138 define Build/scatterfile
139 ./gen_scatterfile.sh $(subst mt,MT,$(SUBTARGET)) "$1" \
140 $(subst -scatter.txt,,$(notdir $@)) "$(DEVICE_TITLE)" > $@
141 endef
142
143 # Full eMMC image including U-Boot and partition table
144 define Device/unielec_u7623-emmc
145 DEVICE_VENDOR := UniElec
146 DEVICE_MODEL := U7623
147 DEVICE_VARIANT := eMMC
148 # When we use FIT images, U-Boot will populate the /memory node with the correct
149 # memory size discovered from the preloader, so we don't need separate builds.
150 DEVICE_DTS := mt7623a-unielec-u7623-02-emmc-512m
151 DEVICE_DTS_DIR := ../dts
152 SUPPORTED_DEVICES := unielec,u7623-02-emmc-512m
153 UBOOT_ENVSIZE := 0x1000
154 UBOOT_OFFSET := 256k
155 UBOOT_TARGET := mt7623a_unielec_u7623
156 IMAGES := img.gz
157 IMAGE/img.gz := mtk-mmc-img | gzip | append-metadata
158 DEVICE_PACKAGES := kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1 kmod-mmc \
159 mkf2fs e2fsprogs kmod-usb-ohci kmod-usb2 kmod-usb3 kmod-ata-ahci-mtk
160 ARTIFACT/scatter.txt := scatterfile $$(firstword $$(FILESYSTEMS))-$$(firstword $$(IMAGES))
161 ARTIFACTS := scatter.txt
162 endef
163 TARGET_DEVICES += unielec_u7623-emmc
164
165 # Legacy partial image for U7623
166 # This preserves the vendor U-Boot and starts with a uImage at 0xA00
167 define Device/unielec_u7623-02-emmc-512m-legacy
168 DEVICE_VENDOR := UniElec
169 DEVICE_MODEL := U7623-02
170 DEVICE_VARIANT := eMMC/512MiB RAM (legacy image)
171 DEVICE_DTS := mt7623a-unielec-u7623-02-emmc-512m
172 DEVICE_DTS_DIR := ../dts
173 KERNEL_NAME := zImage
174 KERNEL := kernel-bin | append-dtb | uImage none
175 KERNEL_INITRAMFS := kernel-bin | append-dtb | uImage none
176 DEVICE_PACKAGES := kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1 kmod-mmc \
177 mkf2fs e2fsprogs kmod-usb-ohci kmod-usb2 kmod-usb3 kmod-ata-ahci-mtk
178 IMAGES := sysupgrade-emmc.bin.gz
179 IMAGE/sysupgrade-emmc.bin.gz := sysupgrade-emmc | gzip | append-metadata
180 SUPPORTED_DEVICES := unielec,u7623-02-emmc-512m
181 endef
182 TARGET_DEVICES += unielec_u7623-02-emmc-512m-legacy