blob: 0380fe279182a687101dbd96293b2e377b8ecba9 [file] [log] [blame]
Simon Glass6fb62072012-02-15 15:51:15 -08001/*
2 * Copyright (c) 2011-2012 The Chromium OS Authors.
Wolfgang Denk1a459662013-07-08 09:37:19 +02003 * SPDX-License-Identifier: GPL-2.0+
Simon Glass6fb62072012-02-15 15:51:15 -08004 */
5
6#include <common.h>
Simon Glass5c2859c2013-11-10 10:27:03 -07007#include <os.h>
Simon Glass6fb62072012-02-15 15:51:15 -08008#include <asm/state.h>
9
10/* Main state record for the sandbox */
11static struct sandbox_state main_state;
12static struct sandbox_state *state; /* Pointer to current state record */
13
14void state_record_exit(enum exit_type_id exit_type)
15{
16 state->exit_type = exit_type;
17}
18
19struct sandbox_state *state_get_current(void)
20{
21 assert(state);
22 return state;
23}
24
25int state_init(void)
26{
27 state = &main_state;
28
Simon Glass5c2859c2013-11-10 10:27:03 -070029 state->ram_size = CONFIG_SYS_SDRAM_SIZE;
30 state->ram_buf = os_malloc(state->ram_size);
31 assert(state->ram_buf);
32
Simon Glass6fb62072012-02-15 15:51:15 -080033 /*
34 * Example of how to use GPIOs:
35 *
36 * sandbox_gpio_set_direction(170, 0);
37 * sandbox_gpio_set_value(170, 0);
38 */
39 return 0;
40}
Simon Glass5c2859c2013-11-10 10:27:03 -070041
42int state_uninit(void)
43{
44 int err;
45
46 state = &main_state;
47
48 if (state->write_ram_buf) {
49 err = os_write_ram_buf(state->ram_buf_fname);
50 if (err) {
51 printf("Failed to write RAM buffer\n");
52 return err;
53 }
54 }
55
56 return 0;
57}