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> |
Xindong Xu | e5d4d17 | 2023-04-10 10:30:25 +0800 | [diff] [blame] | 8 | #include <env.h> |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 9 | #include <malloc.h> |
| 10 | #include <asm/byteorder.h> |
| 11 | #include <config.h> |
Xindong Xu | e5d4d17 | 2023-04-10 10:30:25 +0800 | [diff] [blame] | 12 | #include <asm/amlogic/arch/io.h> |
| 13 | #include <amlogic/partition_table.h> |
| 14 | #include <amlogic/libavb/libavb.h> |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 15 | #include <version.h> |
| 16 | #include <amlogic/storage.h> |
| 17 | #include <fastboot.h> |
| 18 | #include <u-boot/sha1.h> |
Xindong Xu | e5d4d17 | 2023-04-10 10:30:25 +0800 | [diff] [blame] | 19 | #include <asm/amlogic/arch/efuse.h> |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 20 | #include <stdlib.h> |
| 21 | #include "cmd_bootctl_wrapper.h" |
| 22 | #include "cmd_bootctl_utils.h" |
| 23 | |
| 24 | #ifndef getenv |
| 25 | #define getenv env_get |
| 26 | #endif |
| 27 | |
| 28 | static bootctl_func_handles *curr_bootctl_handles; |
| 29 | |
| 30 | static bootctl_func_handles *select_bootctl_cmd_func(void) |
| 31 | { |
| 32 | if (curr_bootctl_handles) { |
| 33 | return curr_bootctl_handles; |
| 34 | }; |
| 35 | |
| 36 | if (aml_get_boot_mode() == BOOT_MODE_AVB) |
| 37 | curr_bootctl_handles = get_bootctl_cmd_func_avb(); |
| 38 | else if (aml_get_boot_mode() == BOOT_MODE_VAB) |
| 39 | curr_bootctl_handles = get_bootctl_cmd_func_vab(); |
| 40 | else |
| 41 | curr_bootctl_handles = get_bootctl_cmd_func(); |
| 42 | |
| 43 | return curr_bootctl_handles; |
| 44 | } |
| 45 | |
| 46 | static int do_GetValidSlot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 47 | { |
| 48 | int ret = 0; |
| 49 | bootctl_func_handles *func_handles = NULL; |
| 50 | |
| 51 | func_handles = select_bootctl_cmd_func(); |
| 52 | |
| 53 | if (func_handles && func_handles->do_GetValidSlot_func) |
| 54 | ret = func_handles->do_GetValidSlot_func(cmdtp, flag, argc, argv); |
| 55 | |
| 56 | return ret; |
| 57 | } |
| 58 | |
| 59 | static int do_SetActiveSlot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 60 | { |
| 61 | int ret = 0; |
| 62 | bootctl_func_handles *func_handles = NULL; |
| 63 | |
| 64 | func_handles = select_bootctl_cmd_func(); |
| 65 | |
| 66 | if (func_handles && func_handles->do_SetActiveSlot_func) |
| 67 | ret = func_handles->do_SetActiveSlot_func(cmdtp, flag, argc, argv); |
| 68 | |
| 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | static int do_SetRollFlag(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 73 | { |
| 74 | int ret = 0; |
| 75 | bootctl_func_handles *func_handles = NULL; |
| 76 | |
| 77 | func_handles = select_bootctl_cmd_func(); |
| 78 | |
| 79 | if (func_handles && func_handles->do_SetRollFlag_func) |
| 80 | ret = func_handles->do_SetRollFlag_func(cmdtp, flag, argc, argv); |
| 81 | |
| 82 | return ret; |
| 83 | } |
| 84 | |
| 85 | static int do_CopySlot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 86 | { |
| 87 | int ret = 0; |
| 88 | bootctl_func_handles *func_handles = NULL; |
| 89 | |
| 90 | func_handles = select_bootctl_cmd_func(); |
| 91 | |
| 92 | if (func_handles && func_handles->do_CopySlot_func) |
| 93 | ret = func_handles->do_CopySlot_func(cmdtp, flag, argc, argv); |
| 94 | |
| 95 | return ret; |
| 96 | } |
| 97 | |
| 98 | static int do_SetUpdateTries(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 99 | { |
| 100 | int ret = 0; |
| 101 | bootctl_func_handles *func_handles = NULL; |
| 102 | |
| 103 | func_handles = select_bootctl_cmd_func(); |
| 104 | |
| 105 | if (func_handles && func_handles->do_SetUpdateTries_func) |
| 106 | ret = func_handles->do_SetUpdateTries_func(cmdtp, flag, argc, argv); |
| 107 | |
| 108 | return ret; |
| 109 | } |
| 110 | |
Xindong Xu | e5d4d17 | 2023-04-10 10:30:25 +0800 | [diff] [blame] | 111 | static int do_UpdateDt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 112 | { |
| 113 | int ret = 0; |
| 114 | bootctl_func_handles *func_handles = NULL; |
| 115 | |
| 116 | func_handles = select_bootctl_cmd_func(); |
| 117 | |
| 118 | if (func_handles && func_handles->do_UpdateDt_func) |
| 119 | ret = func_handles->do_UpdateDt_func(cmdtp, flag, argc, argv); |
| 120 | |
| 121 | return ret; |
| 122 | } |
| 123 | |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 124 | int do_GetSystemMode(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 125 | { |
| 126 | int ret = 0; |
| 127 | bootctl_func_handles *func_handles = NULL; |
| 128 | |
| 129 | func_handles = select_bootctl_cmd_func(); |
| 130 | |
| 131 | if (func_handles && func_handles->do_GetSystemMode_func) |
| 132 | ret = func_handles->do_GetSystemMode_func(cmdtp, flag, argc, argv); |
| 133 | |
| 134 | return ret; |
| 135 | } |
| 136 | |
Xindong Xu | 15e83fa | 2024-03-15 08:56:00 +0800 | [diff] [blame] | 137 | int do_CheckABState(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 138 | { |
| 139 | int ret = 0; |
| 140 | bootctl_func_handles *func_handles = NULL; |
| 141 | |
| 142 | func_handles = select_bootctl_cmd_func(); |
| 143 | |
| 144 | if (func_handles && func_handles->do_CheckABState_func) |
| 145 | ret = func_handles->do_CheckABState_func(cmdtp, flag, argc, argv); |
| 146 | |
| 147 | return ret; |
| 148 | } |
| 149 | |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 150 | U_BOOT_CMD(get_valid_slot, 2, 0, do_GetValidSlot, |
| 151 | "get_valid_slot", |
| 152 | "\nThis command will choose valid slot to boot up which saved in misc\n" |
| 153 | "partition by mark to decide whether execute command!\n" |
| 154 | "So you can execute command: get_valid_slot"); |
| 155 | |
| 156 | U_BOOT_CMD(set_active_slot, 2, 1, do_SetActiveSlot, |
| 157 | "set_active_slot", |
| 158 | "\nThis command will set active slot\n" |
| 159 | "So you can execute command: set_active_slot a"); |
| 160 | |
| 161 | U_BOOT_CMD(set_roll_flag, 2, 1, do_SetRollFlag, |
| 162 | "set_roll_flag", |
| 163 | "\nThis command will set active slot\n" |
| 164 | "So you can execute command: set_active_slot a"); |
| 165 | |
| 166 | U_BOOT_CMD(copy_slot_bootable, 3, 1, do_CopySlot, |
| 167 | "copy_slot_bootable", |
| 168 | "\nThis command will set active slot\n" |
| 169 | "So you can execute command: copy_slot_bootable 2 1"); |
| 170 | |
| 171 | U_BOOT_CMD(update_tries, 2, 0, do_SetUpdateTries, |
| 172 | "update_tries", |
| 173 | "\nThis command will change tries_remaining in misc\n" |
| 174 | "So you can execute command: update_tries"); |
| 175 | |
Xindong Xu | 15e83fa | 2024-03-15 08:56:00 +0800 | [diff] [blame] | 176 | U_BOOT_CMD |
| 177 | (check_ab, 2, 0, do_CheckABState, |
| 178 | "check_ab", |
| 179 | "\nThis command will check ab sate\n" |
| 180 | "So you can execute command: check_ab" |
| 181 | ); |
| 182 | |
Bo Lv | 72d0e90 | 2023-01-02 14:27:34 +0000 | [diff] [blame] | 183 | U_BOOT_CMD(get_system_as_root_mode, 1, 0, do_GetSystemMode, |
| 184 | "get_system_as_root_mode", |
| 185 | "\nThis command will get system_as_root_mode\n" |
| 186 | "So you can execute command: get_system_as_root_mode"); |
| 187 | |
Xindong Xu | e5d4d17 | 2023-04-10 10:30:25 +0800 | [diff] [blame] | 188 | U_BOOT_CMD |
| 189 | (update_dt, 1, 0, do_UpdateDt, |
| 190 | "update_dt", |
| 191 | "\nThis command will update dt\n" |
| 192 | "So you can execute command: update_dt"); |
| 193 | |