summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-ast2600/recipes-bsp/u-boot/files/0016-Add-system-reset-status-support.patch
blob: 1b0d4d95b5bc1c87fec5e2a5fd6ba96961a4d523 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
From ea8f8aa37182b66893ac9afcbbb4d5043b3b4166 Mon Sep 17 00:00:00 2001
From: Yong Li <yong.b.li@linux.intel.com>
Date: Tue, 9 Apr 2019 14:42:05 +0800
Subject: [PATCH] Add system reset status support

Will display the reset reasons and other CPU information in u-boot,
and save the reset reasons into kernel command line,
for applications to query.

Change-Id: I87ada3ecf14368519e4d09035bb1e09fdc05469b
Signed-off-by: Yong Li <yong.b.li@linux.intel.com>
Signed-off-by: AppaRao Puli <apparao.puli@linux.intel.com>
Signed-off-by: Jae Hyun Yoo <jae.hyun.yoo@intel.com>
---
 arch/arm/mach-aspeed/ast2600/scu_info.c |  4 ++
 board/aspeed/ast2600_intel/intel.c      | 65 +++++++++++++++++++++++++
 include/asm-generic/global_data.h       |  3 ++
 3 files changed, 72 insertions(+)

diff --git a/arch/arm/mach-aspeed/ast2600/scu_info.c b/arch/arm/mach-aspeed/ast2600/scu_info.c
index fe26f743c0ca..18514c812018 100644
--- a/arch/arm/mach-aspeed/ast2600/scu_info.c
+++ b/arch/arm/mach-aspeed/ast2600/scu_info.c
@@ -9,6 +9,8 @@
 #include <asm/io.h>
 #include <asm/arch/aspeed_scu_info.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 /* SoC mapping Table */
 #define SOC_ID(str, rev) { .name = str, .rev_id = rev, }
 
@@ -263,6 +265,8 @@ void aspeed_print_sysrst_info(void)
 			writel(SYS_EXT_RESET, ASPEED_SYS_RESET_CTRL);
 		}	
 	}
+
+	gd->reset_reason = rest;
 }
 
 #define SOC_FW_INIT_DRAM		BIT(7)
diff --git a/board/aspeed/ast2600_intel/intel.c b/board/aspeed/ast2600_intel/intel.c
index 0d1ce69b6e53..849e81ff3fef 100644
--- a/board/aspeed/ast2600_intel/intel.c
+++ b/board/aspeed/ast2600_intel/intel.c
@@ -5,6 +5,7 @@
 #include <common.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
+#include <malloc.h>
 
 /* use GPIOC0 on intel boards */
 #define FFUJ_GPIO "gpio@1e78000016"
@@ -292,6 +293,65 @@ int board_early_init_r(void)
 	return 0;
 }
 
+static void update_bootargs_cmd(const char *key, const char *value)
+{
+	int buf_len;
+	char *buf;
+	char *cmdline;
+	char comp_key[128];
+
+	if (!key || (key[0] == '\0')) {
+		printf("%s - Empty key not allowed\n", __func__);
+		return;
+	}
+
+	cmdline = env_get("bootargs");
+
+	/* Allocate space for maximum possible new command line */
+	if (value)
+		buf_len = strlen(cmdline) + strlen(key) + 3 + strlen(value);
+	else
+		buf_len = strlen(cmdline) + strlen(key) + 3;
+
+	buf = malloc(buf_len);
+	if (!buf) {
+		printf("%s: out of memory\n", __func__);
+		return;
+	}
+	memset(buf, 0, buf_len);
+
+	if (!cmdline) {
+		/* lets add key-value, though bootargs are empty */
+		snprintf(buf, buf_len, "%s=%s", key, (value ? value : ""));
+		env_set("bootargs", buf);
+		free(buf);
+		return;
+	}
+
+	snprintf(comp_key, sizeof(comp_key), "%s=", key);
+	char *start = strstr(cmdline, comp_key);
+
+	/* Check for full word match. Match should be start of cmdline
+	 * or there should be space before match */
+	if (start && ((start == cmdline) || (*(start-1) == ' '))) {
+		char *end = strchr(start, ' ');
+		strncpy(buf, cmdline, (start - cmdline));
+
+		if (end)
+			snprintf(buf, buf_len, "%s%s=%s %s", buf, key,
+				 (value ? value : ""), end+1);
+		else
+			snprintf(buf, buf_len, "%s%s=%s", buf, key,
+				 (value ? value : ""));
+	} else {
+		snprintf(buf, buf_len, "%s %s=%s", cmdline, key,
+			 (value ? value : ""));
+	}
+
+	env_set("bootargs", buf);
+	free(buf);
+}
+
 extern void espi_init(void);
 extern void kcs_init(void);
 extern void timer_enable(int n, u32 interval_us, interrupt_handler_t *handler,
@@ -301,12 +361,17 @@ int board_late_init(void)
 #define SCU_014			0x014		/* Silicon Revision ID */
 #define REV_ID_AST2600A0	0x05000303	/* AST2600 A0 */
 #define ONE_MSEC_IN_USEC	1000
+	char value[11];
 
 	if (readl(SCU_BASE | SCU_014) == REV_ID_AST2600A0)
 		timer_enable(0, ONE_MSEC_IN_USEC, timer_callback, (void *)0);
 
 	espi_init();
 
+	/* Add reset reason to bootargs */
+	snprintf(value, sizeof(value), "0x%x", gd->reset_reason);
+	update_bootargs_cmd("resetreason", value);
+
 	if (read_ffuj())
 		kcs_init();
 
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index 78dcf40bff48..fa51e384520f 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -133,6 +133,9 @@ typedef struct global_data {
 	struct spl_handoff *spl_handoff;
 # endif
 #endif
+#ifdef CONFIG_ARCH_ASPEED
+	u32 reset_reason;
+#endif
 } gd_t;
 #endif
 
-- 
2.17.1