blob: b319093c7a1e61e9bf7fc486ba46c6bfc1f97c39 [file] [log] [blame]
Bo Lv72d0e902023-01-02 14:27:34 +00001// 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 Xue5d4d172023-04-10 10:30:25 +08008#include <env.h>
Bo Lv72d0e902023-01-02 14:27:34 +00009#include <malloc.h>
10#include <asm/byteorder.h>
11#include <config.h>
Xindong Xue5d4d172023-04-10 10:30:25 +080012#include <asm/amlogic/arch/io.h>
13#include <amlogic/partition_table.h>
14#include <amlogic/libavb/libavb.h>
Bo Lv72d0e902023-01-02 14:27:34 +000015#include <version.h>
16#include <amlogic/storage.h>
17#include <fastboot.h>
18#include <u-boot/sha1.h>
Xindong Xue5d4d172023-04-10 10:30:25 +080019#include <asm/amlogic/arch/efuse.h>
Bo Lv72d0e902023-01-02 14:27:34 +000020#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
28static bootctl_func_handles *curr_bootctl_handles;
29
30static 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
46static 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
59static 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
72static 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
85static 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
98static 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 Xue5d4d172023-04-10 10:30:25 +0800111static 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 Lv72d0e902023-01-02 14:27:34 +0000124int 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 Xu15e83fa2024-03-15 08:56:00 +0800137int 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 Lv72d0e902023-01-02 14:27:34 +0000150U_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
156U_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
161U_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
166U_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
171U_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 Xu15e83fa2024-03-15 08:56:00 +0800176U_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 Lv72d0e902023-01-02 14:27:34 +0000183U_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 Xue5d4d172023-04-10 10:30:25 +0800188U_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