blob: c6acfc08a845c30f74030a0e47dfb2af3120c602 [file] [log] [blame]
nagendra modadugu24ba5132017-09-14 11:12:30 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Andrew Scull1c02d642017-09-11 17:54:56 +010015 */
16#ifndef __CROS_EC_INCLUDE_APP_NUGGET_H
17#define __CROS_EC_INCLUDE_APP_NUGGET_H
18#include "application.h"
Bill Richardson06ed0652017-10-20 23:19:06 -070019#include "flash_layout.h"
Andrew Scull1c02d642017-09-11 17:54:56 +010020
Andrew Sculle029d572017-09-15 11:38:28 +010021#ifdef __cplusplus
22extern "C" {
23#endif
24
Andrew Scull1c02d642017-09-11 17:54:56 +010025/****************************************************************************/
26/*
Bill Richardson06ed0652017-10-20 23:19:06 -070027 * APP_ID_NUGGET uses the Transport API
Andrew Scull1c02d642017-09-11 17:54:56 +010028 */
29/****************************************************************************/
30
31/* App-specific errors */
32enum {
Andrew Scull36ebf2d2017-10-10 11:25:21 +010033 NUGGET_ERROR_LOCKED = APP_SPECIFIC_ERROR,
34 NUGGET_ERROR_RETRY,
Andrew Scull1c02d642017-09-11 17:54:56 +010035};
36
37/****************************************************************************/
38/* Application functions */
39
40#define NUGGET_PARAM_VERSION 0x0000
41/*
42 * Return the current build string
43 *
44 * @param args <none>
45 * @param arg_len 0
46 * @param reply Null-terminated ASCII string
47 * @param reply_len Max length to return
48 *
49 * @errors APP_ERROR_TOO_MUCH
50 */
51
52/****************************************************************************/
53/* Firmware upgrade stuff */
54
55struct nugget_app_flash_block {
Andrew Scull36ebf2d2017-10-10 11:25:21 +010056 uint32_t block_digest; /* first 4 bytes of sha1 of the rest */
57 uint32_t offset; /* from start of flash */
58 uint8_t payload[CHIP_FLASH_BANK_SIZE]; /* data to write */
Andrew Scull1c02d642017-09-11 17:54:56 +010059} __packed;
60
61#define NUGGET_PARAM_FLASH_BLOCK 0x0001
62/*
63 * Erase and write a single flash block.
64 *
65 * @param args struct nugget_app_flash_block
66 * @param arg_len sizeof(struct nugget_app_flash_block)
67 * @param reply <none>
68 * @param reply_len 0
69 *
70 * @errors NUGGET_ERROR_LOCKED, NUGGET_ERROR_RETRY
71 */
72
73#define NUGGET_PARAM_REBOOT 0x0002
74/*
75 * Reboot Citadel
76 *
77 * @param args uint8_t hard 0 = soft reboot, 1 = hard reboot
78 * @param arg_len sizeof(uint8_t)
79 * @param reply <none>
80 * @param reply_len 0
81 */
82
Allen Webbc8f94522017-10-26 08:17:35 -070083enum NUGGET_REBOOT_ARG_TYPE {
84 NUGGET_REBOOT_SOFT = 0,
85 NUGGET_REBOOT_HARD = 1,
86};
87
Bill Richardsonb1c6e702018-01-17 20:24:52 -080088
89/*********
90 * Firmware updates are written to flash with invalid headers. If an update
91 * password exists, headers can only be marked valid by providing that
92 * password.
93 */
94
95/*
96 * An unassigned password is defined to be all 0xff, with a don't-care digest.
97 * Anything else must have a valid digest over all password bytes. The password
98 * length is chosen arbitrarily for now, but should always be a fixed size with
99 * all bytes used, to resist brute-force guesses.
100 */
101#define NUGGET_UPDATE_PASSWORD_LEN 32
102struct nugget_app_password {
103 uint32_t digest; /* first 4 bytes of sha1 of password (little endian) */
104 uint8_t password[NUGGET_UPDATE_PASSWORD_LEN];
105} __packed;
106
107
108enum NUGGET_ENABLE_HEADER {
109 NUGGET_ENABLE_HEADER_RO = 0x01,
110 NUGGET_ENABLE_HEADER_RW = 0x02,
111};
112struct nugget_app_enable_update {
113 struct nugget_app_password password;
114 uint8_t which_headers; /* bit 0 = RO, bit 1 = RW */
Bill Richardsonb2d86182018-01-23 15:34:03 -0800115} __packed;
Bill Richardsonb1c6e702018-01-17 20:24:52 -0800116#define NUGGET_PARAM_ENABLE_UPDATE 0x0003
117/*
118 * Mark the specified image header(s) as valid, if the provided password
119 * matches.
120 *
121 * @param args struct nugget_app_enable_update
122 * @param arg_len sizeof(struct nugget_app_enable_update)
123 * @param reply <none>
124 * @param reply_len 0
125 *
126 * @errors APP_ERROR_BOGUS_ARGS
127 */
128
129
130struct nugget_app_change_update_password {
131 struct nugget_app_password old_password;
132 struct nugget_app_password new_password;
Bill Richardsonb2d86182018-01-23 15:34:03 -0800133} __packed;
Bill Richardsonb1c6e702018-01-17 20:24:52 -0800134#define NUGGET_PARAM_CHANGE_UPDATE_PASSWORD 0x0004
135/*
136 * Change the update password.
137 *
138 * @param args struct nugget_app_change_update_password
139 * @param arg_len sizeof(struct nugget_app_change_update_password)
140 * @param reply <none>
141 * @param reply_len 0
142 *
143 * @errors APP_ERROR_BOGUS_ARGS
144 */
145
Bill Richardsonb1c6e702018-01-17 20:24:52 -0800146#define NUGGET_PARAM_NUKE_FROM_ORBIT 0x0005
147#define ERASE_CONFIRMATION 0xc05fefee
148/*
149 * This will erase ALL user secrets and reboot.
150 *
151 * @param args uint32_t containing the ERASE_CONFIRMATION value
152 * @param arg_len sizeof(uint32_t)
153 * @param reply <none>
154 * @param reply_len 0
155 *
156 * @errors APP_ERROR_BOGUS_ARGS
157 */
158
159
Andrew Scull1c02d642017-09-11 17:54:56 +0100160/****************************************************************************/
Allen Webb6ebb5eb2017-10-02 09:57:19 -0700161/* Test related commands */
162
163#define NUGGET_PARAM_CYCLES_SINCE_BOOT 0x0100
164/*
165 * Get the number of cycles since boot
166 *
167 * @param args <none>
168 * @param arg_len 0
169 * @param reply uint32_t cycles
170 * @param reply_len sizeof(uint32_t)
171 */
172
173/****************************************************************************/
Bill Richardsonb2d86182018-01-23 15:34:03 -0800174/* Support for Power 1.1 HAL */
175
176/*
177 * This struct is specific to Citadel and Nugget OS, but it's enough for the
178 * AP-side implementation to translate into the info required for the HAL
179 * structs.
180 */
181struct nugget_app_low_power_stats {
182 /* All times in usecs */
183 uint64_t hard_reset_count; /* Cleared by power loss */
184 uint64_t time_since_hard_reset;
185 /* Below are only since the last hard reset */
186 uint64_t wake_count;
187 uint64_t time_at_last_wake;
188 uint64_t time_spent_awake;
189 uint64_t deep_sleep_count;
190 uint64_t time_at_last_deep_sleep;
191 uint64_t time_spent_in_deep_sleep;
192} __packed;
Bill Richardson418b2f42018-01-22 15:56:06 -0800193
194#define NUGGET_PARAM_GET_LOW_POWER_STATS 0x200
195/*
Bill Richardsonb2d86182018-01-23 15:34:03 -0800196 * Return information regarding deep sleep transitions
Bill Richardson418b2f42018-01-22 15:56:06 -0800197 *
198 * @param args <none>
199 * @param arg_len 0
Bill Richardsonb2d86182018-01-23 15:34:03 -0800200 * @param reply struct nugget_param_get_low_power_stats
201 * @param reply_len sizeof(struct nugget_param_get_low_power_stats)
Bill Richardson418b2f42018-01-22 15:56:06 -0800202 */
203
Bill Richardsonb2d86182018-01-23 15:34:03 -0800204/* UNIMPLEMENTED */
205/* Reseved just in case we decide we need it */
206#define NUGGET_PARAM_CLEAR_LOW_POWER_STATS 0x201
207/* UNIMPLEMENTED */
208
Bill Richardson418b2f42018-01-22 15:56:06 -0800209/****************************************************************************/
Andrew Scull1c02d642017-09-11 17:54:56 +0100210/* These are bringup / debug functions only.
211 *
212 * TODO(b/65067435): Remove all of these.
213 */
214
Andrew Scull1c02d642017-09-11 17:54:56 +0100215#define NUGGET_PARAM_READ32 0xF000
216/*
217 * Read a 32-bit value from memory.
218 *
219 * DANGER, WILL ROBINSON! DANGER! There is NO sanity checking on this AT ALL.
220 * Read the wrong address, and Bad Things(tm) WILL happen.
221 *
222 * @param args uint32_t address
223 * @param arg_len sizeof(uint32_t)
224 * @param reply uint32_t value
225 * @param reply_len sizeof(uint32_t)
226 */
227
228struct nugget_app_write32 {
Andrew Scull36ebf2d2017-10-10 11:25:21 +0100229 uint32_t address;
230 uint32_t value;
Andrew Scull1c02d642017-09-11 17:54:56 +0100231} __packed;
232
233#define NUGGET_PARAM_WRITE32 0xF001
234/*
235 * Write a 32-bit value to memory
236 *
237 * DANGER, WILL ROBINSON! DANGER! There is NO sanity checking on this AT ALL.
238 * Write the wrong values to the wrong address, and Bad Things(tm) WILL happen.
239 *
240 * @param args struct nugget_app_write32
241 * @param arg_len sizeof(struct nugget_app_write32)
242 * @param reply <none>
243 * @param reply_len 0
244 */
245
Andrew Sculle029d572017-09-15 11:38:28 +0100246#ifdef __cplusplus
247}
248#endif
249
Andrew Scull36ebf2d2017-10-10 11:25:21 +0100250#endif /* __CROS_EC_INCLUDE_APP_NUGGET_H */