Dima Zavin | d085013 | 2009-01-26 20:02:33 -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> |
| 35 | #include <lib/ptable.h> |
| 36 | #include <dev/flash.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 37 | #include <platform.h> |
Dima Zavin | d085013 | 2009-01-26 20:02:33 -0800 | [diff] [blame] | 38 | |
| 39 | #define BOARD_FLASH_OFFSET 378 |
| 40 | |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 41 | #define LINUX_MACHTYPE 0x0000059F |
| 42 | |
Dima Zavin | d085013 | 2009-01-26 20:02:33 -0800 | [diff] [blame] | 43 | static struct ptable flash_ptable; |
| 44 | |
| 45 | /* for these partitions, start will be offset by either what we get from |
| 46 | * smem, or from the above offset if smem is not useful. Also, we should |
| 47 | * probably have smem_ptable code populate our flash_ptable. |
| 48 | * |
| 49 | * When smem provides us with a full partition table, we can get rid of |
| 50 | * this altogether. |
| 51 | * |
| 52 | */ |
| 53 | static struct ptentry board_part_list[] = { |
| 54 | { |
| 55 | .start = 0, |
Dima Zavin | d085013 | 2009-01-26 20:02:33 -0800 | [diff] [blame] | 56 | .length = 40, |
| 57 | .name = "boot", |
| 58 | }, |
| 59 | { |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 60 | .start = 56, |
Dima Zavin | d085013 | 2009-01-26 20:02:33 -0800 | [diff] [blame] | 61 | .length = 608 /* 76MB */, |
| 62 | .name = "system", |
| 63 | }, |
| 64 | { |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 65 | .start = 664, |
| 66 | .length = 608 /* 76MB */, |
| 67 | .name = "cache", |
Dima Zavin | d085013 | 2009-01-26 20:02:33 -0800 | [diff] [blame] | 68 | }, |
| 69 | { |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 70 | .start = 1272, |
| 71 | .length = 0, |
| 72 | .name = "userdata", |
Dima Zavin | d085013 | 2009-01-26 20:02:33 -0800 | [diff] [blame] | 73 | }, |
| 74 | }; |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 75 | static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry); |
Dima Zavin | d085013 | 2009-01-26 20:02:33 -0800 | [diff] [blame] | 76 | |
| 77 | void smem_ptable_init(void); |
| 78 | unsigned smem_get_apps_flash_start(void); |
| 79 | |
| 80 | void keypad_init(void); |
| 81 | |
| 82 | void target_init(void) |
| 83 | { |
Dima Zavin | d085013 | 2009-01-26 20:02:33 -0800 | [diff] [blame] | 84 | unsigned offset; |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 85 | struct flash_info *flash_info; |
| 86 | int i; |
Dima Zavin | d085013 | 2009-01-26 20:02:33 -0800 | [diff] [blame] | 87 | |
| 88 | dprintf(INFO, "target_init()\n"); |
| 89 | |
| 90 | keys_init(); |
| 91 | keypad_init(); |
| 92 | |
| 93 | ptable_init(&flash_ptable); |
| 94 | smem_ptable_init(); |
| 95 | |
Dima Zavin | e5f6435 | 2009-03-02 16:04:20 -0800 | [diff] [blame] | 96 | flash_init(); |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 97 | flash_info = flash_get_info(); |
| 98 | ASSERT(flash_info); |
Dima Zavin | e5f6435 | 2009-03-02 16:04:20 -0800 | [diff] [blame] | 99 | |
Dima Zavin | d085013 | 2009-01-26 20:02:33 -0800 | [diff] [blame] | 100 | offset = smem_get_apps_flash_start(); |
| 101 | if (offset == 0xffffffff) |
| 102 | offset = BOARD_FLASH_OFFSET; |
| 103 | |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 104 | for (i = 0; i < num_parts; i++) { |
| 105 | struct ptentry *ptn = &board_part_list[i]; |
| 106 | unsigned len = ptn->length; |
| 107 | |
| 108 | if ((len == 0) && (i == num_parts - 1)) |
| 109 | len = flash_info->num_blocks - offset - ptn->start; |
Dima Zavin | d085013 | 2009-01-26 20:02:33 -0800 | [diff] [blame] | 110 | ptable_add(&flash_ptable, ptn->name, offset + ptn->start, |
Dima Zavin | 1cf2363 | 2009-03-02 17:24:59 -0800 | [diff] [blame] | 111 | len, ptn->flags); |
Dima Zavin | d085013 | 2009-01-26 20:02:33 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | ptable_dump(&flash_ptable); |
Dima Zavin | e5f6435 | 2009-03-02 16:04:20 -0800 | [diff] [blame] | 115 | flash_set_ptable(&flash_ptable); |
Dima Zavin | d085013 | 2009-01-26 20:02:33 -0800 | [diff] [blame] | 116 | } |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 117 | |
| 118 | unsigned board_machtype(void) |
| 119 | { |
| 120 | return LINUX_MACHTYPE; |
| 121 | } |