Dima Zavin | f8cefec | 2009-01-20 19:25:51 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * * Neither the name of Google, Inc. nor the names of its contributors |
| 15 | * may be used to endorse or promote products derived from this |
| 16 | * software without specific prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 22 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 25 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 26 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 28 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 29 | * SUCH DAMAGE. |
| 30 | */ |
| 31 | |
| 32 | #include <debug.h> |
| 33 | #include <dev/keys.h> |
| 34 | #include <dev/gpio_keypad.h> |
Dima Zavin | 9c6992d | 2009-01-23 16:43:03 -0800 | [diff] [blame] | 35 | #include <lib/ptable.h> |
| 36 | #include <dev/flash.h> |
| 37 | |
| 38 | #define BOARD_FLASH_OFFSET 378 |
| 39 | |
| 40 | static struct ptable flash_ptable; |
| 41 | |
| 42 | /* for these partitions, start will be offset by either what we get from |
| 43 | * smem, or from the above offset if smem is not useful. Also, we should |
| 44 | * probably have smem_ptable code populate our flash_ptable. |
| 45 | * |
| 46 | * When smem provides us with a full partition table, we can get rid of |
| 47 | * this altogether. |
| 48 | * |
| 49 | */ |
| 50 | static struct ptentry board_part_list[] = { |
| 51 | { |
| 52 | .start = 0, |
Dima Zavin | 9c6992d | 2009-01-23 16:43:03 -0800 | [diff] [blame] | 53 | .length = 40, |
| 54 | .name = "boot", |
| 55 | }, |
| 56 | { |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 57 | .start = 56, |
Dima Zavin | 9c6992d | 2009-01-23 16:43:03 -0800 | [diff] [blame] | 58 | .length = 608 /* 76MB */, |
| 59 | .name = "system", |
| 60 | }, |
| 61 | { |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 62 | .start = 664, |
| 63 | .length = 608 /* 76MB */, |
| 64 | .name = "cache", |
Dima Zavin | 9c6992d | 2009-01-23 16:43:03 -0800 | [diff] [blame] | 65 | }, |
| 66 | { |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 67 | .start = 1272, |
| 68 | .length = 0, |
| 69 | .name = "userdata", |
Dima Zavin | 9c6992d | 2009-01-23 16:43:03 -0800 | [diff] [blame] | 70 | }, |
| 71 | }; |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 72 | static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry); |
Dima Zavin | 9c6992d | 2009-01-23 16:43:03 -0800 | [diff] [blame] | 73 | |
| 74 | void smem_ptable_init(void); |
| 75 | unsigned smem_get_apps_flash_start(void); |
Dima Zavin | f8cefec | 2009-01-20 19:25:51 -0800 | [diff] [blame] | 76 | |
| 77 | void keypad_init(void); |
| 78 | |
| 79 | void target_init(void) |
| 80 | { |
Dima Zavin | 9c6992d | 2009-01-23 16:43:03 -0800 | [diff] [blame] | 81 | unsigned offset; |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 82 | struct flash_info *flash_info; |
| 83 | int i; |
Dima Zavin | 9c6992d | 2009-01-23 16:43:03 -0800 | [diff] [blame] | 84 | |
Dima Zavin | f8cefec | 2009-01-20 19:25:51 -0800 | [diff] [blame] | 85 | dprintf(INFO, "target_init()\n"); |
Dima Zavin | 9c6992d | 2009-01-23 16:43:03 -0800 | [diff] [blame] | 86 | |
Dima Zavin | f8cefec | 2009-01-20 19:25:51 -0800 | [diff] [blame] | 87 | keys_init(); |
| 88 | keypad_init(); |
Dima Zavin | 9c6992d | 2009-01-23 16:43:03 -0800 | [diff] [blame] | 89 | |
| 90 | ptable_init(&flash_ptable); |
| 91 | smem_ptable_init(); |
| 92 | |
Dima Zavin | e5f6435 | 2009-03-02 16:04:20 -0800 | [diff] [blame] | 93 | flash_init(); |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 94 | flash_info = flash_get_info(); |
| 95 | ASSERT(flash_info); |
Dima Zavin | e5f6435 | 2009-03-02 16:04:20 -0800 | [diff] [blame] | 96 | |
Dima Zavin | 9c6992d | 2009-01-23 16:43:03 -0800 | [diff] [blame] | 97 | offset = smem_get_apps_flash_start(); |
| 98 | if (offset == 0xffffffff) |
| 99 | offset = BOARD_FLASH_OFFSET; |
| 100 | |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 101 | for (i = 0; i < num_parts; i++) { |
| 102 | struct ptentry *ptn = &board_part_list[i]; |
| 103 | unsigned len = ptn->length; |
| 104 | |
| 105 | if ((len == 0) && (i == num_parts - 1)) |
| 106 | len = flash_info->num_blocks - offset - ptn->start; |
Dima Zavin | 9c6992d | 2009-01-23 16:43:03 -0800 | [diff] [blame] | 107 | ptable_add(&flash_ptable, ptn->name, offset + ptn->start, |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 108 | len, ptn->flags); |
Dima Zavin | 9c6992d | 2009-01-23 16:43:03 -0800 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | ptable_dump(&flash_ptable); |
Dima Zavin | e5f6435 | 2009-03-02 16:04:20 -0800 | [diff] [blame] | 112 | flash_set_ptable(&flash_ptable); |
Dima Zavin | f8cefec | 2009-01-20 19:25:51 -0800 | [diff] [blame] | 113 | } |