David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012-2014 Wind River Systems, Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <zephyr.h> |
| 18 | #include <misc/printk.h> |
| 19 | #include <flash.h> |
| 20 | #include <asm_inline.h> |
| 21 | |
Ricardo Salveti | 3a2c124 | 2017-01-19 10:22:35 -0200 | [diff] [blame] | 22 | #if defined(MCUBOOT_TARGET_CONFIG) |
| 23 | #include MCUBOOT_TARGET_CONFIG |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 24 | #else |
| 25 | #error "Board is currently not supported by bootloader" |
| 26 | #endif |
| 27 | |
Ricardo Salveti | 3a2c124 | 2017-01-19 10:22:35 -0200 | [diff] [blame] | 28 | #include "bootutil/image.h" |
| 29 | #include "bootutil/bootutil.h" |
| 30 | |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 31 | struct device *boot_flash_device; |
| 32 | |
| 33 | struct vector_table { |
| 34 | uint32_t msp; |
| 35 | uint32_t reset; |
| 36 | }; |
| 37 | |
| 38 | void os_heap_init(void); |
| 39 | |
| 40 | void main(void) |
| 41 | { |
| 42 | struct boot_rsp rsp; |
| 43 | struct vector_table *vt; |
| 44 | int rc; |
| 45 | |
| 46 | os_heap_init(); |
| 47 | |
Ricardo Salveti | 3a2c124 | 2017-01-19 10:22:35 -0200 | [diff] [blame] | 48 | boot_flash_device = device_get_binding(FLASH_DRIVER_NAME); |
David Brown | 5153bd6 | 2017-01-06 11:16:53 -0700 | [diff] [blame] | 49 | if (!boot_flash_device) { |
| 50 | printk("Flash device not found\n"); |
| 51 | while (1) |
| 52 | ; |
| 53 | } |
| 54 | |
| 55 | rc = boot_go(&rsp); |
| 56 | if (rc != 0) { |
| 57 | printk("Unable to find bootable image\n"); |
| 58 | while (1) |
| 59 | ; |
| 60 | } |
| 61 | |
| 62 | printk("Bootloader chain: 0x%x\n", rsp.br_image_addr); |
| 63 | vt = (struct vector_table *)(rsp.br_image_addr + |
| 64 | rsp.br_hdr->ih_hdr_size); |
| 65 | irq_lock(); |
| 66 | _MspSet(vt->msp); |
| 67 | |
| 68 | /* Not all targets set the VTOR, so just set it. */ |
| 69 | _scs_relocate_vector_table((void *) vt); |
| 70 | |
| 71 | ((void (*)(void))vt->reset)(); |
| 72 | |
| 73 | printk("Never should get here\n"); |
| 74 | while (1) |
| 75 | ; |
| 76 | } |