blob: 7dac7c4fd3d7affe0258f347fe93f1d23817c929 [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"
19#include "config.h"
20
Andrew Sculle029d572017-09-15 11:38:28 +010021#ifdef __cplusplus
22extern "C" {
23#endif
24
Andrew Scull1c02d642017-09-11 17:54:56 +010025/****************************************************************************/
26/*
27 * APP_ID_NUGGET uses the Transport API:
28 *
29 * uint32_t call_application(uint8_t app_id, uint16_t app_param,
30 * uint8_t *args, uint16_t arg_len,
31 * uint8_t *reply, uint16_t *reply_len);
32 *
33 * Refer to application.h for details.
34 */
35/****************************************************************************/
36
37/* App-specific errors */
38enum {
39 NUGGET_ERROR_LOCKED = APP_SPECIFIC_ERROR,
40 NUGGET_ERROR_RETRY,
41};
42
43/****************************************************************************/
44/* Application functions */
45
46#define NUGGET_PARAM_VERSION 0x0000
47/*
48 * Return the current build string
49 *
50 * @param args <none>
51 * @param arg_len 0
52 * @param reply Null-terminated ASCII string
53 * @param reply_len Max length to return
54 *
55 * @errors APP_ERROR_TOO_MUCH
56 */
57
58/****************************************************************************/
59/* Firmware upgrade stuff */
60
61struct nugget_app_flash_block {
62 uint32_t block_digest; /* first 4 bytes of sha1 of the rest */
63 uint32_t offset; /* from start of flash */
64 uint8_t payload[CHIP_FLASH_BANK_SIZE]; /* data to write */
65} __packed;
66
67#define NUGGET_PARAM_FLASH_BLOCK 0x0001
68/*
69 * Erase and write a single flash block.
70 *
71 * @param args struct nugget_app_flash_block
72 * @param arg_len sizeof(struct nugget_app_flash_block)
73 * @param reply <none>
74 * @param reply_len 0
75 *
76 * @errors NUGGET_ERROR_LOCKED, NUGGET_ERROR_RETRY
77 */
78
79#define NUGGET_PARAM_REBOOT 0x0002
80/*
81 * Reboot Citadel
82 *
83 * @param args uint8_t hard 0 = soft reboot, 1 = hard reboot
84 * @param arg_len sizeof(uint8_t)
85 * @param reply <none>
86 * @param reply_len 0
87 */
88
89/****************************************************************************/
Allen Webb6ebb5eb2017-10-02 09:57:19 -070090/* Test related commands */
91
92#define NUGGET_PARAM_CYCLES_SINCE_BOOT 0x0100
93/*
94 * Get the number of cycles since boot
95 *
96 * @param args <none>
97 * @param arg_len 0
98 * @param reply uint32_t cycles
99 * @param reply_len sizeof(uint32_t)
100 */
101
102/****************************************************************************/
Andrew Scull1c02d642017-09-11 17:54:56 +0100103/* These are bringup / debug functions only.
104 *
105 * TODO(b/65067435): Remove all of these.
106 */
107
108#define NUGGET_PARAM_REVERSE 0xbeef
109/*
110 * Reverse a sequence of bytes, just to have something to demonstrate.
111 *
112 * @param args any arbitrary bytes
113 * @param arg_len any arbitrary length, within reason
114 * @param reply input bytes, in reverse order
115 * @param reply_len same as arg_len
116 *
117 * @errors APP_ERROR_TOO_MUCH
118 */
119
120#define NUGGET_PARAM_READ32 0xF000
121/*
122 * Read a 32-bit value from memory.
123 *
124 * DANGER, WILL ROBINSON! DANGER! There is NO sanity checking on this AT ALL.
125 * Read the wrong address, and Bad Things(tm) WILL happen.
126 *
127 * @param args uint32_t address
128 * @param arg_len sizeof(uint32_t)
129 * @param reply uint32_t value
130 * @param reply_len sizeof(uint32_t)
131 */
132
133struct nugget_app_write32 {
134 uint32_t address;
135 uint32_t value;
136} __packed;
137
138#define NUGGET_PARAM_WRITE32 0xF001
139/*
140 * Write a 32-bit value to memory
141 *
142 * DANGER, WILL ROBINSON! DANGER! There is NO sanity checking on this AT ALL.
143 * Write the wrong values to the wrong address, and Bad Things(tm) WILL happen.
144 *
145 * @param args struct nugget_app_write32
146 * @param arg_len sizeof(struct nugget_app_write32)
147 * @param reply <none>
148 * @param reply_len 0
149 */
150
Andrew Sculle029d572017-09-15 11:38:28 +0100151#ifdef __cplusplus
152}
153#endif
154
Andrew Scull1c02d642017-09-11 17:54:56 +0100155#endif /* __CROS_EC_INCLUDE_APP_NUGGET_H */