blob: 800fe51ca3c3865202b20034deed3ec2bb5c2420 [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
22#include "bootutil/image.h"
23#include "bootutil/bootutil.h"
24
25#if defined(CONFIG_BOARD_FRDM_K64F)
26#define BOOT_FLASH "KSDK_FLASH"
27#elif defined(CONFIG_BOARD_96B_CARBON)
28#define BOOT_FLASH "STM32F4_FLASH"
29#else
30#error "Board is currently not supported by bootloader"
31#endif
32
33struct device *boot_flash_device;
34
35struct vector_table {
36 uint32_t msp;
37 uint32_t reset;
38};
39
40void os_heap_init(void);
41
42void main(void)
43{
44 struct boot_rsp rsp;
45 struct vector_table *vt;
46 int rc;
47
48 os_heap_init();
49
50 boot_flash_device = device_get_binding(BOOT_FLASH);
51 if (!boot_flash_device) {
52 printk("Flash device not found\n");
53 while (1)
54 ;
55 }
56
57 rc = boot_go(&rsp);
58 if (rc != 0) {
59 printk("Unable to find bootable image\n");
60 while (1)
61 ;
62 }
63
64 printk("Bootloader chain: 0x%x\n", rsp.br_image_addr);
65 vt = (struct vector_table *)(rsp.br_image_addr +
66 rsp.br_hdr->ih_hdr_size);
67 irq_lock();
68 _MspSet(vt->msp);
69
70 /* Not all targets set the VTOR, so just set it. */
71 _scs_relocate_vector_table((void *) vt);
72
73 ((void (*)(void))vt->reset)();
74
75 printk("Never should get here\n");
76 while (1)
77 ;
78}