blob: 026fc925efcf077a7c85f6063465ad0e33b1e679 [file] [log] [blame]
David Brown5153bd62017-01-06 11:16:53 -07001/*
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 Salveti3a2c1242017-01-19 10:22:35 -020022#if defined(MCUBOOT_TARGET_CONFIG)
23#include MCUBOOT_TARGET_CONFIG
David Brown5153bd62017-01-06 11:16:53 -070024#else
25#error "Board is currently not supported by bootloader"
26#endif
27
Ricardo Salveti3a2c1242017-01-19 10:22:35 -020028#include "bootutil/image.h"
29#include "bootutil/bootutil.h"
30
David Brown5153bd62017-01-06 11:16:53 -070031struct device *boot_flash_device;
32
33struct vector_table {
34 uint32_t msp;
35 uint32_t reset;
36};
37
38void os_heap_init(void);
39
40void main(void)
41{
42 struct boot_rsp rsp;
43 struct vector_table *vt;
44 int rc;
45
46 os_heap_init();
47
Ricardo Salveti3a2c1242017-01-19 10:22:35 -020048 boot_flash_device = device_get_binding(FLASH_DRIVER_NAME);
David Brown5153bd62017-01-06 11:16:53 -070049 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}