Lines Matching full:ec

23  * Ultimately it shold be possible to connect an Chrome OS EC emulation
31 * into key scan data, passed back from the EC as key scan messages. The
36 * 3. Save/restore of EC state, so that the vboot context, flash memory
38 * since the EC is supposed to continue running even if the AP resets.
41 * to enter recovery mode. The EC passes this to U-Boot through the normal
47 * 6. Hashing of the EC image, again to support software sync.
50 * the EC image in with U-Boot (Vic has demonstrated a prototype for this).
64 * struct ec_state - Information about the EC state
66 * @vbnv_context: Vboot context data stored by EC
67 * @ec_config: FDT config information about the EC (e.g. flashmap)
70 * @current_image: Current image the EC is running
89 * cros_ec_read_state() - read the sandbox EC state from the state file
92 * not this function sets up an empty EC.
99 struct ec_state *ec = &s_state; in cros_ec_read_state() local
104 ec->current_image = EC_IMAGE_RO; in cros_ec_read_state()
109 ec->current_image = fdtdec_get_int(blob, node, "current-image", in cros_ec_read_state()
112 if (prop && len == sizeof(ec->vbnv_context)) in cros_ec_read_state()
113 memcpy(ec->vbnv_context, prop, len); in cros_ec_read_state()
117 ec->flash_data_len = len; in cros_ec_read_state()
118 ec->flash_data = os_malloc(len); in cros_ec_read_state()
119 if (!ec->flash_data) in cros_ec_read_state()
121 memcpy(ec->flash_data, prop, len); in cros_ec_read_state()
122 debug("%s: Loaded EC flash data size %#x\n", __func__, len); in cros_ec_read_state()
139 struct ec_state *ec = g_state; in cros_ec_write_state() local
142 fdt_setprop_u32(blob, node, "current-image", ec->current_image); in cros_ec_write_state()
143 fdt_setprop(blob, node, "vbnv-context", ec->vbnv_context, in cros_ec_write_state()
144 sizeof(ec->vbnv_context)); in cros_ec_write_state()
145 return state_setprop(node, "flash-data", ec->flash_data, in cros_ec_write_state()
146 ec->ec_config.flash.length); in cros_ec_write_state()
149 SANDBOX_STATE_IO(cros_ec, "google,cros-ec", cros_ec_read_state,
157 * that used by the real EC code base.
159 * @param ec Current emulated EC state
164 static int get_image_used(struct ec_state *ec, struct fmap_entry *entry) in get_image_used() argument
170 * last byte of the image. See ec.lds.S for how this is inserted at in get_image_used()
174 size > 0 && ec->flash_data[entry->offset + size] != 0xea; in get_image_used()
187 * @param ec Current emulated EC state
191 static int keyscan_read_fdt_matrix(struct ec_state *ec, ofnode node) in keyscan_read_fdt_matrix() argument
198 ec->matrix_count = len / 4; in keyscan_read_fdt_matrix()
199 ec->matrix = calloc(ec->matrix_count, sizeof(*ec->matrix)); in keyscan_read_fdt_matrix()
200 if (!ec->matrix) { in keyscan_read_fdt_matrix()
206 for (upto = 0; upto < ec->matrix_count; upto++) { in keyscan_read_fdt_matrix()
207 struct ec_keymatrix_entry *matrix = &ec->matrix[upto]; in keyscan_read_fdt_matrix()
224 if (upto != ec->matrix_count) { in keyscan_read_fdt_matrix()
235 * @param ec Current emulated EC state
240 static int cros_ec_keyscan(struct ec_state *ec, uint8_t *scan) in cros_ec_keyscan() argument
248 memset(ec->keyscan, '\0', bytes); in cros_ec_keyscan()
252 for (i = 0, matrix = ec->matrix; i < ec->matrix_count; i++, matrix++) { in cros_ec_keyscan()
264 ec->keyscan[matrix->col] |= 1 << matrix->row; in cros_ec_keyscan()
268 memcpy(scan, ec->keyscan, bytes); in cros_ec_keyscan()
273 * Process an emulated EC command
275 * @param ec Current emulated EC state
282 static int process_cmd(struct ec_state *ec, in process_cmd() argument
289 debug("EC command %#0x\n", req_hdr->command); in process_cmd()
305 resp->current_image = ec->current_image; in process_cmd()
317 memcpy(resp->block, ec->vbnv_context, in process_cmd()
323 memcpy(ec->vbnv_context, req->block, in process_cmd()
343 ec->current_image = EC_IMAGE_RW; in process_cmd()
356 if (ec->recovery_req) { in process_cmd()
370 entry = &ec->ec_config.region[EC_FLASH_REGION_ACTIVE]; in process_cmd()
376 len = get_image_used(ec, entry); in process_cmd()
378 ec->flash_data + entry->offset, in process_cmd()
427 entry = &ec->ec_config.region[req->region]; in process_cmd()
431 printf("EC flash region %d: offset=%#x, size=%#x\n", in process_cmd()
443 memset(ec->flash_data + req->offset, in process_cmd()
444 ec->ec_config.flash_erase_value, in process_cmd()
452 memcpy(ec->flash_data + req->offset, req + 1, req->size); in process_cmd()
457 len = cros_ec_keyscan(ec, resp_data); in process_cmd()
463 printf(" ** Unknown EC command %#02x\n", req_hdr->command); in process_cmd()
473 struct ec_state *ec = dev_get_priv(dev->dev); in cros_ec_sandbox_packet() local
480 len = process_cmd(ec, req_hdr, req_data, resp_hdr, resp_data); in cros_ec_sandbox_packet()
498 struct ec_state *ec = dev_get_priv(dev); in cros_ec_check_keyboard() local
501 printf("Press keys for EC to detect on reset (ESC=recovery)..."); in cros_ec_check_keyboard()
507 ec->recovery_req = true; in cros_ec_check_keyboard()
508 printf(" - EC requests recovery\n"); in cros_ec_check_keyboard()
514 struct ec_state *ec = dev->priv; in cros_ec_probe() local
520 memcpy(ec, &s_state, sizeof(*ec)); in cros_ec_probe()
521 err = cros_ec_decode_ec_flash(dev, &ec->ec_config); in cros_ec_probe()
523 debug("%s: Cannot device EC flash\n", __func__); in cros_ec_probe()
538 } else if (keyscan_read_fdt_matrix(ec, node)) { in cros_ec_probe()
543 /* If we loaded EC data, check that the length matches */ in cros_ec_probe()
544 if (ec->flash_data && in cros_ec_probe()
545 ec->flash_data_len != ec->ec_config.flash.length) { in cros_ec_probe()
546 printf("EC data length is %x, expected %x, discarding data\n", in cros_ec_probe()
547 ec->flash_data_len, ec->ec_config.flash.length); in cros_ec_probe()
548 os_free(ec->flash_data); in cros_ec_probe()
549 ec->flash_data = NULL; in cros_ec_probe()
553 if (!ec->flash_data) { in cros_ec_probe()
554 ec->flash_data_len = ec->ec_config.flash.length; in cros_ec_probe()
555 ec->flash_data = os_malloc(ec->flash_data_len); in cros_ec_probe()
556 if (!ec->flash_data) in cros_ec_probe()
561 g_state = ec; in cros_ec_probe()
570 { .compatible = "google,cros-ec-sandbox" },