[openwrt/openwrt] uboot-mediaktek: add support for PSTORE and check it on boot

LEDE Commits lede-commits at lists.infradead.org
Sat May 8 15:37:43 PDT 2021


dangole pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/cc201759b69e6e61736005864d99cdac44b7e19f

commit cc201759b69e6e61736005864d99cdac44b7e19f
Author: Daniel Golle <daniel at makrotopia.org>
AuthorDate: Fri May 7 16:47:26 2021 +0100

    uboot-mediaktek: add support for PSTORE and check it on boot
    
    Add support for pstore/ramoops now that DRAM content is preserved
    over reboot on MT7622. On each boot, check pstore and boot to recovery
    image in case there are records stored in it.
    
    Signed-off-by: Daniel Golle <daniel at makrotopia.org>
---
 .../patches/050-mt7622-enable-pstore.patch         | 33 +++++++++
 .../patches/230-cmd-add-pstore-check.patch         | 78 ++++++++++++++++++++++
 .../404-add-bananapi_bpi-r64_defconfigs.patch      | 21 +++---
 .../patches/410-add-linksys-e8450.patch            |  7 +-
 .../patches/412-add-ubnt-unifi-6-lr.patch          |  7 +-
 5 files changed, 131 insertions(+), 15 deletions(-)

diff --git a/package/boot/uboot-mediatek/patches/050-mt7622-enable-pstore.patch b/package/boot/uboot-mediatek/patches/050-mt7622-enable-pstore.patch
new file mode 100644
index 0000000000..42d60c3f66
--- /dev/null
+++ b/package/boot/uboot-mediatek/patches/050-mt7622-enable-pstore.patch
@@ -0,0 +1,33 @@
+--- a/arch/arm/dts/mt7622.dtsi
++++ b/arch/arm/dts/mt7622.dtsi
+@@ -37,6 +37,30 @@
+ 		};
+ 	};
+ 
++	psci {
++		compatible  = "arm,psci-1.0";
++		method      = "smc";
++	};
++
++	reserved-memory {
++		#address-cells = <2>;
++		#size-cells = <2>;
++		ranges;
++
++		/* 64 KiB reserved for ramoops/pstore */
++		ramoops at 0x42ff0000 {
++			compatible = "ramoops";
++			reg = <0 0x42ff0000 0 0x10000>;
++			record-size = <0x1000>;
++		};
++
++		/* 192 KiB reserved for ARM Trusted Firmware (BL31) */
++		secmon_reserved: secmon at 43000000 {
++			reg = <0 0x43000000 0 0x30000>;
++			no-map;
++		};
++	};
++
+ 	snfi: snfi at 1100d000 {
+ 		compatible = "mediatek,mtk-snfi-spi";
+ 		reg = <0x1100d000 0x2000>;
diff --git a/package/boot/uboot-mediatek/patches/230-cmd-add-pstore-check.patch b/package/boot/uboot-mediatek/patches/230-cmd-add-pstore-check.patch
new file mode 100644
index 0000000000..587245d2ab
--- /dev/null
+++ b/package/boot/uboot-mediatek/patches/230-cmd-add-pstore-check.patch
@@ -0,0 +1,78 @@
+--- a/cmd/pstore.c
++++ b/cmd/pstore.c
+@@ -207,6 +207,58 @@ static int pstore_set(struct cmd_tbl *cm
+ }
+ 
+ /**
++ * pstore_check() - Check for pstore records
++ * @cmdtp: Command data struct pointer
++ * @flag: Command flag
++ * @argc: Command-line argument count
++ * @argv: Array of command-line arguments
++ *
++ * Return: 0 if there are records in pstore, 1 otherwise
++ */
++static int pstore_check(struct cmd_tbl *cmdtp, int flag,  int argc,
++			char * const argv[])
++{
++	phys_addr_t ptr;
++	char *buffer;
++	u32 size;
++	int header_len = 0;
++	bool compressed;
++
++	if (pstore_length == 0) {
++		printf("Please set PStore configuration\n");
++		return CMD_RET_USAGE;
++	}
++
++	if (buffer_size == 0)
++		pstore_init_buffer_size();
++
++	buffer = malloc_cache_aligned(buffer_size);
++
++	ptr = pstore_addr;
++	phys_addr_t ptr_end = ptr + pstore_length - pstore_pmsg_size
++			- pstore_ftrace_size - pstore_console_size;
++
++	while (ptr < ptr_end) {
++		size = pstore_get_buffer(PERSISTENT_RAM_SIG, ptr,
++					 pstore_record_size, buffer);
++		ptr += pstore_record_size;
++
++		if (size == 0)
++			continue;
++
++		header_len = pstore_read_kmsg_hdr(buffer, &compressed);
++		if (header_len == 0)
++			continue;
++
++		free(buffer);
++		return 0;
++	}
++
++	free(buffer);
++	return 1;
++}
++
++/**
+  * pstore_print_buffer() - Print buffer
+  * @type: buffer type
+  * @buffer: buffer to print
+@@ -458,6 +510,7 @@ static int pstore_save(struct cmd_tbl *c
+ 
+ static struct cmd_tbl cmd_pstore_sub[] = {
+ 	U_BOOT_CMD_MKENT(set, 8, 0, pstore_set, "", ""),
++	U_BOOT_CMD_MKENT(check, 1, 0, pstore_check, "", ""),
+ 	U_BOOT_CMD_MKENT(display, 3, 0, pstore_display, "", ""),
+ 	U_BOOT_CMD_MKENT(save, 4, 0, pstore_save, "", ""),
+ };
+@@ -531,6 +584,8 @@ U_BOOT_CMD(pstore, 10, 0, do_pstore,
+ 	   "  'pmsg-size' is the size of the user space logs record.\n"
+ 	   "  'ecc-size' enables/disables ECC support and specifies ECC buffer size in\n"
+ 	   "  bytes (0 disables it, 1 is a special value, means 16 bytes ECC).\n"
++	   "pstore check\n"
++	   "- Returns true if there are records in pstore.\n"
+ 	   "pstore display [record-type] [nb]\n"
+ 	   "- Display existing records in pstore reserved memory. A 'record-type' can\n"
+ 	   "  be given to only display records of this kind. 'record-type' can be one\n"
diff --git a/package/boot/uboot-mediatek/patches/404-add-bananapi_bpi-r64_defconfigs.patch b/package/boot/uboot-mediatek/patches/404-add-bananapi_bpi-r64_defconfigs.patch
index ceaa15045e..72913e4d2f 100644
--- a/package/boot/uboot-mediatek/patches/404-add-bananapi_bpi-r64_defconfigs.patch
+++ b/package/boot/uboot-mediatek/patches/404-add-bananapi_bpi-r64_defconfigs.patch
@@ -1,6 +1,6 @@
 --- /dev/null
 +++ b/configs/mt7622_bananapi_bpi-r64-sdmmc_defconfig
-@@ -0,0 +1,157 @@
+@@ -0,0 +1,158 @@
 +CONFIG_ARM=y
 +CONFIG_POSITION_INDEPENDENT=y
 +CONFIG_ARCH_MEDIATEK=y
@@ -74,7 +74,8 @@
 +CONFIG_CMD_UBIFS=y
 +CONFIG_CMD_ASKENV=y
 +CONFIG_CMD_PART=y
-+# CONFIG_CMD_PSTORE is not set
++CONFIG_CMD_PSTORE=y
++CONFIG_CMD_PSTORE_MEM_ADDR=0x42ff0000
 +CONFIG_CMD_RARP=y
 +CONFIG_CMD_SETEXPR=y
 +CONFIG_CMD_SLEEP=y
@@ -165,7 +166,7 @@
 +serverip=192.168.1.254
 +loadaddr=0x4007ff28
 +bootargs=root=/dev/mmcblk1p65
-+bootcmd=run boot_sdmmc
++bootcmd=if pstore check ; then run boot_recovery ; else run boot_sdmmc ; fi
 +bootconf=config-mt7622-bananapi-bpi-r64-pcie1
 +bootconf_pcie=config-mt7622-bananapi-bpi-r64-pcie1
 +bootconf_sata=config-mt7622-bananapi-bpi-r64-sata
@@ -244,7 +245,7 @@
 +_bootmenu_update_title=setenv _bootmenu_update_title ; setenv bootmenu_title "$bootmenu_title       $ver"
 --- /dev/null
 +++ b/configs/mt7622_bananapi_bpi-r64-emmc_defconfig
-@@ -0,0 +1,144 @@
+@@ -0,0 +1,145 @@
 +CONFIG_ARM=y
 +CONFIG_POSITION_INDEPENDENT=y
 +CONFIG_ARCH_MEDIATEK=y
@@ -313,7 +314,8 @@
 +CONFIG_CMD_TFTPSRV=y
 +CONFIG_CMD_ASKENV=y
 +CONFIG_CMD_PART=y
-+# CONFIG_CMD_PSTORE is not set
++CONFIG_CMD_PSTORE=y
++CONFIG_CMD_PSTORE_MEM_ADDR=0x42ff0000
 +CONFIG_CMD_RARP=y
 +CONFIG_CMD_SETEXPR=y
 +CONFIG_CMD_SLEEP=y
@@ -395,7 +397,7 @@
 +ipaddr=192.168.1.1
 +serverip=192.168.1.254
 +loadaddr=0x4007ff28
-+bootcmd=run boot_emmc
++bootcmd=if pstore check ; then run boot_recovery ; else run boot_emmc ; fi
 +bootargs=root=/dev/mmcblk0p65
 +bootconf=config-mt7622-bananapi-bpi-r64-pcie1
 +bootconf_pcie=config-mt7622-bananapi-bpi-r64-pcie1
@@ -448,7 +450,7 @@
 +_bootmenu_update_title=setenv _bootmenu_update_title ; setenv bootmenu_title "$bootmenu_title       $ver"
 --- /dev/null
 +++ b/configs/mt7622_bananapi_bpi-r64-snand_defconfig
-@@ -0,0 +1,138 @@
+@@ -0,0 +1,139 @@
 +CONFIG_ARM=y
 +CONFIG_POSITION_INDEPENDENT=y
 +CONFIG_ARCH_MEDIATEK=y
@@ -519,7 +521,8 @@
 +CONFIG_CMD_UBIFS=y
 +CONFIG_CMD_ASKENV=y
 +CONFIG_CMD_PART=y
-+# CONFIG_CMD_PSTORE is not set
++CONFIG_CMD_PSTORE=y
++CONFIG_CMD_PSTORE_MEM_ADDR=0x42ff0000
 +CONFIG_CMD_RARP=y
 +CONFIG_CMD_SETEXPR=y
 +CONFIG_CMD_SLEEP=y
@@ -594,7 +597,7 @@
 +serverip=192.168.1.254
 +loadaddr=0x4007ff28
 +bootargs=root=/dev/ubiblock0_2p1
-+bootcmd=run boot_ubi
++bootcmd=if pstore check ; then run boot_recovery ; else run boot_ubi ; fi
 +bootconf=config-mt7622-bananapi-bpi-r64-pcie1
 +bootconf_pcie=config-mt7622-bananapi-bpi-r64-pcie1
 +bootconf_sata=config-mt7622-bananapi-bpi-r64-sata
diff --git a/package/boot/uboot-mediatek/patches/410-add-linksys-e8450.patch b/package/boot/uboot-mediatek/patches/410-add-linksys-e8450.patch
index a6eb40f1d2..f09a7db137 100644
--- a/package/boot/uboot-mediatek/patches/410-add-linksys-e8450.patch
+++ b/package/boot/uboot-mediatek/patches/410-add-linksys-e8450.patch
@@ -1,6 +1,6 @@
 --- /dev/null
 +++ b/configs/mt7622_linksys_e8450_defconfig
-@@ -0,0 +1,133 @@
+@@ -0,0 +1,134 @@
 +CONFIG_ARM=y
 +CONFIG_POSITION_INDEPENDENT=y
 +CONFIG_ARCH_MEDIATEK=y
@@ -69,7 +69,8 @@
 +CONFIG_CMD_UBIFS=y
 +CONFIG_CMD_ASKENV=y
 +CONFIG_CMD_PART=y
-+# CONFIG_CMD_PSTORE is not set
++CONFIG_CMD_PSTORE=y
++CONFIG_CMD_PSTORE_MEM_ADDR=0x42ff0000
 +CONFIG_CMD_RARP=y
 +CONFIG_CMD_SETEXPR=y
 +CONFIG_CMD_SLEEP=y
@@ -350,7 +351,7 @@
 +ipaddr=192.168.1.1
 +serverip=192.168.1.254
 +loadaddr=0x4007ff28
-+bootcmd=run boot_ubi
++bootcmd=if pstore check ; then run boot_recovery ; else run boot_ubi ; fi
 +bootdelay=0
 +bootfile=openwrt-mediatek-mt7622-linksys_e8450-ubi-initramfs-recovery.itb
 +bootfile_bl2=openwrt-mediatek-mt7622-linksys_e8450-ubi-preloader.bin
diff --git a/package/boot/uboot-mediatek/patches/412-add-ubnt-unifi-6-lr.patch b/package/boot/uboot-mediatek/patches/412-add-ubnt-unifi-6-lr.patch
index 8e8fe04a07..d9b8a01f73 100644
--- a/package/boot/uboot-mediatek/patches/412-add-ubnt-unifi-6-lr.patch
+++ b/package/boot/uboot-mediatek/patches/412-add-ubnt-unifi-6-lr.patch
@@ -1,6 +1,6 @@
 --- /dev/null
 +++ b/configs/mt7622_ubnt_unifi-6-lr_defconfig
-@@ -0,0 +1,138 @@
+@@ -0,0 +1,139 @@
 +CONFIG_ARM=y
 +CONFIG_POSITION_INDEPENDENT=y
 +CONFIG_ARCH_MEDIATEK=y
@@ -72,7 +72,8 @@
 +CONFIG_CMD_TFTPSRV=y
 +# CONFIG_CMD_UNLZ4 is not set
 +CONFIG_CMD_ASKENV=y
-+# CONFIG_CMD_PSTORE is not set
++CONFIG_CMD_PSTORE=y
++CONFIG_CMD_PSTORE_MEM_ADDR=0x42ff0000
 +CONFIG_CMD_RARP=y
 +CONFIG_CMD_SETEXPR=y
 +CONFIG_CMD_SLEEP=y
@@ -362,7 +363,7 @@
 +ipaddr=192.168.1.1
 +serverip=192.168.1.254
 +loadaddr=0x40080000
-+bootcmd=run boot_nor
++bootcmd=if pstore check ; then run boot_recovery ; else run boot_nor ; fi
 +bootdelay=0
 +bootfile=openwrt-mediatek-mt7622-ubnt_unifi-6-lr-ubootmod-initramfs-recovery.itb
 +bootfile_bl2=openwrt-mediatek-mt7622-ubnt_unifi-6-lr-ubootmod-preloader.bin



More information about the lede-commits mailing list