Simon Glass | 6fb6207 | 2012-02-15 15:51:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011-2012 The Chromium OS Authors. |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 3 | * SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 6fb6207 | 2012-02-15 15:51:15 -0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 5c2859c | 2013-11-10 10:27:03 -0700 | [diff] [blame^] | 7 | #include <os.h> |
Simon Glass | 6fb6207 | 2012-02-15 15:51:15 -0800 | [diff] [blame] | 8 | #include <asm/state.h> |
| 9 | |
| 10 | /* Main state record for the sandbox */ |
| 11 | static struct sandbox_state main_state; |
| 12 | static struct sandbox_state *state; /* Pointer to current state record */ |
| 13 | |
| 14 | void state_record_exit(enum exit_type_id exit_type) |
| 15 | { |
| 16 | state->exit_type = exit_type; |
| 17 | } |
| 18 | |
| 19 | struct sandbox_state *state_get_current(void) |
| 20 | { |
| 21 | assert(state); |
| 22 | return state; |
| 23 | } |
| 24 | |
| 25 | int state_init(void) |
| 26 | { |
| 27 | state = &main_state; |
| 28 | |
Simon Glass | 5c2859c | 2013-11-10 10:27:03 -0700 | [diff] [blame^] | 29 | state->ram_size = CONFIG_SYS_SDRAM_SIZE; |
| 30 | state->ram_buf = os_malloc(state->ram_size); |
| 31 | assert(state->ram_buf); |
| 32 | |
Simon Glass | 6fb6207 | 2012-02-15 15:51:15 -0800 | [diff] [blame] | 33 | /* |
| 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 Glass | 5c2859c | 2013-11-10 10:27:03 -0700 | [diff] [blame^] | 41 | |
| 42 | int 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 | } |