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