blob: f8e8fda2134258a955dca4f096501572387b1e05 [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/*
Bill Richardsonb49b34d2018-04-27 10:29:38 -070042 * Return the one-line version string of the running image
Andrew Scull1c02d642017-09-11 17:54:56 +010043 *
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 *
Bill Richardson580e93a2018-04-25 16:43:24 -070077 * @param args <none>
78 * @param arg_len 0
Andrew Scull1c02d642017-09-11 17:54:56 +010079 * @param reply <none>
80 * @param reply_len 0
81 */
82
Bill Richardsonb1c6e702018-01-17 20:24:52 -080083/*********
84 * Firmware updates are written to flash with invalid headers. If an update
85 * password exists, headers can only be marked valid by providing that
86 * password.
87 */
88
89/*
90 * An unassigned password is defined to be all 0xff, with a don't-care digest.
91 * Anything else must have a valid digest over all password bytes. The password
92 * length is chosen arbitrarily for now, but should always be a fixed size with
93 * all bytes used, to resist brute-force guesses.
94 */
95#define NUGGET_UPDATE_PASSWORD_LEN 32
96struct nugget_app_password {
97 uint32_t digest; /* first 4 bytes of sha1 of password (little endian) */
98 uint8_t password[NUGGET_UPDATE_PASSWORD_LEN];
99} __packed;
100
101
102enum NUGGET_ENABLE_HEADER {
103 NUGGET_ENABLE_HEADER_RO = 0x01,
104 NUGGET_ENABLE_HEADER_RW = 0x02,
105};
106struct nugget_app_enable_update {
107 struct nugget_app_password password;
108 uint8_t which_headers; /* bit 0 = RO, bit 1 = RW */
Bill Richardsonb2d86182018-01-23 15:34:03 -0800109} __packed;
Bill Richardsonb1c6e702018-01-17 20:24:52 -0800110#define NUGGET_PARAM_ENABLE_UPDATE 0x0003
111/*
112 * Mark the specified image header(s) as valid, if the provided password
113 * matches.
114 *
115 * @param args struct nugget_app_enable_update
116 * @param arg_len sizeof(struct nugget_app_enable_update)
117 * @param reply <none>
118 * @param reply_len 0
119 *
120 * @errors APP_ERROR_BOGUS_ARGS
121 */
122
123
124struct nugget_app_change_update_password {
125 struct nugget_app_password old_password;
126 struct nugget_app_password new_password;
Bill Richardsonb2d86182018-01-23 15:34:03 -0800127} __packed;
Bill Richardsonb1c6e702018-01-17 20:24:52 -0800128#define NUGGET_PARAM_CHANGE_UPDATE_PASSWORD 0x0004
129/*
130 * Change the update password.
131 *
132 * @param args struct nugget_app_change_update_password
133 * @param arg_len sizeof(struct nugget_app_change_update_password)
134 * @param reply <none>
135 * @param reply_len 0
136 *
137 * @errors APP_ERROR_BOGUS_ARGS
138 */
139
Bill Richardsonb1c6e702018-01-17 20:24:52 -0800140#define NUGGET_PARAM_NUKE_FROM_ORBIT 0x0005
141#define ERASE_CONFIRMATION 0xc05fefee
142/*
143 * This will erase ALL user secrets and reboot.
144 *
145 * @param args uint32_t containing the ERASE_CONFIRMATION value
146 * @param arg_len sizeof(uint32_t)
147 * @param reply <none>
148 * @param reply_len 0
149 *
150 * @errors APP_ERROR_BOGUS_ARGS
151 */
152
Andrew Sculld2c3a232018-03-29 20:24:11 +0100153#define NUGGET_PARAM_DEVICE_ID 0x0006
154/*
155 * Get the device ID of the chip.
156 *
157 * @param args <none>
158 * @param arg_len 0
159 * @param reply Null-terminated ASCII string
160 * @param reply_len Max length to return
161 */
162
Bill Richardsonb1c6e702018-01-17 20:24:52 -0800163
Bill Richardsonb49b34d2018-04-27 10:29:38 -0700164#define NUGGET_PARAM_LONG_VERSION 0x0007
165/*
166 * Return the multi-line description of all images
167 *
168 * @param args <none>
169 * @param arg_len 0
170 * @param reply Null-terminated ASCII string
171 * @param reply_len Max length to return
172 *
173 * @errors APP_ERROR_TOO_MUCH
174 */
175
176#define NUGGET_PARAM_HEADER_RO_A 0x0008
177/*
178 * Return the signature header for RO_A
179 *
180 * @param args <none>
181 * @param arg_len 0
182 * @param reply struct SignedHeader
183 * @param reply_len Max length to return
184 *
185 * @errors APP_ERROR_TOO_MUCH
186 */
187
188#define NUGGET_PARAM_HEADER_RO_B 0x0009
189/*
190 * Return the signature header for RO_B
191 *
192 * @param args <none>
193 * @param arg_len 0
194 * @param reply struct SignedHeader
195 * @param reply_len Max length to return
196 *
197 * @errors APP_ERROR_TOO_MUCH
198 */
199
200#define NUGGET_PARAM_HEADER_RW_A 0x000a
201/*
202 * Return the signature header for RW_A
203 *
204 * @param args <none>
205 * @param arg_len 0
206 * @param reply struct SignedHeader
207 * @param reply_len Max length to return
208 *
209 * @errors APP_ERROR_TOO_MUCH
210 */
211
212#define NUGGET_PARAM_HEADER_RW_B 0x000b
213/*
214 * Return the signature header for RW_B
215 *
216 * @param args <none>
217 * @param arg_len 0
218 * @param reply struct SignedHeader
219 * @param reply_len Max length to return
220 *
221 * @errors APP_ERROR_TOO_MUCH
222 */
223
Bill Richardson30558862018-04-27 16:11:12 -0700224#define NUGGET_PARAM_REPO_SNAPSHOT 0x000c
225/*
226 * Return the multi-line repo snapshot info for the current image
227 *
228 * @param args <none>
229 * @param arg_len 0
230 * @param reply Null-terminated ASCII string
231 * @param reply_len Max length to return
232 *
233 * @errors APP_ERROR_TOO_MUCH
234 */
235
Bill Richardsond3eaf972018-05-23 15:23:33 -0700236enum nugget_ap_uart_passthru_cfg {
237 NUGGET_AP_UART_OFF, /* off */
238 NUGGET_AP_UART_IS_USB, /* USB CCD is in use over SBU */
239 NUGGET_AP_UART_ENABLED, /* AP UART is on SBU lines */
240 NUGGET_AP_UART_SSC_UART, /* This doesn't actually exist */
241 NUGGET_AP_UART_CITADEL_UART, /* Citadel UART on SBU lines (ew) */
242
243 NUGGET_AP_UART_NUM_CFGS,
244};
245#define NUGGET_PARAM_AP_UART_PASSTHRU 0x000d
246/*
247 * Enable/Disable the AP UART PASSTHRU function
248 *
249 * This always returns the current state of the AP UART passthru feature. Even
250 * if the AP UART is disabled, a SuzyQable may connected to use the SBU lines.
251 *
252 * The AP can only request that the AP UART passthru feature be enabled
253 * (NUGGET_AP_UART_ENABLED), or disabled (NUGGET_AP_UART_OFF). The other enums
254 * are for internal testing.
255 *
256 * @param args <none> OR enum nugget_ap_uart_passthru_cfg
257 * @param arg_len 0 OR 1 byte
258 * @param reply enum nugget_param_ap_uart_passthru
259 * @param reply_len 1 byte
260 *
261 * @errors APP_ERROR_BOGUS_ARGS
262 */
263
Andrew Scull1c02d642017-09-11 17:54:56 +0100264/****************************************************************************/
Allen Webb6ebb5eb2017-10-02 09:57:19 -0700265/* Test related commands */
266
267#define NUGGET_PARAM_CYCLES_SINCE_BOOT 0x0100
268/*
269 * Get the number of cycles since boot
270 *
271 * @param args <none>
272 * @param arg_len 0
273 * @param reply uint32_t cycles
274 * @param reply_len sizeof(uint32_t)
275 */
276
277/****************************************************************************/
Bill Richardsonb2d86182018-01-23 15:34:03 -0800278/* Support for Power 1.1 HAL */
279
280/*
281 * This struct is specific to Citadel and Nugget OS, but it's enough for the
282 * AP-side implementation to translate into the info required for the HAL
283 * structs.
284 */
285struct nugget_app_low_power_stats {
286 /* All times in usecs */
287 uint64_t hard_reset_count; /* Cleared by power loss */
288 uint64_t time_since_hard_reset;
289 /* Below are only since the last hard reset */
290 uint64_t wake_count;
291 uint64_t time_at_last_wake;
292 uint64_t time_spent_awake;
293 uint64_t deep_sleep_count;
294 uint64_t time_at_last_deep_sleep;
295 uint64_t time_spent_in_deep_sleep;
296} __packed;
Bill Richardson418b2f42018-01-22 15:56:06 -0800297
298#define NUGGET_PARAM_GET_LOW_POWER_STATS 0x200
299/*
Bill Richardsonb2d86182018-01-23 15:34:03 -0800300 * Return information regarding deep sleep transitions
Bill Richardson418b2f42018-01-22 15:56:06 -0800301 *
302 * @param args <none>
303 * @param arg_len 0
Bill Richardsonb2d86182018-01-23 15:34:03 -0800304 * @param reply struct nugget_param_get_low_power_stats
305 * @param reply_len sizeof(struct nugget_param_get_low_power_stats)
Bill Richardson418b2f42018-01-22 15:56:06 -0800306 */
307
Bill Richardsonb2d86182018-01-23 15:34:03 -0800308/* UNIMPLEMENTED */
309/* Reseved just in case we decide we need it */
310#define NUGGET_PARAM_CLEAR_LOW_POWER_STATS 0x201
311/* UNIMPLEMENTED */
312
Bill Richardson418b2f42018-01-22 15:56:06 -0800313/****************************************************************************/
Andrew Scull1c02d642017-09-11 17:54:56 +0100314/* These are bringup / debug functions only.
315 *
316 * TODO(b/65067435): Remove all of these.
317 */
318
Andrew Scull1c02d642017-09-11 17:54:56 +0100319#define NUGGET_PARAM_READ32 0xF000
320/*
321 * Read a 32-bit value from memory.
322 *
323 * DANGER, WILL ROBINSON! DANGER! There is NO sanity checking on this AT ALL.
324 * Read the wrong address, and Bad Things(tm) WILL happen.
325 *
326 * @param args uint32_t address
327 * @param arg_len sizeof(uint32_t)
328 * @param reply uint32_t value
329 * @param reply_len sizeof(uint32_t)
330 */
331
332struct nugget_app_write32 {
Andrew Scull36ebf2d2017-10-10 11:25:21 +0100333 uint32_t address;
334 uint32_t value;
Andrew Scull1c02d642017-09-11 17:54:56 +0100335} __packed;
336
337#define NUGGET_PARAM_WRITE32 0xF001
338/*
339 * Write a 32-bit value to memory
340 *
341 * DANGER, WILL ROBINSON! DANGER! There is NO sanity checking on this AT ALL.
342 * Write the wrong values to the wrong address, and Bad Things(tm) WILL happen.
343 *
344 * @param args struct nugget_app_write32
345 * @param arg_len sizeof(struct nugget_app_write32)
346 * @param reply <none>
347 * @param reply_len 0
348 */
349
Andrew Sculle029d572017-09-15 11:38:28 +0100350#ifdef __cplusplus
351}
352#endif
353
Andrew Scull36ebf2d2017-10-10 11:25:21 +0100354#endif /* __CROS_EC_INCLUDE_APP_NUGGET_H */