Christopher Collins | cf18a03 | 2017-02-06 15:10:45 -0800 | [diff] [blame] | 1 | /* |
| 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 Utzig | 19356bf | 2017-05-11 16:19:36 -0300 | [diff] [blame] | 30 | #ifdef MCUBOOT_SERIAL |
Christopher Collins | cf18a03 | 2017-02-06 15:10:45 -0800 | [diff] [blame] | 31 | #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 Utzig | 19356bf | 2017-05-11 16:19:36 -0300 | [diff] [blame] | 42 | #ifdef MCUBOOT_SERIAL |
Christopher Collins | cf18a03 | 2017-02-06 15:10:45 -0800 | [diff] [blame] | 43 | #define BOOT_SER_CONS_INPUT 128 |
| 44 | #endif |
| 45 | |
Marti Bolivar | eb94080 | 2017-05-01 23:15:29 -0400 | [diff] [blame^] | 46 | /* |
| 47 | * Temporary flash_device_base() implementation. |
| 48 | * |
| 49 | * TODO: remove this when mynewt needs to support flash_device_base() |
| 50 | * for devices with nonzero base addresses. |
| 51 | */ |
| 52 | int flash_device_base(uint8_t fd_id, uintptr_t *ret) |
| 53 | { |
| 54 | *ret = 0; |
| 55 | return 0; |
| 56 | } |
| 57 | |
Christopher Collins | cf18a03 | 2017-02-06 15:10:45 -0800 | [diff] [blame] | 58 | int |
| 59 | main(void) |
| 60 | { |
| 61 | struct boot_rsp rsp; |
Marti Bolivar | eb94080 | 2017-05-01 23:15:29 -0400 | [diff] [blame^] | 62 | uintptr_t flash_base; |
Christopher Collins | cf18a03 | 2017-02-06 15:10:45 -0800 | [diff] [blame] | 63 | int rc; |
| 64 | |
Fabio Utzig | 19356bf | 2017-05-11 16:19:36 -0300 | [diff] [blame] | 65 | #ifdef MCUBOOT_SERIAL |
Christopher Collins | cf18a03 | 2017-02-06 15:10:45 -0800 | [diff] [blame] | 66 | sysinit(); |
| 67 | #else |
| 68 | flash_map_init(); |
| 69 | hal_bsp_init(); |
| 70 | #endif |
| 71 | |
Fabio Utzig | 19356bf | 2017-05-11 16:19:36 -0300 | [diff] [blame] | 72 | #ifdef MCUBOOT_SERIAL |
Christopher Collins | cf18a03 | 2017-02-06 15:10:45 -0800 | [diff] [blame] | 73 | /* |
| 74 | * Configure a GPIO as input, and compare it against expected value. |
| 75 | * If it matches, await for download commands from serial. |
| 76 | */ |
| 77 | hal_gpio_init_in(BOOT_SERIAL_DETECT_PIN, BOOT_SERIAL_DETECT_PIN_CFG); |
| 78 | if (hal_gpio_read(BOOT_SERIAL_DETECT_PIN) == BOOT_SERIAL_DETECT_PIN_VAL) { |
| 79 | boot_serial_start(BOOT_SER_CONS_INPUT); |
| 80 | assert(0); |
| 81 | } |
| 82 | #endif |
| 83 | rc = boot_go(&rsp); |
| 84 | assert(rc == 0); |
| 85 | |
Marti Bolivar | eb94080 | 2017-05-01 23:15:29 -0400 | [diff] [blame^] | 86 | rc = flash_device_base(rsp->br_flash_dev_id, &flash_base); |
| 87 | assert(rc == 0); |
| 88 | |
| 89 | hal_system_start((void *)(flash_base + rsp.br_image_off + |
| 90 | rsp.br_hdr->ih_hdr_size)); |
Christopher Collins | cf18a03 | 2017-02-06 15:10:45 -0800 | [diff] [blame] | 91 | |
| 92 | return 0; |
| 93 | } |