blob: f6cf9b1e6c0f95b4ade8f0426ced426f2942398d [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>
8#include <environment.h>
9#include <malloc.h>
10#include <asm/byteorder.h>
11#include <config.h>
12#include <asm/arch/io.h>
13#include <partition_table.h>
14#include <libavb.h>
15#include <version.h>
16#include <amlogic/storage.h>
17#include <fastboot.h>
18#include <u-boot/sha1.h>
19#include <asm/arch/efuse.h>
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
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
111int do_GetSystemMode(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_GetSystemMode_func)
119 ret = func_handles->do_GetSystemMode_func(cmdtp, flag, argc, argv);
120
121 return ret;
122}
123
124int do_GetAvbMode(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_GetAvbMode_func)
132 ret = func_handles->do_GetAvbMode_func(cmdtp, flag, argc, argv);
133
134 return ret;
135}
136
137U_BOOT_CMD(get_valid_slot, 2, 0, do_GetValidSlot,
138 "get_valid_slot",
139 "\nThis command will choose valid slot to boot up which saved in misc\n"
140 "partition by mark to decide whether execute command!\n"
141 "So you can execute command: get_valid_slot");
142
143U_BOOT_CMD(set_active_slot, 2, 1, do_SetActiveSlot,
144 "set_active_slot",
145 "\nThis command will set active slot\n"
146 "So you can execute command: set_active_slot a");
147
148U_BOOT_CMD(set_roll_flag, 2, 1, do_SetRollFlag,
149 "set_roll_flag",
150 "\nThis command will set active slot\n"
151 "So you can execute command: set_active_slot a");
152
153U_BOOT_CMD(copy_slot_bootable, 3, 1, do_CopySlot,
154 "copy_slot_bootable",
155 "\nThis command will set active slot\n"
156 "So you can execute command: copy_slot_bootable 2 1");
157
158U_BOOT_CMD(update_tries, 2, 0, do_SetUpdateTries,
159 "update_tries",
160 "\nThis command will change tries_remaining in misc\n"
161 "So you can execute command: update_tries");
162
163U_BOOT_CMD(get_system_as_root_mode, 1, 0, do_GetSystemMode,
164 "get_system_as_root_mode",
165 "\nThis command will get system_as_root_mode\n"
166 "So you can execute command: get_system_as_root_mode");
167
168U_BOOT_CMD(get_avb_mode, 1, 0, do_GetAvbMode,
169 "get_avb_mode",
170 "\nThis command will get avb mode\n"
171 "So you can execute command: get_avb_mode");
172