mediatek: use CONFIG_TARGET_ROOTFS_PARTSIZE
[openwrt/staging/mkresin.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 $(CONFIG_TARGET_ROOTFS_PARTSIZE)M@48M \
62 ) \
63 $(if $(findstring emmc,$1), \
64 -t 0x2e -N production -p $(CONFIG_TARGET_ROOTFS_PARTSIZE)M@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 ifneq ($(CONFIG_MTK_BOOT_PARTSIZE),)
117 BOOTFS_BLOCK_SIZE := 1024
118 BOOTFS_BLOCKS := $(shell echo $$(($(CONFIG_MTK_BOOT_PARTSIZE)*1024*1024/$(BOOTFS_BLOCK_SIZE))))
119 endif
120
121 define Build/mtk-mmc-img
122 rm -f $@.boot
123 mkfs.fat -C $@.boot $(BOOTFS_BLOCKS)
124
125 if [ -r $(STAGING_DIR_IMAGE)/$(UBOOT_TARGET)-preloader.bin ]; then \
126 ./gen_mtk_mmc_img.sh emmc $@.emmc \
127 $(STAGING_DIR_IMAGE)/$(UBOOT_TARGET)-preloader.bin; \
128 mcopy -i $@.boot $@.emmc ::eMMCboot.bin; \
129 fi
130 mkenvimage -s $(UBOOT_ENVSIZE) -o $(STAGING_DIR_IMAGE)/$(UBOOT_TARGET)-uboot.env $(UBOOT_TARGET)-uEnv.txt
131 mcopy -i $@.boot $(STAGING_DIR_IMAGE)/$(UBOOT_TARGET)-uboot.env ::uboot.env
132 mcopy -i $@.boot $(IMAGE_KERNEL) ::uImage
133 ./gen_mtk_mmc_img.sh sd $@ \
134 $(STAGING_DIR_IMAGE)/$(UBOOT_TARGET)-preloader.bin \
135 $(STAGING_DIR_IMAGE)/$(UBOOT_TARGET)-u-boot*.bin \
136 $(UBOOT_OFFSET) \
137 $@.boot \
138 $(IMAGE_ROOTFS) \
139 $(CONFIG_MTK_BOOT_PARTSIZE) \
140 104
141 endef
142
143 define Build/scatterfile
144 ./gen_scatterfile.sh $(subst mt,MT,$(SUBTARGET)) "$1" \
145 $(subst -scatter.txt,,$(notdir $@)) "$(DEVICE_TITLE)" > $@
146 endef
147
148
149 # Full eMMC image including U-Boot and partition table
150 define Device/unielec_u7623-emmc
151 DEVICE_VENDOR := UniElec
152 DEVICE_MODEL := U7623
153 DEVICE_VARIANT := eMMC
154 # When we use FIT images, U-Boot will populate the /memory node with the correct
155 # memory size discovered from the preloader, so we don't need separate builds.
156 DEVICE_DTS := mt7623a-unielec-u7623-02-emmc-512m
157 DEVICE_DTS_DIR := ../dts
158 SUPPORTED_DEVICES := unielec,u7623-02-emmc-512m
159 UBOOT_ENVSIZE := 0x1000
160 UBOOT_OFFSET := 256k
161 UBOOT_TARGET := mt7623a_unielec_u7623
162 IMAGES := img.gz
163 IMAGE/img.gz := mtk-mmc-img | gzip | append-metadata
164 DEVICE_PACKAGES := kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1 kmod-mmc \
165 mkf2fs e2fsprogs kmod-usb-ohci kmod-usb2 kmod-usb3 kmod-ata-ahci-mtk
166 ARTIFACT/scatter.txt := scatterfile $$(firstword $$(FILESYSTEMS))-$$(firstword $$(IMAGES))
167 ARTIFACTS := scatter.txt
168 endef
169 TARGET_DEVICES += unielec_u7623-emmc
170
171 # Legacy partial image for U7623
172 # This preserves the vendor U-Boot and starts with a uImage at 0xA00
173 define Device/unielec_u7623-02-emmc-512m-legacy
174 DEVICE_VENDOR := UniElec
175 DEVICE_MODEL := U7623-02
176 DEVICE_VARIANT := eMMC/512MiB RAM (legacy image)
177 DEVICE_DTS := mt7623a-unielec-u7623-02-emmc-512m
178 DEVICE_DTS_DIR := ../dts
179 KERNEL_NAME := zImage
180 KERNEL := kernel-bin | append-dtb | uImage none
181 KERNEL_INITRAMFS := kernel-bin | append-dtb | uImage none
182 DEVICE_PACKAGES := kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1 kmod-mmc \
183 mkf2fs e2fsprogs kmod-usb-ohci kmod-usb2 kmod-usb3 kmod-ata-ahci-mtk
184 IMAGES := sysupgrade-emmc.bin.gz
185 IMAGE/sysupgrade-emmc.bin.gz := sysupgrade-emmc | gzip | append-metadata
186 SUPPORTED_DEVICES := unielec,u7623-02-emmc-512m
187 endef
188 TARGET_DEVICES += unielec_u7623-02-emmc-512m-legacy