blob: 2af6680cf792c7f7f9d21c4b62bf38b999a473e8 [file] [log] [blame]
Christopher Collinscf18a032017-02-06 15:10:45 -08001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#include <assert.h>
21#include <stddef.h>
22#include <inttypes.h>
23#include "syscfg/syscfg.h"
24#include <flash_map/flash_map.h>
25#include <os/os.h>
26#include <bsp/bsp.h>
27#include <hal/hal_bsp.h>
28#include <hal/hal_system.h>
29#include <hal/hal_flash.h>
Fabio Utzig19356bf2017-05-11 16:19:36 -030030#ifdef MCUBOOT_SERIAL
Christopher Collinscf18a032017-02-06 15:10:45 -080031#include <hal/hal_gpio.h>
32#include <boot_serial/boot_serial.h>
33#include <sysinit/sysinit.h>
34#endif
35#include <console/console.h>
36#include "bootutil/image.h"
37#include "bootutil/bootutil.h"
38
39#define BOOT_AREA_DESC_MAX (256)
40#define AREA_DESC_MAX (BOOT_AREA_DESC_MAX)
41
Fabio Utzig19356bf2017-05-11 16:19:36 -030042#ifdef MCUBOOT_SERIAL
Christopher Collinscf18a032017-02-06 15:10:45 -080043#define BOOT_SER_CONS_INPUT 128
44#endif
45
46int
47main(void)
48{
49 struct boot_rsp rsp;
50 int rc;
51
Fabio Utzig19356bf2017-05-11 16:19:36 -030052#ifdef MCUBOOT_SERIAL
Christopher Collinscf18a032017-02-06 15:10:45 -080053 sysinit();
54#else
55 flash_map_init();
56 hal_bsp_init();
57#endif
58
Fabio Utzig19356bf2017-05-11 16:19:36 -030059#ifdef MCUBOOT_SERIAL
Christopher Collinscf18a032017-02-06 15:10:45 -080060 /*
61 * Configure a GPIO as input, and compare it against expected value.
62 * If it matches, await for download commands from serial.
63 */
64 hal_gpio_init_in(BOOT_SERIAL_DETECT_PIN, BOOT_SERIAL_DETECT_PIN_CFG);
65 if (hal_gpio_read(BOOT_SERIAL_DETECT_PIN) == BOOT_SERIAL_DETECT_PIN_VAL) {
66 boot_serial_start(BOOT_SER_CONS_INPUT);
67 assert(0);
68 }
69#endif
70 rc = boot_go(&rsp);
71 assert(rc == 0);
72
Marti Bolivar88f48d92017-05-01 22:30:02 -040073 hal_system_start((void *)(rsp.br_image_off + rsp.br_hdr->ih_hdr_size));
Christopher Collinscf18a032017-02-06 15:10:45 -080074
75 return 0;
76}