cros_ec.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. /*
  2. * Chromium OS cros_ec driver
  3. *
  4. * Copyright (c) 2012 The Chromium OS Authors.
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * The Matrix Keyboard Protocol driver handles talking to the keyboard
  25. * controller chip. Mostly this is for keyboard functions, but some other
  26. * things have slipped in, so we provide generic services to talk to the
  27. * KBC.
  28. */
  29. #include <common.h>
  30. #include <command.h>
  31. #include <i2c.h>
  32. #include <cros_ec.h>
  33. #include <fdtdec.h>
  34. #include <malloc.h>
  35. #include <spi.h>
  36. #include <asm/io.h>
  37. #include <asm-generic/gpio.h>
  38. #ifdef DEBUG_TRACE
  39. #define debug_trace(fmt, b...) debug(fmt, #b)
  40. #else
  41. #define debug_trace(fmt, b...)
  42. #endif
  43. enum {
  44. /* Timeout waiting for a flash erase command to complete */
  45. CROS_EC_CMD_TIMEOUT_MS = 5000,
  46. /* Timeout waiting for a synchronous hash to be recomputed */
  47. CROS_EC_CMD_HASH_TIMEOUT_MS = 2000,
  48. };
  49. static struct cros_ec_dev static_dev, *last_dev;
  50. DECLARE_GLOBAL_DATA_PTR;
  51. /* Note: depends on enum ec_current_image */
  52. static const char * const ec_current_image_name[] = {"unknown", "RO", "RW"};
  53. void cros_ec_dump_data(const char *name, int cmd, const uint8_t *data, int len)
  54. {
  55. #ifdef DEBUG
  56. int i;
  57. printf("%s: ", name);
  58. if (cmd != -1)
  59. printf("cmd=%#x: ", cmd);
  60. for (i = 0; i < len; i++)
  61. printf("%02x ", data[i]);
  62. printf("\n");
  63. #endif
  64. }
  65. /*
  66. * Calculate a simple 8-bit checksum of a data block
  67. *
  68. * @param data Data block to checksum
  69. * @param size Size of data block in bytes
  70. * @return checksum value (0 to 255)
  71. */
  72. int cros_ec_calc_checksum(const uint8_t *data, int size)
  73. {
  74. int csum, i;
  75. for (i = csum = 0; i < size; i++)
  76. csum += data[i];
  77. return csum & 0xff;
  78. }
  79. static int send_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
  80. const void *dout, int dout_len,
  81. uint8_t **dinp, int din_len)
  82. {
  83. int ret;
  84. switch (dev->interface) {
  85. #ifdef CONFIG_CROS_EC_SPI
  86. case CROS_EC_IF_SPI:
  87. ret = cros_ec_spi_command(dev, cmd, cmd_version,
  88. (const uint8_t *)dout, dout_len,
  89. dinp, din_len);
  90. break;
  91. #endif
  92. #ifdef CONFIG_CROS_EC_I2C
  93. case CROS_EC_IF_I2C:
  94. ret = cros_ec_i2c_command(dev, cmd, cmd_version,
  95. (const uint8_t *)dout, dout_len,
  96. dinp, din_len);
  97. break;
  98. #endif
  99. #ifdef CONFIG_CROS_EC_LPC
  100. case CROS_EC_IF_LPC:
  101. ret = cros_ec_lpc_command(dev, cmd, cmd_version,
  102. (const uint8_t *)dout, dout_len,
  103. dinp, din_len);
  104. break;
  105. #endif
  106. case CROS_EC_IF_NONE:
  107. default:
  108. ret = -1;
  109. }
  110. return ret;
  111. }
  112. /**
  113. * Send a command to the CROS-EC device and return the reply.
  114. *
  115. * The device's internal input/output buffers are used.
  116. *
  117. * @param dev CROS-EC device
  118. * @param cmd Command to send (EC_CMD_...)
  119. * @param cmd_version Version of command to send (EC_VER_...)
  120. * @param dout Output data (may be NULL If dout_len=0)
  121. * @param dout_len Size of output data in bytes
  122. * @param dinp Response data (may be NULL If din_len=0).
  123. * If not NULL, it will be updated to point to the data
  124. * and will always be double word aligned (64-bits)
  125. * @param din_len Maximum size of response in bytes
  126. * @return number of bytes in response, or -1 on error
  127. */
  128. static int ec_command_inptr(struct cros_ec_dev *dev, uint8_t cmd,
  129. int cmd_version, const void *dout, int dout_len, uint8_t **dinp,
  130. int din_len)
  131. {
  132. uint8_t *din;
  133. int len;
  134. if (cmd_version != 0 && !dev->cmd_version_is_supported) {
  135. debug("%s: Command version >0 unsupported\n", __func__);
  136. return -1;
  137. }
  138. len = send_command(dev, cmd, cmd_version, dout, dout_len,
  139. &din, din_len);
  140. /* If the command doesn't complete, wait a while */
  141. if (len == -EC_RES_IN_PROGRESS) {
  142. struct ec_response_get_comms_status *resp;
  143. ulong start;
  144. /* Wait for command to complete */
  145. start = get_timer(0);
  146. do {
  147. int ret;
  148. mdelay(50); /* Insert some reasonable delay */
  149. ret = send_command(dev, EC_CMD_GET_COMMS_STATUS, 0,
  150. NULL, 0,
  151. (uint8_t **)&resp, sizeof(*resp));
  152. if (ret < 0)
  153. return ret;
  154. if (get_timer(start) > CROS_EC_CMD_TIMEOUT_MS) {
  155. debug("%s: Command %#02x timeout\n",
  156. __func__, cmd);
  157. return -EC_RES_TIMEOUT;
  158. }
  159. } while (resp->flags & EC_COMMS_STATUS_PROCESSING);
  160. /* OK it completed, so read the status response */
  161. /* not sure why it was 0 for the last argument */
  162. len = send_command(dev, EC_CMD_RESEND_RESPONSE, 0,
  163. NULL, 0, &din, din_len);
  164. }
  165. debug("%s: len=%d, dinp=%p, *dinp=%p\n", __func__, len, dinp, *dinp);
  166. if (dinp) {
  167. /* If we have any data to return, it must be 64bit-aligned */
  168. assert(len <= 0 || !((uintptr_t)din & 7));
  169. *dinp = din;
  170. }
  171. return len;
  172. }
  173. /**
  174. * Send a command to the CROS-EC device and return the reply.
  175. *
  176. * The device's internal input/output buffers are used.
  177. *
  178. * @param dev CROS-EC device
  179. * @param cmd Command to send (EC_CMD_...)
  180. * @param cmd_version Version of command to send (EC_VER_...)
  181. * @param dout Output data (may be NULL If dout_len=0)
  182. * @param dout_len Size of output data in bytes
  183. * @param din Response data (may be NULL If din_len=0).
  184. * It not NULL, it is a place for ec_command() to copy the
  185. * data to.
  186. * @param din_len Maximum size of response in bytes
  187. * @return number of bytes in response, or -1 on error
  188. */
  189. static int ec_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
  190. const void *dout, int dout_len,
  191. void *din, int din_len)
  192. {
  193. uint8_t *in_buffer;
  194. int len;
  195. assert((din_len == 0) || din);
  196. len = ec_command_inptr(dev, cmd, cmd_version, dout, dout_len,
  197. &in_buffer, din_len);
  198. if (len > 0) {
  199. /*
  200. * If we were asked to put it somewhere, do so, otherwise just
  201. * disregard the result.
  202. */
  203. if (din && in_buffer) {
  204. assert(len <= din_len);
  205. memmove(din, in_buffer, len);
  206. }
  207. }
  208. return len;
  209. }
  210. int cros_ec_scan_keyboard(struct cros_ec_dev *dev, struct mbkp_keyscan *scan)
  211. {
  212. if (ec_command(dev, EC_CMD_CROS_EC_STATE, 0, NULL, 0, scan,
  213. sizeof(scan->data)) < sizeof(scan->data))
  214. return -1;
  215. return 0;
  216. }
  217. int cros_ec_read_id(struct cros_ec_dev *dev, char *id, int maxlen)
  218. {
  219. struct ec_response_get_version *r;
  220. if (ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
  221. (uint8_t **)&r, sizeof(*r)) < sizeof(*r))
  222. return -1;
  223. if (maxlen > sizeof(r->version_string_ro))
  224. maxlen = sizeof(r->version_string_ro);
  225. switch (r->current_image) {
  226. case EC_IMAGE_RO:
  227. memcpy(id, r->version_string_ro, maxlen);
  228. break;
  229. case EC_IMAGE_RW:
  230. memcpy(id, r->version_string_rw, maxlen);
  231. break;
  232. default:
  233. return -1;
  234. }
  235. id[maxlen - 1] = '\0';
  236. return 0;
  237. }
  238. int cros_ec_read_version(struct cros_ec_dev *dev,
  239. struct ec_response_get_version **versionp)
  240. {
  241. if (ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
  242. (uint8_t **)versionp, sizeof(**versionp))
  243. < sizeof(**versionp))
  244. return -1;
  245. return 0;
  246. }
  247. int cros_ec_read_build_info(struct cros_ec_dev *dev, char **strp)
  248. {
  249. if (ec_command_inptr(dev, EC_CMD_GET_BUILD_INFO, 0, NULL, 0,
  250. (uint8_t **)strp, EC_HOST_PARAM_SIZE) < 0)
  251. return -1;
  252. return 0;
  253. }
  254. int cros_ec_read_current_image(struct cros_ec_dev *dev,
  255. enum ec_current_image *image)
  256. {
  257. struct ec_response_get_version *r;
  258. if (ec_command_inptr(dev, EC_CMD_GET_VERSION, 0, NULL, 0,
  259. (uint8_t **)&r, sizeof(*r)) < sizeof(*r))
  260. return -1;
  261. *image = r->current_image;
  262. return 0;
  263. }
  264. static int cros_ec_wait_on_hash_done(struct cros_ec_dev *dev,
  265. struct ec_response_vboot_hash *hash)
  266. {
  267. struct ec_params_vboot_hash p;
  268. ulong start;
  269. start = get_timer(0);
  270. while (hash->status == EC_VBOOT_HASH_STATUS_BUSY) {
  271. mdelay(50); /* Insert some reasonable delay */
  272. p.cmd = EC_VBOOT_HASH_GET;
  273. if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
  274. hash, sizeof(*hash)) < 0)
  275. return -1;
  276. if (get_timer(start) > CROS_EC_CMD_HASH_TIMEOUT_MS) {
  277. debug("%s: EC_VBOOT_HASH_GET timeout\n", __func__);
  278. return -EC_RES_TIMEOUT;
  279. }
  280. }
  281. return 0;
  282. }
  283. int cros_ec_read_hash(struct cros_ec_dev *dev,
  284. struct ec_response_vboot_hash *hash)
  285. {
  286. struct ec_params_vboot_hash p;
  287. int rv;
  288. p.cmd = EC_VBOOT_HASH_GET;
  289. if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
  290. hash, sizeof(*hash)) < 0)
  291. return -1;
  292. /* If the EC is busy calculating the hash, fidget until it's done. */
  293. rv = cros_ec_wait_on_hash_done(dev, hash);
  294. if (rv)
  295. return rv;
  296. /* If the hash is valid, we're done. Otherwise, we have to kick it off
  297. * again and wait for it to complete. Note that we explicitly assume
  298. * that hashing zero bytes is always wrong, even though that would
  299. * produce a valid hash value. */
  300. if (hash->status == EC_VBOOT_HASH_STATUS_DONE && hash->size)
  301. return 0;
  302. debug("%s: No valid hash (status=%d size=%d). Compute one...\n",
  303. __func__, hash->status, hash->size);
  304. p.cmd = EC_VBOOT_HASH_RECALC;
  305. p.hash_type = EC_VBOOT_HASH_TYPE_SHA256;
  306. p.nonce_size = 0;
  307. p.offset = EC_VBOOT_HASH_OFFSET_RW;
  308. if (ec_command(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
  309. hash, sizeof(*hash)) < 0)
  310. return -1;
  311. rv = cros_ec_wait_on_hash_done(dev, hash);
  312. if (rv)
  313. return rv;
  314. debug("%s: hash done\n", __func__);
  315. return 0;
  316. }
  317. static int cros_ec_invalidate_hash(struct cros_ec_dev *dev)
  318. {
  319. struct ec_params_vboot_hash p;
  320. struct ec_response_vboot_hash *hash;
  321. /* We don't have an explict command for the EC to discard its current
  322. * hash value, so we'll just tell it to calculate one that we know is
  323. * wrong (we claim that hashing zero bytes is always invalid).
  324. */
  325. p.cmd = EC_VBOOT_HASH_RECALC;
  326. p.hash_type = EC_VBOOT_HASH_TYPE_SHA256;
  327. p.nonce_size = 0;
  328. p.offset = 0;
  329. p.size = 0;
  330. debug("%s:\n", __func__);
  331. if (ec_command_inptr(dev, EC_CMD_VBOOT_HASH, 0, &p, sizeof(p),
  332. (uint8_t **)&hash, sizeof(*hash)) < 0)
  333. return -1;
  334. /* No need to wait for it to finish */
  335. return 0;
  336. }
  337. int cros_ec_reboot(struct cros_ec_dev *dev, enum ec_reboot_cmd cmd,
  338. uint8_t flags)
  339. {
  340. struct ec_params_reboot_ec p;
  341. p.cmd = cmd;
  342. p.flags = flags;
  343. if (ec_command_inptr(dev, EC_CMD_REBOOT_EC, 0, &p, sizeof(p), NULL, 0)
  344. < 0)
  345. return -1;
  346. if (!(flags & EC_REBOOT_FLAG_ON_AP_SHUTDOWN)) {
  347. /*
  348. * EC reboot will take place immediately so delay to allow it
  349. * to complete. Note that some reboot types (EC_REBOOT_COLD)
  350. * will reboot the AP as well, in which case we won't actually
  351. * get to this point.
  352. */
  353. /*
  354. * TODO(rspangler@chromium.org): Would be nice if we had a
  355. * better way to determine when the reboot is complete. Could
  356. * we poll a memory-mapped LPC value?
  357. */
  358. udelay(50000);
  359. }
  360. return 0;
  361. }
  362. int cros_ec_interrupt_pending(struct cros_ec_dev *dev)
  363. {
  364. /* no interrupt support : always poll */
  365. if (!fdt_gpio_isvalid(&dev->ec_int))
  366. return 1;
  367. return !gpio_get_value(dev->ec_int.gpio);
  368. }
  369. int cros_ec_info(struct cros_ec_dev *dev, struct ec_response_cros_ec_info *info)
  370. {
  371. if (ec_command(dev, EC_CMD_CROS_EC_INFO, 0, NULL, 0, info,
  372. sizeof(*info)) < sizeof(*info))
  373. return -1;
  374. return 0;
  375. }
  376. int cros_ec_get_host_events(struct cros_ec_dev *dev, uint32_t *events_ptr)
  377. {
  378. struct ec_response_host_event_mask *resp;
  379. /*
  380. * Use the B copy of the event flags, because the main copy is already
  381. * used by ACPI/SMI.
  382. */
  383. if (ec_command_inptr(dev, EC_CMD_HOST_EVENT_GET_B, 0, NULL, 0,
  384. (uint8_t **)&resp, sizeof(*resp)) < sizeof(*resp))
  385. return -1;
  386. if (resp->mask & EC_HOST_EVENT_MASK(EC_HOST_EVENT_INVALID))
  387. return -1;
  388. *events_ptr = resp->mask;
  389. return 0;
  390. }
  391. int cros_ec_clear_host_events(struct cros_ec_dev *dev, uint32_t events)
  392. {
  393. struct ec_params_host_event_mask params;
  394. params.mask = events;
  395. /*
  396. * Use the B copy of the event flags, so it affects the data returned
  397. * by cros_ec_get_host_events().
  398. */
  399. if (ec_command_inptr(dev, EC_CMD_HOST_EVENT_CLEAR_B, 0,
  400. &params, sizeof(params), NULL, 0) < 0)
  401. return -1;
  402. return 0;
  403. }
  404. int cros_ec_flash_protect(struct cros_ec_dev *dev,
  405. uint32_t set_mask, uint32_t set_flags,
  406. struct ec_response_flash_protect *resp)
  407. {
  408. struct ec_params_flash_protect params;
  409. params.mask = set_mask;
  410. params.flags = set_flags;
  411. if (ec_command(dev, EC_CMD_FLASH_PROTECT, EC_VER_FLASH_PROTECT,
  412. &params, sizeof(params),
  413. resp, sizeof(*resp)) < sizeof(*resp))
  414. return -1;
  415. return 0;
  416. }
  417. static int cros_ec_check_version(struct cros_ec_dev *dev)
  418. {
  419. struct ec_params_hello req;
  420. struct ec_response_hello *resp;
  421. #ifdef CONFIG_CROS_EC_LPC
  422. /* LPC has its own way of doing this */
  423. if (dev->interface == CROS_EC_IF_LPC)
  424. return cros_ec_lpc_check_version(dev);
  425. #endif
  426. /*
  427. * TODO(sjg@chromium.org).
  428. * There is a strange oddity here with the EC. We could just ignore
  429. * the response, i.e. pass the last two parameters as NULL and 0.
  430. * In this case we won't read back very many bytes from the EC.
  431. * On the I2C bus the EC gets upset about this and will try to send
  432. * the bytes anyway. This means that we will have to wait for that
  433. * to complete before continuing with a new EC command.
  434. *
  435. * This problem is probably unique to the I2C bus.
  436. *
  437. * So for now, just read all the data anyway.
  438. */
  439. dev->cmd_version_is_supported = 1;
  440. if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
  441. (uint8_t **)&resp, sizeof(*resp)) > 0) {
  442. /* It appears to understand new version commands */
  443. dev->cmd_version_is_supported = 1;
  444. } else {
  445. dev->cmd_version_is_supported = 0;
  446. if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req,
  447. sizeof(req), (uint8_t **)&resp,
  448. sizeof(*resp)) < 0) {
  449. debug("%s: Failed both old and new command style\n",
  450. __func__);
  451. return -1;
  452. }
  453. }
  454. return 0;
  455. }
  456. int cros_ec_test(struct cros_ec_dev *dev)
  457. {
  458. struct ec_params_hello req;
  459. struct ec_response_hello *resp;
  460. req.in_data = 0x12345678;
  461. if (ec_command_inptr(dev, EC_CMD_HELLO, 0, &req, sizeof(req),
  462. (uint8_t **)&resp, sizeof(*resp)) < sizeof(*resp)) {
  463. printf("ec_command_inptr() returned error\n");
  464. return -1;
  465. }
  466. if (resp->out_data != req.in_data + 0x01020304) {
  467. printf("Received invalid handshake %x\n", resp->out_data);
  468. return -1;
  469. }
  470. return 0;
  471. }
  472. int cros_ec_flash_offset(struct cros_ec_dev *dev, enum ec_flash_region region,
  473. uint32_t *offset, uint32_t *size)
  474. {
  475. struct ec_params_flash_region_info p;
  476. struct ec_response_flash_region_info *r;
  477. int ret;
  478. p.region = region;
  479. ret = ec_command_inptr(dev, EC_CMD_FLASH_REGION_INFO,
  480. EC_VER_FLASH_REGION_INFO,
  481. &p, sizeof(p), (uint8_t **)&r, sizeof(*r));
  482. if (ret != sizeof(*r))
  483. return -1;
  484. if (offset)
  485. *offset = r->offset;
  486. if (size)
  487. *size = r->size;
  488. return 0;
  489. }
  490. int cros_ec_flash_erase(struct cros_ec_dev *dev, uint32_t offset, uint32_t size)
  491. {
  492. struct ec_params_flash_erase p;
  493. p.offset = offset;
  494. p.size = size;
  495. return ec_command_inptr(dev, EC_CMD_FLASH_ERASE, 0, &p, sizeof(p),
  496. NULL, 0);
  497. }
  498. /**
  499. * Write a single block to the flash
  500. *
  501. * Write a block of data to the EC flash. The size must not exceed the flash
  502. * write block size which you can obtain from cros_ec_flash_write_burst_size().
  503. *
  504. * The offset starts at 0. You can obtain the region information from
  505. * cros_ec_flash_offset() to find out where to write for a particular region.
  506. *
  507. * Attempting to write to the region where the EC is currently running from
  508. * will result in an error.
  509. *
  510. * @param dev CROS-EC device
  511. * @param data Pointer to data buffer to write
  512. * @param offset Offset within flash to write to.
  513. * @param size Number of bytes to write
  514. * @return 0 if ok, -1 on error
  515. */
  516. static int cros_ec_flash_write_block(struct cros_ec_dev *dev,
  517. const uint8_t *data, uint32_t offset, uint32_t size)
  518. {
  519. struct ec_params_flash_write p;
  520. p.offset = offset;
  521. p.size = size;
  522. assert(data && p.size <= sizeof(p.data));
  523. memcpy(p.data, data, p.size);
  524. return ec_command_inptr(dev, EC_CMD_FLASH_WRITE, 0,
  525. &p, sizeof(p), NULL, 0) >= 0 ? 0 : -1;
  526. }
  527. /**
  528. * Return optimal flash write burst size
  529. */
  530. static int cros_ec_flash_write_burst_size(struct cros_ec_dev *dev)
  531. {
  532. struct ec_params_flash_write p;
  533. return sizeof(p.data);
  534. }
  535. /**
  536. * Check if a block of data is erased (all 0xff)
  537. *
  538. * This function is useful when dealing with flash, for checking whether a
  539. * data block is erased and thus does not need to be programmed.
  540. *
  541. * @param data Pointer to data to check (must be word-aligned)
  542. * @param size Number of bytes to check (must be word-aligned)
  543. * @return 0 if erased, non-zero if any word is not erased
  544. */
  545. static int cros_ec_data_is_erased(const uint32_t *data, int size)
  546. {
  547. assert(!(size & 3));
  548. size /= sizeof(uint32_t);
  549. for (; size > 0; size -= 4, data++)
  550. if (*data != -1U)
  551. return 0;
  552. return 1;
  553. }
  554. int cros_ec_flash_write(struct cros_ec_dev *dev, const uint8_t *data,
  555. uint32_t offset, uint32_t size)
  556. {
  557. uint32_t burst = cros_ec_flash_write_burst_size(dev);
  558. uint32_t end, off;
  559. int ret;
  560. /*
  561. * TODO: round up to the nearest multiple of write size. Can get away
  562. * without that on link right now because its write size is 4 bytes.
  563. */
  564. end = offset + size;
  565. for (off = offset; off < end; off += burst, data += burst) {
  566. uint32_t todo;
  567. /* If the data is empty, there is no point in programming it */
  568. todo = min(end - off, burst);
  569. if (dev->optimise_flash_write &&
  570. cros_ec_data_is_erased((uint32_t *)data, todo))
  571. continue;
  572. ret = cros_ec_flash_write_block(dev, data, off, todo);
  573. if (ret)
  574. return ret;
  575. }
  576. return 0;
  577. }
  578. /**
  579. * Read a single block from the flash
  580. *
  581. * Read a block of data from the EC flash. The size must not exceed the flash
  582. * write block size which you can obtain from cros_ec_flash_write_burst_size().
  583. *
  584. * The offset starts at 0. You can obtain the region information from
  585. * cros_ec_flash_offset() to find out where to read for a particular region.
  586. *
  587. * @param dev CROS-EC device
  588. * @param data Pointer to data buffer to read into
  589. * @param offset Offset within flash to read from
  590. * @param size Number of bytes to read
  591. * @return 0 if ok, -1 on error
  592. */
  593. static int cros_ec_flash_read_block(struct cros_ec_dev *dev, uint8_t *data,
  594. uint32_t offset, uint32_t size)
  595. {
  596. struct ec_params_flash_read p;
  597. p.offset = offset;
  598. p.size = size;
  599. return ec_command(dev, EC_CMD_FLASH_READ, 0,
  600. &p, sizeof(p), data, size) >= 0 ? 0 : -1;
  601. }
  602. int cros_ec_flash_read(struct cros_ec_dev *dev, uint8_t *data, uint32_t offset,
  603. uint32_t size)
  604. {
  605. uint32_t burst = cros_ec_flash_write_burst_size(dev);
  606. uint32_t end, off;
  607. int ret;
  608. end = offset + size;
  609. for (off = offset; off < end; off += burst, data += burst) {
  610. ret = cros_ec_flash_read_block(dev, data, off,
  611. min(end - off, burst));
  612. if (ret)
  613. return ret;
  614. }
  615. return 0;
  616. }
  617. int cros_ec_flash_update_rw(struct cros_ec_dev *dev,
  618. const uint8_t *image, int image_size)
  619. {
  620. uint32_t rw_offset, rw_size;
  621. int ret;
  622. if (cros_ec_flash_offset(dev, EC_FLASH_REGION_RW, &rw_offset, &rw_size))
  623. return -1;
  624. if (image_size > rw_size)
  625. return -1;
  626. /* Invalidate the existing hash, just in case the AP reboots
  627. * unexpectedly during the update. If that happened, the EC RW firmware
  628. * would be invalid, but the EC would still have the original hash.
  629. */
  630. ret = cros_ec_invalidate_hash(dev);
  631. if (ret)
  632. return ret;
  633. /*
  634. * Erase the entire RW section, so that the EC doesn't see any garbage
  635. * past the new image if it's smaller than the current image.
  636. *
  637. * TODO: could optimize this to erase just the current image, since
  638. * presumably everything past that is 0xff's. But would still need to
  639. * round up to the nearest multiple of erase size.
  640. */
  641. ret = cros_ec_flash_erase(dev, rw_offset, rw_size);
  642. if (ret)
  643. return ret;
  644. /* Write the image */
  645. ret = cros_ec_flash_write(dev, image, rw_offset, image_size);
  646. if (ret)
  647. return ret;
  648. return 0;
  649. }
  650. int cros_ec_read_vbnvcontext(struct cros_ec_dev *dev, uint8_t *block)
  651. {
  652. struct ec_params_vbnvcontext p;
  653. int len;
  654. p.op = EC_VBNV_CONTEXT_OP_READ;
  655. len = ec_command(dev, EC_CMD_VBNV_CONTEXT, EC_VER_VBNV_CONTEXT,
  656. &p, sizeof(p), block, EC_VBNV_BLOCK_SIZE);
  657. if (len < EC_VBNV_BLOCK_SIZE)
  658. return -1;
  659. return 0;
  660. }
  661. int cros_ec_write_vbnvcontext(struct cros_ec_dev *dev, const uint8_t *block)
  662. {
  663. struct ec_params_vbnvcontext p;
  664. int len;
  665. p.op = EC_VBNV_CONTEXT_OP_WRITE;
  666. memcpy(p.block, block, sizeof(p.block));
  667. len = ec_command_inptr(dev, EC_CMD_VBNV_CONTEXT, EC_VER_VBNV_CONTEXT,
  668. &p, sizeof(p), NULL, 0);
  669. if (len < 0)
  670. return -1;
  671. return 0;
  672. }
  673. int cros_ec_set_ldo(struct cros_ec_dev *dev, uint8_t index, uint8_t state)
  674. {
  675. struct ec_params_ldo_set params;
  676. params.index = index;
  677. params.state = state;
  678. if (ec_command_inptr(dev, EC_CMD_LDO_SET, 0,
  679. &params, sizeof(params),
  680. NULL, 0))
  681. return -1;
  682. return 0;
  683. }
  684. int cros_ec_get_ldo(struct cros_ec_dev *dev, uint8_t index, uint8_t *state)
  685. {
  686. struct ec_params_ldo_get params;
  687. struct ec_response_ldo_get *resp;
  688. params.index = index;
  689. if (ec_command_inptr(dev, EC_CMD_LDO_GET, 0,
  690. &params, sizeof(params),
  691. (uint8_t **)&resp, sizeof(*resp)) < sizeof(*resp))
  692. return -1;
  693. *state = resp->state;
  694. return 0;
  695. }
  696. /**
  697. * Decode MBKP details from the device tree and allocate a suitable device.
  698. *
  699. * @param blob Device tree blob
  700. * @param node Node to decode from
  701. * @param devp Returns a pointer to the new allocated device
  702. * @return 0 if ok, -1 on error
  703. */
  704. static int cros_ec_decode_fdt(const void *blob, int node,
  705. struct cros_ec_dev **devp)
  706. {
  707. enum fdt_compat_id compat;
  708. struct cros_ec_dev *dev;
  709. int parent;
  710. /* See what type of parent we are inside (this is expensive) */
  711. parent = fdt_parent_offset(blob, node);
  712. if (parent < 0) {
  713. debug("%s: Cannot find node parent\n", __func__);
  714. return -1;
  715. }
  716. dev = &static_dev;
  717. dev->node = node;
  718. dev->parent_node = parent;
  719. compat = fdtdec_lookup(blob, parent);
  720. switch (compat) {
  721. #ifdef CONFIG_CROS_EC_SPI
  722. case COMPAT_SAMSUNG_EXYNOS_SPI:
  723. dev->interface = CROS_EC_IF_SPI;
  724. if (cros_ec_spi_decode_fdt(dev, blob))
  725. return -1;
  726. break;
  727. #endif
  728. #ifdef CONFIG_CROS_EC_I2C
  729. case COMPAT_SAMSUNG_S3C2440_I2C:
  730. dev->interface = CROS_EC_IF_I2C;
  731. if (cros_ec_i2c_decode_fdt(dev, blob))
  732. return -1;
  733. break;
  734. #endif
  735. #ifdef CONFIG_CROS_EC_LPC
  736. case COMPAT_INTEL_LPC:
  737. dev->interface = CROS_EC_IF_LPC;
  738. break;
  739. #endif
  740. default:
  741. debug("%s: Unknown compat id %d\n", __func__, compat);
  742. return -1;
  743. }
  744. fdtdec_decode_gpio(blob, node, "ec-interrupt", &dev->ec_int);
  745. dev->optimise_flash_write = fdtdec_get_bool(blob, node,
  746. "optimise-flash-write");
  747. *devp = dev;
  748. return 0;
  749. }
  750. int cros_ec_init(const void *blob, struct cros_ec_dev **cros_ecp)
  751. {
  752. char id[MSG_BYTES];
  753. struct cros_ec_dev *dev;
  754. int node = 0;
  755. *cros_ecp = NULL;
  756. do {
  757. node = fdtdec_next_compatible(blob, node,
  758. COMPAT_GOOGLE_CROS_EC);
  759. if (node < 0) {
  760. debug("%s: Node not found\n", __func__);
  761. return 0;
  762. }
  763. } while (!fdtdec_get_is_enabled(blob, node));
  764. if (cros_ec_decode_fdt(blob, node, &dev)) {
  765. debug("%s: Failed to decode device.\n", __func__);
  766. return -CROS_EC_ERR_FDT_DECODE;
  767. }
  768. switch (dev->interface) {
  769. #ifdef CONFIG_CROS_EC_SPI
  770. case CROS_EC_IF_SPI:
  771. if (cros_ec_spi_init(dev, blob)) {
  772. debug("%s: Could not setup SPI interface\n", __func__);
  773. return -CROS_EC_ERR_DEV_INIT;
  774. }
  775. break;
  776. #endif
  777. #ifdef CONFIG_CROS_EC_I2C
  778. case CROS_EC_IF_I2C:
  779. if (cros_ec_i2c_init(dev, blob))
  780. return -CROS_EC_ERR_DEV_INIT;
  781. break;
  782. #endif
  783. #ifdef CONFIG_CROS_EC_LPC
  784. case CROS_EC_IF_LPC:
  785. if (cros_ec_lpc_init(dev, blob))
  786. return -CROS_EC_ERR_DEV_INIT;
  787. break;
  788. #endif
  789. case CROS_EC_IF_NONE:
  790. default:
  791. return 0;
  792. }
  793. /* we will poll the EC interrupt line */
  794. fdtdec_setup_gpio(&dev->ec_int);
  795. if (fdt_gpio_isvalid(&dev->ec_int))
  796. gpio_direction_input(dev->ec_int.gpio);
  797. if (cros_ec_check_version(dev)) {
  798. debug("%s: Could not detect CROS-EC version\n", __func__);
  799. return -CROS_EC_ERR_CHECK_VERSION;
  800. }
  801. if (cros_ec_read_id(dev, id, sizeof(id))) {
  802. debug("%s: Could not read KBC ID\n", __func__);
  803. return -CROS_EC_ERR_READ_ID;
  804. }
  805. /* Remember this device for use by the cros_ec command */
  806. last_dev = *cros_ecp = dev;
  807. debug("Google Chrome EC CROS-EC driver ready, id '%s'\n", id);
  808. return 0;
  809. }
  810. #ifdef CONFIG_CMD_CROS_EC
  811. int cros_ec_decode_region(int argc, char * const argv[])
  812. {
  813. if (argc > 0) {
  814. if (0 == strcmp(*argv, "rw"))
  815. return EC_FLASH_REGION_RW;
  816. else if (0 == strcmp(*argv, "ro"))
  817. return EC_FLASH_REGION_RO;
  818. debug("%s: Invalid region '%s'\n", __func__, *argv);
  819. } else {
  820. debug("%s: Missing region parameter\n", __func__);
  821. }
  822. return -1;
  823. }
  824. /**
  825. * Perform a flash read or write command
  826. *
  827. * @param dev CROS-EC device to read/write
  828. * @param is_write 1 do to a write, 0 to do a read
  829. * @param argc Number of arguments
  830. * @param argv Arguments (2 is region, 3 is address)
  831. * @return 0 for ok, 1 for a usage error or -ve for ec command error
  832. * (negative EC_RES_...)
  833. */
  834. static int do_read_write(struct cros_ec_dev *dev, int is_write, int argc,
  835. char * const argv[])
  836. {
  837. uint32_t offset, size = -1U, region_size;
  838. unsigned long addr;
  839. char *endp;
  840. int region;
  841. int ret;
  842. region = cros_ec_decode_region(argc - 2, argv + 2);
  843. if (region == -1)
  844. return 1;
  845. if (argc < 4)
  846. return 1;
  847. addr = simple_strtoul(argv[3], &endp, 16);
  848. if (*argv[3] == 0 || *endp != 0)
  849. return 1;
  850. if (argc > 4) {
  851. size = simple_strtoul(argv[4], &endp, 16);
  852. if (*argv[4] == 0 || *endp != 0)
  853. return 1;
  854. }
  855. ret = cros_ec_flash_offset(dev, region, &offset, &region_size);
  856. if (ret) {
  857. debug("%s: Could not read region info\n", __func__);
  858. return ret;
  859. }
  860. if (size == -1U)
  861. size = region_size;
  862. ret = is_write ?
  863. cros_ec_flash_write(dev, (uint8_t *)addr, offset, size) :
  864. cros_ec_flash_read(dev, (uint8_t *)addr, offset, size);
  865. if (ret) {
  866. debug("%s: Could not %s region\n", __func__,
  867. is_write ? "write" : "read");
  868. return ret;
  869. }
  870. return 0;
  871. }
  872. static int do_cros_ec(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  873. {
  874. struct cros_ec_dev *dev = last_dev;
  875. const char *cmd;
  876. int ret = 0;
  877. if (argc < 2)
  878. return CMD_RET_USAGE;
  879. cmd = argv[1];
  880. if (0 == strcmp("init", cmd)) {
  881. ret = cros_ec_init(gd->fdt_blob, &dev);
  882. if (ret) {
  883. printf("Could not init cros_ec device (err %d)\n", ret);
  884. return 1;
  885. }
  886. return 0;
  887. }
  888. /* Just use the last allocated device; there should be only one */
  889. if (!last_dev) {
  890. printf("No CROS-EC device available\n");
  891. return 1;
  892. }
  893. if (0 == strcmp("id", cmd)) {
  894. char id[MSG_BYTES];
  895. if (cros_ec_read_id(dev, id, sizeof(id))) {
  896. debug("%s: Could not read KBC ID\n", __func__);
  897. return 1;
  898. }
  899. printf("%s\n", id);
  900. } else if (0 == strcmp("info", cmd)) {
  901. struct ec_response_cros_ec_info info;
  902. if (cros_ec_info(dev, &info)) {
  903. debug("%s: Could not read KBC info\n", __func__);
  904. return 1;
  905. }
  906. printf("rows = %u\n", info.rows);
  907. printf("cols = %u\n", info.cols);
  908. printf("switches = %#x\n", info.switches);
  909. } else if (0 == strcmp("curimage", cmd)) {
  910. enum ec_current_image image;
  911. if (cros_ec_read_current_image(dev, &image)) {
  912. debug("%s: Could not read KBC image\n", __func__);
  913. return 1;
  914. }
  915. printf("%d\n", image);
  916. } else if (0 == strcmp("hash", cmd)) {
  917. struct ec_response_vboot_hash hash;
  918. int i;
  919. if (cros_ec_read_hash(dev, &hash)) {
  920. debug("%s: Could not read KBC hash\n", __func__);
  921. return 1;
  922. }
  923. if (hash.hash_type == EC_VBOOT_HASH_TYPE_SHA256)
  924. printf("type: SHA-256\n");
  925. else
  926. printf("type: %d\n", hash.hash_type);
  927. printf("offset: 0x%08x\n", hash.offset);
  928. printf("size: 0x%08x\n", hash.size);
  929. printf("digest: ");
  930. for (i = 0; i < hash.digest_size; i++)
  931. printf("%02x", hash.hash_digest[i]);
  932. printf("\n");
  933. } else if (0 == strcmp("reboot", cmd)) {
  934. int region;
  935. enum ec_reboot_cmd cmd;
  936. if (argc >= 3 && !strcmp(argv[2], "cold"))
  937. cmd = EC_REBOOT_COLD;
  938. else {
  939. region = cros_ec_decode_region(argc - 2, argv + 2);
  940. if (region == EC_FLASH_REGION_RO)
  941. cmd = EC_REBOOT_JUMP_RO;
  942. else if (region == EC_FLASH_REGION_RW)
  943. cmd = EC_REBOOT_JUMP_RW;
  944. else
  945. return CMD_RET_USAGE;
  946. }
  947. if (cros_ec_reboot(dev, cmd, 0)) {
  948. debug("%s: Could not reboot KBC\n", __func__);
  949. return 1;
  950. }
  951. } else if (0 == strcmp("events", cmd)) {
  952. uint32_t events;
  953. if (cros_ec_get_host_events(dev, &events)) {
  954. debug("%s: Could not read host events\n", __func__);
  955. return 1;
  956. }
  957. printf("0x%08x\n", events);
  958. } else if (0 == strcmp("clrevents", cmd)) {
  959. uint32_t events = 0x7fffffff;
  960. if (argc >= 3)
  961. events = simple_strtol(argv[2], NULL, 0);
  962. if (cros_ec_clear_host_events(dev, events)) {
  963. debug("%s: Could not clear host events\n", __func__);
  964. return 1;
  965. }
  966. } else if (0 == strcmp("read", cmd)) {
  967. ret = do_read_write(dev, 0, argc, argv);
  968. if (ret > 0)
  969. return CMD_RET_USAGE;
  970. } else if (0 == strcmp("write", cmd)) {
  971. ret = do_read_write(dev, 1, argc, argv);
  972. if (ret > 0)
  973. return CMD_RET_USAGE;
  974. } else if (0 == strcmp("erase", cmd)) {
  975. int region = cros_ec_decode_region(argc - 2, argv + 2);
  976. uint32_t offset, size;
  977. if (region == -1)
  978. return CMD_RET_USAGE;
  979. if (cros_ec_flash_offset(dev, region, &offset, &size)) {
  980. debug("%s: Could not read region info\n", __func__);
  981. ret = -1;
  982. } else {
  983. ret = cros_ec_flash_erase(dev, offset, size);
  984. if (ret) {
  985. debug("%s: Could not erase region\n",
  986. __func__);
  987. }
  988. }
  989. } else if (0 == strcmp("regioninfo", cmd)) {
  990. int region = cros_ec_decode_region(argc - 2, argv + 2);
  991. uint32_t offset, size;
  992. if (region == -1)
  993. return CMD_RET_USAGE;
  994. ret = cros_ec_flash_offset(dev, region, &offset, &size);
  995. if (ret) {
  996. debug("%s: Could not read region info\n", __func__);
  997. } else {
  998. printf("Region: %s\n", region == EC_FLASH_REGION_RO ?
  999. "RO" : "RW");
  1000. printf("Offset: %x\n", offset);
  1001. printf("Size: %x\n", size);
  1002. }
  1003. } else if (0 == strcmp("vbnvcontext", cmd)) {
  1004. uint8_t block[EC_VBNV_BLOCK_SIZE];
  1005. char buf[3];
  1006. int i, len;
  1007. unsigned long result;
  1008. if (argc <= 2) {
  1009. ret = cros_ec_read_vbnvcontext(dev, block);
  1010. if (!ret) {
  1011. printf("vbnv_block: ");
  1012. for (i = 0; i < EC_VBNV_BLOCK_SIZE; i++)
  1013. printf("%02x", block[i]);
  1014. putc('\n');
  1015. }
  1016. } else {
  1017. /*
  1018. * TODO(clchiou): Move this to a utility function as
  1019. * cmd_spi might want to call it.
  1020. */
  1021. memset(block, 0, EC_VBNV_BLOCK_SIZE);
  1022. len = strlen(argv[2]);
  1023. buf[2] = '\0';
  1024. for (i = 0; i < EC_VBNV_BLOCK_SIZE; i++) {
  1025. if (i * 2 >= len)
  1026. break;
  1027. buf[0] = argv[2][i * 2];
  1028. if (i * 2 + 1 >= len)
  1029. buf[1] = '0';
  1030. else
  1031. buf[1] = argv[2][i * 2 + 1];
  1032. strict_strtoul(buf, 16, &result);
  1033. block[i] = result;
  1034. }
  1035. ret = cros_ec_write_vbnvcontext(dev, block);
  1036. }
  1037. if (ret) {
  1038. debug("%s: Could not %s VbNvContext\n", __func__,
  1039. argc <= 2 ? "read" : "write");
  1040. }
  1041. } else if (0 == strcmp("test", cmd)) {
  1042. int result = cros_ec_test(dev);
  1043. if (result)
  1044. printf("Test failed with error %d\n", result);
  1045. else
  1046. puts("Test passed\n");
  1047. } else if (0 == strcmp("version", cmd)) {
  1048. struct ec_response_get_version *p;
  1049. char *build_string;
  1050. ret = cros_ec_read_version(dev, &p);
  1051. if (!ret) {
  1052. /* Print versions */
  1053. printf("RO version: %1.*s\n",
  1054. sizeof(p->version_string_ro),
  1055. p->version_string_ro);
  1056. printf("RW version: %1.*s\n",
  1057. sizeof(p->version_string_rw),
  1058. p->version_string_rw);
  1059. printf("Firmware copy: %s\n",
  1060. (p->current_image <
  1061. ARRAY_SIZE(ec_current_image_name) ?
  1062. ec_current_image_name[p->current_image] :
  1063. "?"));
  1064. ret = cros_ec_read_build_info(dev, &build_string);
  1065. if (!ret)
  1066. printf("Build info: %s\n", build_string);
  1067. }
  1068. } else if (0 == strcmp("ldo", cmd)) {
  1069. uint8_t index, state;
  1070. char *endp;
  1071. if (argc < 3)
  1072. return CMD_RET_USAGE;
  1073. index = simple_strtoul(argv[2], &endp, 10);
  1074. if (*argv[2] == 0 || *endp != 0)
  1075. return CMD_RET_USAGE;
  1076. if (argc > 3) {
  1077. state = simple_strtoul(argv[3], &endp, 10);
  1078. if (*argv[3] == 0 || *endp != 0)
  1079. return CMD_RET_USAGE;
  1080. ret = cros_ec_set_ldo(dev, index, state);
  1081. } else {
  1082. ret = cros_ec_get_ldo(dev, index, &state);
  1083. if (!ret) {
  1084. printf("LDO%d: %s\n", index,
  1085. state == EC_LDO_STATE_ON ?
  1086. "on" : "off");
  1087. }
  1088. }
  1089. if (ret) {
  1090. debug("%s: Could not access LDO%d\n", __func__, index);
  1091. return ret;
  1092. }
  1093. } else {
  1094. return CMD_RET_USAGE;
  1095. }
  1096. if (ret < 0) {
  1097. printf("Error: CROS-EC command failed (error %d)\n", ret);
  1098. ret = 1;
  1099. }
  1100. return ret;
  1101. }
  1102. U_BOOT_CMD(
  1103. crosec, 5, 1, do_cros_ec,
  1104. "CROS-EC utility command",
  1105. "init Re-init CROS-EC (done on startup automatically)\n"
  1106. "crosec id Read CROS-EC ID\n"
  1107. "crosec info Read CROS-EC info\n"
  1108. "crosec curimage Read CROS-EC current image\n"
  1109. "crosec hash Read CROS-EC hash\n"
  1110. "crosec reboot [rw | ro | cold] Reboot CROS-EC\n"
  1111. "crosec events Read CROS-EC host events\n"
  1112. "crosec clrevents [mask] Clear CROS-EC host events\n"
  1113. "crosec regioninfo <ro|rw> Read image info\n"
  1114. "crosec erase <ro|rw> Erase EC image\n"
  1115. "crosec read <ro|rw> <addr> [<size>] Read EC image\n"
  1116. "crosec write <ro|rw> <addr> [<size>] Write EC image\n"
  1117. "crosec vbnvcontext [hexstring] Read [write] VbNvContext from EC\n"
  1118. "crosec ldo <idx> [<state>] Switch/Read LDO state\n"
  1119. "crosec test run tests on cros_ec\n"
  1120. "crosec version Read CROS-EC version"
  1121. );
  1122. #endif