Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0+ OR MIT) |
| 2 | /* |
| 3 | * Copyright (c) 2019 Amlogic, Inc. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <command.h> |
| 8 | #include <asm/amlogic/arch/reboot.h> |
| 9 | #include <asm/amlogic/arch/secure_apb.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <asm/amlogic/arch/bl31_apis.h> |
| 12 | #include <amlogic/partition_table.h> |
| 13 | #include <amlogic/storage.h> |
| 14 | #include <asm/amlogic/arch/stick_mem.h> |
| 15 | /* |
| 16 | run get_rebootmode //set reboot_mode env with current mode |
| 17 | */ |
| 18 | |
| 19 | int do_get_rebootmode (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 20 | { |
| 21 | uint32_t reboot_mode_val; |
| 22 | |
| 23 | reboot_mode_val = ((readl(AO_SEC_SD_CFG15) >> 12) & 0xf); |
| 24 | //this step prevent the reboot mode val stored in sticky register lost |
| 25 | //during the reset |
| 26 | if (reboot_mode_val == 0) |
| 27 | reboot_mode_val |= stick_reboot_flag; |
| 28 | |
| 29 | debug("reboot_mode(0x%x)=0x%x\n", AO_SEC_SD_CFG15, reboot_mode_val); |
| 30 | |
| 31 | switch (reboot_mode_val) |
| 32 | { |
| 33 | case AMLOGIC_COLD_BOOT: |
| 34 | { |
| 35 | env_set("reboot_mode","cold_boot"); |
| 36 | break; |
| 37 | } |
| 38 | case AMLOGIC_NORMAL_BOOT: |
| 39 | { |
| 40 | env_set("reboot_mode","normal"); |
| 41 | break; |
| 42 | } |
| 43 | case AMLOGIC_FACTORY_RESET_REBOOT: |
| 44 | { |
| 45 | env_set("reboot_mode","factory_reset"); |
| 46 | break; |
| 47 | } |
| 48 | case AMLOGIC_UPDATE_REBOOT: |
| 49 | { |
| 50 | env_set("reboot_mode","update"); |
| 51 | break; |
| 52 | } |
| 53 | case AMLOGIC_FASTBOOT_REBOOT: |
| 54 | { |
| 55 | env_set("reboot_mode","fastboot"); |
| 56 | break; |
| 57 | } |
| 58 | case AMLOGIC_BOOTLOADER_REBOOT: |
| 59 | { |
| 60 | env_set("reboot_mode","bootloader"); |
| 61 | break; |
| 62 | } |
| 63 | case AMLOGIC_SUSPEND_REBOOT: |
| 64 | { |
| 65 | env_set("reboot_mode","suspend_off"); |
| 66 | break; |
| 67 | } |
| 68 | case AMLOGIC_HIBERNATE_REBOOT: |
| 69 | { |
| 70 | env_set("reboot_mode","hibernate"); |
| 71 | break; |
| 72 | } |
| 73 | case AMLOGIC_SHUTDOWN_REBOOT: |
| 74 | { |
| 75 | env_set("reboot_mode","shutdown_reboot"); |
| 76 | break; |
| 77 | } |
| 78 | case AMLOGIC_RESCUEPARTY_REBOOT: |
| 79 | { |
| 80 | env_set("reboot_mode", "rescueparty"); |
| 81 | break; |
| 82 | } |
| 83 | case AMLOGIC_KERNEL_PANIC: |
| 84 | { |
| 85 | env_set("reboot_mode","kernel_panic"); |
| 86 | break; |
| 87 | } |
| 88 | case AMLOGIC_WATCHDOG_REBOOT: |
| 89 | { |
| 90 | env_set("reboot_mode","watchdog_reboot"); |
| 91 | break; |
| 92 | } |
| 93 | case AMLOGIC_RPMBP_REBOOT: |
| 94 | { |
| 95 | env_set("reboot_mode","rpmbp"); |
| 96 | break; |
| 97 | } |
| 98 | case AMLOGIC_QUIESCENT_REBOOT: |
| 99 | { |
| 100 | env_set("reboot_mode","quiescent"); |
| 101 | break; |
| 102 | } |
| 103 | case AMLOGIC_RECOVERY_QUIESCENT_REBOOT: |
| 104 | { |
| 105 | env_set("reboot_mode","recovery_quiescent"); |
| 106 | break; |
| 107 | } |
| 108 | #ifdef AMLOGIC_FFV_REBOOT |
| 109 | case AMLOGIC_FFV_REBOOT: |
| 110 | { |
| 111 | env_set("reboot_mode", "ffv_reboot"); |
| 112 | break; |
| 113 | } |
| 114 | #endif |
| 115 | default: |
| 116 | { |
| 117 | env_set("reboot_mode","charging"); |
| 118 | break; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | #ifdef CONFIG_CMD_FASTBOOT |
| 123 | switch (reboot_mode_val) { |
| 124 | case AMLOGIC_FASTBOOT_REBOOT: { |
| 125 | env_set("reboot_mode","fastboot"); |
| 126 | break; |
| 127 | } |
| 128 | case AMLOGIC_BOOTLOADER_REBOOT: { |
| 129 | if (dynamic_partition) |
| 130 | env_set("reboot_mode","fastboot"); |
| 131 | break; |
| 132 | } |
| 133 | } |
| 134 | #endif |
| 135 | |
| 136 | #if defined(CONFIG_AML_RPMB) |
| 137 | run_command("rpmb_state",0); |
| 138 | #endif |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | int do_reboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 144 | { |
| 145 | uint32_t reboot_mode_val = AMLOGIC_NORMAL_BOOT; |
| 146 | if (argc <= 1) { |
| 147 | printf("reboot use default mode: normal\n"); |
| 148 | } |
| 149 | else { |
| 150 | printf("reboot mode: %s\n", argv[1]); |
| 151 | char * mode = argv[1]; |
| 152 | |
| 153 | if (strcmp(mode, "next") == 0) { |
| 154 | store_restore_bootidx(); |
| 155 | reboot_mode_val = AMLOGIC_COLD_BOOT; |
| 156 | } else if (strcmp(mode, "next,quiescent") == 0) { |
| 157 | store_restore_bootidx(); |
| 158 | reboot_mode_val = AMLOGIC_QUIESCENT_REBOOT; |
| 159 | } else if (strcmp(mode, "cold_boot") == 0) |
| 160 | reboot_mode_val = AMLOGIC_COLD_BOOT; |
| 161 | else if (strcmp(mode, "normal") == 0) |
| 162 | reboot_mode_val = AMLOGIC_NORMAL_BOOT; |
| 163 | else if (strcmp(mode, "recovery") == 0 || strcmp(mode, "factory_reset") == 0) |
| 164 | reboot_mode_val = AMLOGIC_FACTORY_RESET_REBOOT; |
| 165 | else if (strcmp(mode, "update") == 0) |
| 166 | reboot_mode_val = AMLOGIC_UPDATE_REBOOT; |
| 167 | else if (strcmp(mode, "fastboot") == 0) { |
| 168 | if (dynamic_partition) { |
| 169 | printf("dynamic partition, enter fastbootd"); |
| 170 | reboot_mode_val = AMLOGIC_FACTORY_RESET_REBOOT; |
| 171 | run_command("bcb fastbootd",0); |
| 172 | } else |
| 173 | reboot_mode_val = AMLOGIC_FASTBOOT_REBOOT; |
| 174 | } else if (strcmp(mode, "bootloader") == 0) |
| 175 | reboot_mode_val = AMLOGIC_BOOTLOADER_REBOOT; |
| 176 | else if (strcmp(mode, "suspend_off") == 0) |
| 177 | reboot_mode_val = AMLOGIC_SUSPEND_REBOOT; |
| 178 | else if (strcmp(mode, "hibernate") == 0) |
| 179 | reboot_mode_val = AMLOGIC_HIBERNATE_REBOOT; |
| 180 | else if (strcmp(mode, "rescueparty") == 0) |
| 181 | reboot_mode_val = AMLOGIC_RESCUEPARTY_REBOOT; |
| 182 | else if (strcmp(mode, "kernel_panic") == 0) |
| 183 | reboot_mode_val = AMLOGIC_KERNEL_PANIC; |
| 184 | else if (strcmp(mode, "rpmbp") == 0) |
| 185 | reboot_mode_val = AMLOGIC_RPMBP_REBOOT; |
| 186 | #ifdef AMLOGIC_FFV_REBOOT |
| 187 | else if (strcmp(mode, "ffv_reboot") == 0) |
| 188 | reboot_mode_val = AMLOGIC_FFV_REBOOT; |
| 189 | #endif |
| 190 | else { |
| 191 | printf("Can not find match reboot mode, use normal by default\n"); |
| 192 | reboot_mode_val = AMLOGIC_NORMAL_BOOT; |
| 193 | } |
| 194 | } |
| 195 | #ifdef CONFIG_USB_DEVICE_V2 |
| 196 | #if !(defined AML_USB_V2) |
| 197 | *P_RESET1_REGISTER |= (1<<17); |
| 198 | mdelay(200); |
| 199 | #endif |
| 200 | #endif |
| 201 | dcache_disable(); |
| 202 | |
| 203 | aml_reboot (PSCI_SYS_REBOOT, reboot_mode_val, 0, 0); |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | /* USB BOOT FUNC sub command list*/ |
| 208 | #define CLEAR_USB_BOOT 1 |
| 209 | #define FORCE_USB_BOOT 2 |
| 210 | #define RUN_COMD_USB_BOOT 3 |
| 211 | #define PANIC_DUMP_USB_BOOT 4 |
| 212 | |
| 213 | int do_set_usb_boot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 214 | { |
| 215 | unsigned int usb_mode = 0; |
| 216 | if (argc <= 1) { |
| 217 | printf("usb flag default 0\n"); |
| 218 | } |
| 219 | else { |
| 220 | usb_mode = simple_strtoul(argv[1], NULL, 16); |
| 221 | } |
| 222 | printf("usb flag: %d\n", usb_mode); |
| 223 | set_usb_boot_function(usb_mode); |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | U_BOOT_CMD( |
| 229 | get_rebootmode, 1, 0, do_get_rebootmode, |
| 230 | "get reboot mode", |
| 231 | "/N\n" |
| 232 | " This command will get and set env 'reboot_mode'\n" |
| 233 | "get_rebootmode\n" |
| 234 | ); |
| 235 | |
| 236 | U_BOOT_CMD( |
| 237 | reboot, 2, 0, do_reboot, |
| 238 | "set reboot mode and reboot system", |
| 239 | "[rebootmode]/N\n" |
| 240 | " This command will set reboot mode and reboot system\n" |
| 241 | "\n" |
| 242 | " support following [rebootmode]:\n" |
| 243 | " cold_boot\n" |
| 244 | " normal[default]\n" |
| 245 | " factory_reset/recovery\n" |
| 246 | " update\n" |
| 247 | " fastboot\n" |
| 248 | " bootloader\n" |
| 249 | " suspend_off\n" |
| 250 | " hibernate\n" |
| 251 | " next <ONLY work for SC2>\n" |
| 252 | " crash_dump\n" |
| 253 | ); |
| 254 | |
| 255 | U_BOOT_CMD( |
| 256 | set_usb_boot, 2, 0, do_set_usb_boot, |
| 257 | "set usb boot mode", |
| 258 | "[usb boot mode]/N\n" |
| 259 | " support following [usb boot mode]:\n" |
| 260 | " 1: CLEAR_USB_BOOT\n" |
| 261 | " 2: FORCE_USB_BOOT[default]\n" |
| 262 | " 3: RUN_COMD_USB_BOOT/recovery\n" |
| 263 | " 4: PANIC_DUMP_USB_BOOT\n" |
| 264 | ); |
| 265 | |
| 266 | int do_systemoff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 267 | { |
| 268 | aml_system_off(); |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | |
| 273 | U_BOOT_CMD( |
| 274 | systemoff, 2, 1, do_systemoff, |
| 275 | "system off ", |
| 276 | "systemoff " |
| 277 | ); |