blob: fa1413fa7c9a7e952642560fd6c9c97c50d539aa [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*********************************************************************
2 Copyright 2016 by ZIXCCorporation.
3*
4* FileName:: boot_mode.c
5* File Mark:
6* Description:
7* Others:
8* Version: v1.0
9* Author: zhouqi
10* Date: 2014-1-15
11
12* History 1:
13* Date:
14* Version:
15* Author:
16* Modification:
17* History 2:
18**********************************************************************/
19
20#include <common.h>
21#include <errno.h>
22#include <asm/io.h>
23#include <boot_mode.h>
24#include <load_image.h>
25#include <zx234290.h>
26#include <power.h>
27#include <config.h>
28#include <partition_table.h>
29#include <linux/mtd/compat.h>
30
31#define NVRWALL_PATH "/nvrwall.bin"
32#ifdef CONFIG_ZX297520V3E_MDL_AB
33extern int imagefs_flag;
34#endif
35
36int g_iftype = IF_TYPE_UNKNOWN; // initialize to UNKNOWN DEVICE
37boot_reason_t g_boot_reason = RB_POWER_KEY;
38u_char ucBootReason1st = 0xff;
39u_char ucBootReason2nd = 0xff;
40
41u_char battery_detect_flag = 0xff;
42
43int nvrw_flag_init(void)
44{
45 u_char *p_boot_reason = NULL;
46 char cmd[64] = {0};
47
48#ifdef CONFIG_ZX297520V3E_MDL_AB
49 if(imagefs_flag == 1)
50 sprintf(cmd, "fsload imagefs 0x%x %s", (ulong)CONFIG_SYS_SDRAM_TEMP_BASE, NVRWALL_PATH);
51 else
52 sprintf(cmd, "fsload imagefs2 0x%x %s", (ulong)CONFIG_SYS_SDRAM_TEMP_BASE, NVRWALL_PATH);
53#else
54 sprintf(cmd, "fsload imagefs 0x%x %s", (ulong)CONFIG_SYS_SDRAM_TEMP_BASE, NVRWALL_PATH);
55#endif
56 run_command(cmd, 0);
57
58 p_boot_reason = (u_char*)CONFIG_SYS_SDRAM_TEMP_BASE;
59
60 ucBootReason1st = *(p_boot_reason + ARM_AMT_FLAG_OFFSET);
61 ucBootReason2nd = *(p_boot_reason + ARM_AMT_FLAG_OFFSET + 1);
62
63 battery_detect_flag = *(p_boot_reason + ARM_DRV_PERIPHERAL_OFFSET);
64 if(battery_detect_flag != 0)
65 {
66 battery_detect_flag = 1;
67 }
68
69 printf("ucBootReason1st=0x%x, ucBootReason2nd=0x%x, battery_detect_flag=0x%x\n",
70 ucBootReason1st, ucBootReason2nd, battery_detect_flag);
71
72 return 0;
73}
74
75int get_battery_detect_flag(void)
76{
77 if(battery_detect_flag != 0)
78 {
79 return 1;
80 }
81
82 return 0;
83}
84
85
86
87/*******************************************************************************
88 * Function: get_load_mode
89 * Description:»ñÈ¡loadµÄģʽ£¬Ê¹UBOOT½øÈëÏàÓ¦µÄģʽ
90 * Parameters:
91 * Input:
92 *
93 * Output:
94 *
95 * Returns:
96 *
97 *
98 * Others: Z-Load ---> uboot µÄÕý³£Æô¶¯Ä£Ê½
99 T-Load ---> uboot µÄÏÂÔØÄ£Ê½:
100 ********************************************************************************/
101load_mode_t get_load_mode( void )
102{
103 uint32_t mode = readl(CFG_BOOT_MODE_SAVE_ADDR_FOR_UBOOT);
104
105 if( mode == CFG_TLOAD_MODE )
106 {
107 return TLOAD_MODE;
108 }
109 else if( mode == CFG_ZLOAD_MODE )
110 {
111 return ZLOAD_MODE;
112 }
113 else
114 {
115 return UNKNOWN_LOAD_MODE;
116 }
117}
118
119
120/*******************************************************************************
121 * Function:
122 * Description: get_boot_reason
123 * Parameters: »ñÈ¡¿ª»úÔ­Òò
124 * Input:
125 *
126 * Output:
127 *
128 * Returns:
129 *
130 *
131 * Others:
132 ********************************************************************************/
133int get_boot_reason(void)
134{
135 int ret = 0;
136
137 /* ´Ótsp_nvrw_0x00050000.binµÄǰÁ½¸ö×Ö½ÚÅÐ¶ÏÆô¶¯·½Ê½
138 * Èç¹ûΪ¡°TM¡±£¨¼´£º0x54,0x4D£©£¬ÔòÅÐΪAMTģʽ
139 * ·ñÔòΪÕý³£°æ±¾ */
140 if((0x54 == ucBootReason1st) && (0x4D == ucBootReason2nd))
141 {
142 g_boot_reason = RB_AMT;
143 }
144 else if((0x54 == ucBootReason1st) && (0x02 == ucBootReason2nd))
145 {
146 g_boot_reason = RB_PRODUCTION;
147 }
148 else
149 {
150 struct pmu_opt *pmu = get_pmu_opt();
151 ret = pmu->get_boot_reason(&g_boot_reason);
152 ret += get_fota_update_flag();
153 }
154 BOOT_PRINTF(UBOOT_DBG, "g_boot_reason=0x%x, ret=0x%x.\n", g_boot_reason, ret);
155 return ret;
156}
157
158/*******************************************************************************
159 * Function: read_boot_reason
160 * Description:
161 * Parameters:
162 * Input:
163 *
164 * Output:
165 *
166 * Returns:
167 *
168 *
169 * Others:
170 ********************************************************************************/
171boot_reason_t read_boot_reason(void)
172{
173 return g_boot_reason;
174}
175
176
177void get_boot_flashtype(void)
178{
179 uint32_t type = readl(CFG_BOOT_MODE_START_MODE_FOR_UBOOT);
180
181 switch( type )
182 {
183 case CFG_START_MODE_NAND:
184 g_iftype = IF_TYPE_NAND;
185 break;
186 case CFG_START_MODE_SPI_NAND:
187 g_iftype = IF_TYPE_SPI_NAND;
188 break;
189 case CFG_START_MODE_SDIO:
190 g_iftype = IF_TYPE_SD;
191 break;
192 case CFG_START_MODE_EMMC:
193 g_iftype = IF_TYPE_MMC;
194 break;
195 case CFG_START_MODE_NOR:
196 g_iftype = IF_TYPE_NOR;
197 break;
198 default:
199 g_iftype = IF_TYPE_UNKNOWN;
200 break;
201 }
202}
203
204int read_boot_flashtype(void)
205{
206 return g_iftype;
207}
208