nagendra modadugu | 24ba513 | 2017-09-14 11:12:30 -0700 | [diff] [blame] | 1 | /* |
| 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 Scull | 1c02d64 | 2017-09-11 17:54:56 +0100 | [diff] [blame] | 15 | */ |
| 16 | #ifndef __CROS_EC_INCLUDE_APP_NUGGET_H |
| 17 | #define __CROS_EC_INCLUDE_APP_NUGGET_H |
| 18 | #include "application.h" |
Bill Richardson | 06ed065 | 2017-10-20 23:19:06 -0700 | [diff] [blame] | 19 | #include "flash_layout.h" |
Andrew Scull | 1c02d64 | 2017-09-11 17:54:56 +0100 | [diff] [blame] | 20 | |
Andrew Scull | e029d57 | 2017-09-15 11:38:28 +0100 | [diff] [blame] | 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
Andrew Scull | 1c02d64 | 2017-09-11 17:54:56 +0100 | [diff] [blame] | 25 | /****************************************************************************/ |
| 26 | /* |
Bill Richardson | 06ed065 | 2017-10-20 23:19:06 -0700 | [diff] [blame] | 27 | * APP_ID_NUGGET uses the Transport API |
Andrew Scull | 1c02d64 | 2017-09-11 17:54:56 +0100 | [diff] [blame] | 28 | */ |
| 29 | /****************************************************************************/ |
| 30 | |
| 31 | /* App-specific errors */ |
| 32 | enum { |
Andrew Scull | 36ebf2d | 2017-10-10 11:25:21 +0100 | [diff] [blame] | 33 | NUGGET_ERROR_LOCKED = APP_SPECIFIC_ERROR, |
| 34 | NUGGET_ERROR_RETRY, |
Andrew Scull | 1c02d64 | 2017-09-11 17:54:56 +0100 | [diff] [blame] | 35 | }; |
| 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 | |
| 55 | struct nugget_app_flash_block { |
Andrew Scull | 36ebf2d | 2017-10-10 11:25:21 +0100 | [diff] [blame] | 56 | 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 Scull | 1c02d64 | 2017-09-11 17:54:56 +0100 | [diff] [blame] | 59 | } __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 Webb | c8f9452 | 2017-10-26 08:17:35 -0700 | [diff] [blame] | 83 | enum NUGGET_REBOOT_ARG_TYPE { |
| 84 | NUGGET_REBOOT_SOFT = 0, |
| 85 | NUGGET_REBOOT_HARD = 1, |
| 86 | }; |
| 87 | |
Bill Richardson | b1c6e70 | 2018-01-17 20:24:52 -0800 | [diff] [blame] | 88 | |
| 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 |
| 102 | struct 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 | |
| 108 | enum NUGGET_ENABLE_HEADER { |
| 109 | NUGGET_ENABLE_HEADER_RO = 0x01, |
| 110 | NUGGET_ENABLE_HEADER_RW = 0x02, |
| 111 | }; |
| 112 | struct nugget_app_enable_update { |
| 113 | struct nugget_app_password password; |
| 114 | uint8_t which_headers; /* bit 0 = RO, bit 1 = RW */ |
Bill Richardson | b2d8618 | 2018-01-23 15:34:03 -0800 | [diff] [blame^] | 115 | } __packed; |
Bill Richardson | b1c6e70 | 2018-01-17 20:24:52 -0800 | [diff] [blame] | 116 | #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 | |
| 130 | struct nugget_app_change_update_password { |
| 131 | struct nugget_app_password old_password; |
| 132 | struct nugget_app_password new_password; |
Bill Richardson | b2d8618 | 2018-01-23 15:34:03 -0800 | [diff] [blame^] | 133 | } __packed; |
Bill Richardson | b1c6e70 | 2018-01-17 20:24:52 -0800 | [diff] [blame] | 134 | #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 Richardson | b1c6e70 | 2018-01-17 20:24:52 -0800 | [diff] [blame] | 146 | #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 Scull | 1c02d64 | 2017-09-11 17:54:56 +0100 | [diff] [blame] | 160 | /****************************************************************************/ |
Allen Webb | 6ebb5eb | 2017-10-02 09:57:19 -0700 | [diff] [blame] | 161 | /* 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 Richardson | b2d8618 | 2018-01-23 15:34:03 -0800 | [diff] [blame^] | 174 | /* 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 | */ |
| 181 | struct 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 Richardson | 418b2f4 | 2018-01-22 15:56:06 -0800 | [diff] [blame] | 193 | |
| 194 | #define NUGGET_PARAM_GET_LOW_POWER_STATS 0x200 |
| 195 | /* |
Bill Richardson | b2d8618 | 2018-01-23 15:34:03 -0800 | [diff] [blame^] | 196 | * Return information regarding deep sleep transitions |
Bill Richardson | 418b2f4 | 2018-01-22 15:56:06 -0800 | [diff] [blame] | 197 | * |
| 198 | * @param args <none> |
| 199 | * @param arg_len 0 |
Bill Richardson | b2d8618 | 2018-01-23 15:34:03 -0800 | [diff] [blame^] | 200 | * @param reply struct nugget_param_get_low_power_stats |
| 201 | * @param reply_len sizeof(struct nugget_param_get_low_power_stats) |
Bill Richardson | 418b2f4 | 2018-01-22 15:56:06 -0800 | [diff] [blame] | 202 | */ |
| 203 | |
Bill Richardson | b2d8618 | 2018-01-23 15:34:03 -0800 | [diff] [blame^] | 204 | /* UNIMPLEMENTED */ |
| 205 | /* Reseved just in case we decide we need it */ |
| 206 | #define NUGGET_PARAM_CLEAR_LOW_POWER_STATS 0x201 |
| 207 | /* UNIMPLEMENTED */ |
| 208 | |
Bill Richardson | 418b2f4 | 2018-01-22 15:56:06 -0800 | [diff] [blame] | 209 | /****************************************************************************/ |
Andrew Scull | 1c02d64 | 2017-09-11 17:54:56 +0100 | [diff] [blame] | 210 | /* These are bringup / debug functions only. |
| 211 | * |
| 212 | * TODO(b/65067435): Remove all of these. |
| 213 | */ |
| 214 | |
Andrew Scull | 1c02d64 | 2017-09-11 17:54:56 +0100 | [diff] [blame] | 215 | #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 | |
| 228 | struct nugget_app_write32 { |
Andrew Scull | 36ebf2d | 2017-10-10 11:25:21 +0100 | [diff] [blame] | 229 | uint32_t address; |
| 230 | uint32_t value; |
Andrew Scull | 1c02d64 | 2017-09-11 17:54:56 +0100 | [diff] [blame] | 231 | } __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 Scull | e029d57 | 2017-09-15 11:38:28 +0100 | [diff] [blame] | 246 | #ifdef __cplusplus |
| 247 | } |
| 248 | #endif |
| 249 | |
Andrew Scull | 36ebf2d | 2017-10-10 11:25:21 +0100 | [diff] [blame] | 250 | #endif /* __CROS_EC_INCLUDE_APP_NUGGET_H */ |