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