mediatek: mt7622: add spi-nand support for bananapi bpi-r64
authorOskari Lemmela <oskari@lemmela.net>
Sat, 10 Apr 2021 17:16:08 +0000 (20:16 +0300)
committerDaniel Golle <daniel@makrotopia.org>
Sun, 11 Apr 2021 19:19:44 +0000 (20:19 +0100)
Some of bpi-r64 boards have serial NAND attached to SPI bus.
Add SD card image support for installing openwrt to it.
Default to nand upgrade if root device is not mmc block device.

Separate preloader and uboot images for snand are generated.

Signed-off-by: Oskari Lemmela <oskari@lemmela.net>
target/linux/mediatek/image/mt7622.mk
target/linux/mediatek/mt7622/base-files/lib/upgrade/platform.sh
target/linux/mediatek/patches-5.10/115-dts-bpi64-add-snand-support.patch [new file with mode: 0644]
target/linux/mediatek/patches-5.4/115-dts-bpi64-add-snand-support.patch [new file with mode: 0644]

index 3901800bcb24e178c9d37d5410f52de8970fe9ed..58dc578d391213af197b4b143ba4bbd613ec36b1 100644 (file)
@@ -76,9 +76,11 @@ define Device/bananapi_bpi-r64
   DEVICE_DTS := mt7622-bananapi-bpi-r64
   DEVICE_DTS_OVERLAY := mt7622-bananapi-bpi-r64-pcie1 mt7622-bananapi-bpi-r64-sata
   DEVICE_PACKAGES := kmod-ata-ahci-mtk kmod-btmtkuart kmod-usb3 e2fsprogs mkf2fs f2fsck
-  ARTIFACTS := sdcard.img.gz
+  ARTIFACTS := sdcard.img.gz snand-preloader.bin snand-bl31-uboot.fip
   IMAGES := sysupgrade.itb
   KERNEL_INITRAMFS_SUFFIX := -recovery.itb
+  ARTIFACT/snand-preloader.bin := bl2 snand-2ddr
+  ARTIFACT/snand-bl31-uboot.fip        := bl31-uboot bananapi_bpi-r64-snand
   ARTIFACT/sdcard.img.gz       := mt7622-gpt sdmmc |\
                                   pad-to 512k | bl2 sdmmc-2ddr |\
                                   pad-to 2048k | bl31-uboot bananapi_bpi-r64-sdmmc |\
@@ -86,6 +88,8 @@ define Device/bananapi_bpi-r64
                                   pad-to 38912k | mt7622-gpt emmc |\
                                   pad-to 39424k | bl2 emmc-2ddr |\
                                   pad-to 40960k | bl31-uboot bananapi_bpi-r64-emmc |\
+                                  pad-to 43008k | bl2 snand-2ddr |\
+                                  pad-to 43520k | bl31-uboot bananapi_bpi-r64-snand |\
                                   pad-to 46080k | append-image squashfs-sysupgrade.itb | gzip
   KERNEL                       := kernel-bin | gzip
   KERNEL_INITRAMFS             := kernel-bin | lzma | fit lzma $$(DTS_DIR)/$$(DEVICE_DTS).dtb with-initrd | pad-to 128k
index 2c1460650fc54102fd88e459548e6166c2142b3d..cdae06e63033d4ab6814f285c725cbc0cf4dc3cb 100755 (executable)
@@ -10,16 +10,24 @@ platform_do_upgrade() {
        bananapi,bpi-r64)
                export_bootdevice
                export_partdevice rootdev 0
-               local fitpart=$(get_partition_by_name $rootdev "production")
-               [ "$fitpart" ] || return 1
-               dd if=/dev/zero of=/dev/$fitpart bs=4096 count=1 2>/dev/null
-               blockdev --rereadpt /dev/$rootdev
-               get_image "$1" | dd of=/dev/$fitpart
-               blockdev --rereadpt /dev/$rootdev
-               local datapart=$(get_partition_by_name $rootdev "rootfs_data")
-               [ "$datapart" ] || return 0
-               dd if=/dev/zero of=/dev/$datapart bs=4096 count=1 2>/dev/null
-               echo $datapart > /tmp/sysupgrade.datapart
+               case "$rootdev" in
+               mmc*)
+                       local fitpart=$(get_partition_by_name $rootdev "production")
+                       [ "$fitpart" ] || return 1
+                       dd if=/dev/zero of=/dev/$fitpart bs=4096 count=1 2>/dev/null
+                       blockdev --rereadpt /dev/$rootdev
+                       get_image "$1" | dd of=/dev/$fitpart
+                       blockdev --rereadpt /dev/$rootdev
+                       local datapart=$(get_partition_by_name $rootdev "rootfs_data")
+                       [ "$datapart" ] || return 0
+                       dd if=/dev/zero of=/dev/$datapart bs=4096 count=1 2>/dev/null
+                       echo $datapart > /tmp/sysupgrade.datapart
+                       ;;
+               *)
+                       CI_KERNPART="fit"
+                       nand_do_upgrade "$1"
+                       ;;
+               esac
                ;;
        buffalo,wsr-2533dhp2)
                local magic="$(get_magic_long "$1")"
@@ -87,7 +95,11 @@ platform_copy_config_mmc() {
 platform_copy_config() {
        case "$(board_name)" in
        bananapi,bpi-r64)
-               platform_copy_config_mmc
+               export_bootdevice
+               export_partdevice rootdev 0
+               if echo $rootdev | grep -q mmc; then
+                       platform_copy_config_mmc
+               fi
                ;;
        esac
 }
diff --git a/target/linux/mediatek/patches-5.10/115-dts-bpi64-add-snand-support.patch b/target/linux/mediatek/patches-5.10/115-dts-bpi64-add-snand-support.patch
new file mode 100644 (file)
index 0000000..aa0e347
--- /dev/null
@@ -0,0 +1,57 @@
+--- a/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts 2021-03-13 13:46:37.057936814 +0200
++++ b/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts 2021-03-13 13:49:26.957481217 +0200
+@@ -114,7 +114,7 @@
+ };
+ &bch {
+-      status = "disabled";
++      status = "okay";
+ };
+ &btif {
+@@ -259,14 +259,40 @@
+       status = "disabled";
+ };
+-&nor_flash {
++&snfi {
+       pinctrl-names = "default";
+-      pinctrl-0 = <&spi_nor_pins>;
+-      status = "disabled";
++      pinctrl-0 = <&serial_nand_pins>;
++      status = "okay";
+-      flash@0 {
+-              compatible = "jedec,spi-nor";
++      snand: spi_nand@0 {
++              #address-cells = <1>;
++              #size-cells = <1>;
++              compatible = "spi-nand";
++              spi-max-frequency = <104000000>;
+               reg = <0>;
++
++              partitions {
++                      compatible = "fixed-partitions";
++                      #address-cells = <1>;
++                      #size-cells = <1>;
++
++                      partition@0 {
++                              label = "bl2";
++                              reg = <0x0 0x80000>;
++                              read-only;
++                      };
++
++                      partition@80000 {
++                              label = "fip";
++                              reg = <0x80000 0x200000>;
++                              read-only;
++                      };
++
++                      partition@280000 {
++                              label = "ubi";
++                              reg = <0x280000 0x7d80000>;
++                      };
++              };
+       };
+ };
diff --git a/target/linux/mediatek/patches-5.4/115-dts-bpi64-add-snand-support.patch b/target/linux/mediatek/patches-5.4/115-dts-bpi64-add-snand-support.patch
new file mode 100644 (file)
index 0000000..aa0e347
--- /dev/null
@@ -0,0 +1,57 @@
+--- a/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts 2021-03-13 13:46:37.057936814 +0200
++++ b/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts 2021-03-13 13:49:26.957481217 +0200
+@@ -114,7 +114,7 @@
+ };
+ &bch {
+-      status = "disabled";
++      status = "okay";
+ };
+ &btif {
+@@ -259,14 +259,40 @@
+       status = "disabled";
+ };
+-&nor_flash {
++&snfi {
+       pinctrl-names = "default";
+-      pinctrl-0 = <&spi_nor_pins>;
+-      status = "disabled";
++      pinctrl-0 = <&serial_nand_pins>;
++      status = "okay";
+-      flash@0 {
+-              compatible = "jedec,spi-nor";
++      snand: spi_nand@0 {
++              #address-cells = <1>;
++              #size-cells = <1>;
++              compatible = "spi-nand";
++              spi-max-frequency = <104000000>;
+               reg = <0>;
++
++              partitions {
++                      compatible = "fixed-partitions";
++                      #address-cells = <1>;
++                      #size-cells = <1>;
++
++                      partition@0 {
++                              label = "bl2";
++                              reg = <0x0 0x80000>;
++                              read-only;
++                      };
++
++                      partition@80000 {
++                              label = "fip";
++                              reg = <0x80000 0x200000>;
++                              read-only;
++                      };
++
++                      partition@280000 {
++                              label = "ubi";
++                              reg = <0x280000 0x7d80000>;
++                      };
++              };
+       };
+ };