Lines Matching refs:state

14 #include <asm/state.h>
17 /* Main state record for the sandbox */
19 static struct sandbox_state *state; /* Pointer to current state record */
23 void *blob = state->state_fdt;
46 state->state_fdt = buf;
50 static int state_read_file(struct sandbox_state *state, const char *fname)
58 printf("Cannot find sandbox state file '%s'\n", fname);
61 state->state_fdt = os_malloc(size);
62 if (!state->state_fdt) {
63 puts("No memory to read sandbox state\n");
68 printf("Cannot open sandbox state file '%s'\n", fname);
72 if (os_read(fd, state->state_fdt, size) != size) {
73 printf("Cannot read sandbox state file '%s'\n", fname);
87 os_free(state->state_fdt);
88 state->state_fdt = NULL;
94 * sandbox_read_state_nodes() - Read state associated with a driver
97 * each one, to read in the state.
100 * single global state for that driver.
102 * @state: Sandbox state
103 * @io: Method to use for reading state
104 * @blob: FDT containing state
107 int sandbox_read_state_nodes(struct sandbox_state *state,
127 printf("Unable to read state for '%s'\n", io->compat);
134 * If we got no saved state, call the read function once without a
135 * node, to set up the global state.
141 printf("Unable to read global state for '%s'\n",
150 int sandbox_read_state(struct sandbox_state *state, const char *fname)
157 if (state->read_state && fname) {
158 ret = state_read_file(state, fname);
159 if (ret == -ENOENT && state->ignore_missing_state_on_read)
165 /* Call all the state read functions */
167 blob = state->state_fdt;
170 ret = sandbox_read_state_nodes(state, io, blob);
175 if (state->read_state && fname) {
176 debug("Read sandbox state from '%s'%s\n", fname,
184 * sandbox_write_state_node() - Write state associated with a driver
186 * This calls the write function to write out global state for that driver.
188 * TODO(sjg@chromium.org): Support writing out state from multiple drivers
192 * @state: Sandbox state
193 * @io: Method to use for writing state
197 int sandbox_write_state_node(struct sandbox_state *state,
209 printf("Failed to add more space for state\n");
214 blob = state->state_fdt;
233 debug("Write state for '%s' to node %d\n", io->compat, node);
236 printf("Unable to write state for '%s'\n", io->compat);
243 int sandbox_write_state(struct sandbox_state *state, const char *fname)
251 /* Create a state FDT if we don't have one */
252 if (!state->state_fdt) {
254 state->state_fdt = os_malloc(size);
255 if (!state->state_fdt) {
259 ret = fdt_create_empty_tree(state->state_fdt, size);
261 printf("Cannot create empty state FDT: %s\n",
268 /* Call all the state write funtcions */
273 ret = sandbox_write_state_node(state, io);
281 printf("Could not write sandbox state\n");
285 ret = fdt_pack(state->state_fdt);
287 printf("Cannot pack state FDT: %s\n", fdt_strerror(ret));
291 size = fdt_totalsize(state->state_fdt);
294 printf("Cannot open sandbox state file '%s'\n", fname);
298 if (os_write(fd, state->state_fdt, size) != size) {
299 printf("Cannot write sandbox state file '%s'\n", fname);
305 debug("Wrote sandbox state to '%s'%s\n", fname,
312 os_free(state->state_fdt);
323 fdt_getprop(state->state_fdt, node, prop_name, &len);
331 blob = state->state_fdt;
345 assert(state);
346 return state;
351 struct sandbox_state *state = state_get_current();
353 state->skip_delays = skip_delays;
358 struct sandbox_state *state = state_get_current();
360 return state->skip_delays;
363 void state_reset_for_test(struct sandbox_state *state)
366 state->last_sysreset = SYSRESET_COUNT;
367 state->sysreset_allowed[SYSRESET_POWER_OFF] = true;
368 state->sysreset_allowed[SYSRESET_COLD] = true;
369 state->allow_memio = false;
372 memset(&state->wdt, '\0', sizeof(state->wdt));
373 memset(state->spi, '\0', sizeof(state->spi));
380 INIT_LIST_HEAD(&state->mapmem_head);
381 state->next_tag = state->ram_size;
386 struct sandbox_state *state = state_get_current();
388 return IS_ENABLED(CONFIG_AUTOBOOT_KEYED) && state->autoboot_keyed;
393 struct sandbox_state *state = state_get_current();
394 bool old_val = state->autoboot_keyed;
396 state->autoboot_keyed = autoboot_keyed;
403 struct sandbox_state *state = state_get_current();
409 p = strrchr(state->argv[0], '/');
410 prog_len = p ? p - state->argv[0] : 0;
416 strncpy(buf, state->argv[0], prog_len);
425 struct sandbox_state *state = state_get_current();
430 if (!state->other_fdt_buf) {
436 ret = os_read_file(fname, &state->other_fdt_buf,
437 &state->other_size);
443 *bufp = state->other_fdt_buf;
444 *sizep = state->other_size;
451 struct sandbox_state *state = state_get_current();
453 state->disable_eth = !enable;
458 struct sandbox_state *state = state_get_current();
460 return !state->disable_eth;
465 struct sandbox_state *state = state_get_current();
467 state->disable_sf_bootdevs = !enable;
472 struct sandbox_state *state = state_get_current();
474 return !state->disable_sf_bootdevs;
479 state = &main_state;
481 state->ram_size = CFG_SYS_SDRAM_SIZE;
482 state->ram_buf = os_malloc(state->ram_size);
483 if (!state->ram_buf) {
488 state_reset_for_test(state);
502 if (state->write_ram_buf || state->write_state)
503 log_debug("Writing sandbox state\n");
504 state = &main_state;
509 if (state->write_ram_buf) {
510 err = os_write_ram_buf(state->ram_buf_fname);
515 log_debug("Wrote RAM to file '%s'\n", state->ram_buf_fname);
518 if (state->write_state) {
519 if (sandbox_write_state(state, state->state_fname)) {
520 printf("Failed to write sandbox state\n");
523 log_debug("Wrote state to file '%s'\n", state->ram_buf_fname);
527 if (state->jumped_fname)
528 os_unlink(state->jumped_fname);
534 os_free(state->state_fdt);
535 os_free(state->ram_buf);
536 memset(state, '\0', sizeof(*state));