|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * |
| 4 | + * Copyright (c) 2017-2019 Linaro LTD |
| 5 | + * Copyright (c) 2016-2019 JUUL Labs |
| 6 | + * Copyright (c) 2019-2020 Arm Limited |
| 7 | + * Copyright (c) 2020 Nordic Semiconductor ASA |
| 8 | + * |
| 9 | + * Original license: |
| 10 | + * |
| 11 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 12 | + * or more contributor license agreements. See the NOTICE file |
| 13 | + * distributed with this work for additional information |
| 14 | + * regarding copyright ownership. The ASF licenses this file |
| 15 | + * to you under the Apache License, Version 2.0 (the |
| 16 | + * "License"); you may not use this file except in compliance |
| 17 | + * with the License. You may obtain a copy of the License at |
| 18 | + * |
| 19 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 20 | + * |
| 21 | + * Unless required by applicable law or agreed to in writing, |
| 22 | + * software distributed under the License is distributed on an |
| 23 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 24 | + * KIND, either express or implied. See the License for the |
| 25 | + * specific language governing permissions and limitations |
| 26 | + * under the License. |
| 27 | + */ |
| 28 | + |
| 29 | +#ifndef H_BOOTUTIL_PUBLIC |
| 30 | +#define H_BOOTUTIL_PUBLIC |
| 31 | + |
| 32 | +#include <inttypes.h> |
| 33 | +#include <string.h> |
| 34 | +#include <flash_map_backend/flash_map_backend.h> |
| 35 | + |
| 36 | +#ifdef __cplusplus |
| 37 | +extern "C" { |
| 38 | +#endif |
| 39 | + |
| 40 | +/** Attempt to boot the contents of the primary slot. */ |
| 41 | +#define BOOT_SWAP_TYPE_NONE 1 |
| 42 | + |
| 43 | +/** |
| 44 | + * Swap to the secondary slot. |
| 45 | + * Absent a confirm command, revert back on next boot. |
| 46 | + */ |
| 47 | +#define BOOT_SWAP_TYPE_TEST 2 |
| 48 | + |
| 49 | +/** |
| 50 | + * Swap to the secondary slot, |
| 51 | + * and permanently switch to booting its contents. |
| 52 | + */ |
| 53 | +#define BOOT_SWAP_TYPE_PERM 3 |
| 54 | + |
| 55 | +/** Swap back to alternate slot. A confirm changes this state to NONE. */ |
| 56 | +#define BOOT_SWAP_TYPE_REVERT 4 |
| 57 | + |
| 58 | +/** Swap failed because image to be run is not valid */ |
| 59 | +#define BOOT_SWAP_TYPE_FAIL 5 |
| 60 | + |
| 61 | +/** Swapping encountered an unrecoverable error */ |
| 62 | +#define BOOT_SWAP_TYPE_PANIC 0xff |
| 63 | + |
| 64 | +#define BOOT_MAX_ALIGN 8 |
| 65 | + |
| 66 | +#define BOOT_MAGIC_GOOD 1 |
| 67 | +#define BOOT_MAGIC_BAD 2 |
| 68 | +#define BOOT_MAGIC_UNSET 3 |
| 69 | +#define BOOT_MAGIC_ANY 4 /* NOTE: control only, not dependent on sector */ |
| 70 | +#define BOOT_MAGIC_NOTGOOD 5 /* NOTE: control only, not dependent on sector */ |
| 71 | + |
| 72 | +/* |
| 73 | + * NOTE: leave BOOT_FLAG_SET equal to one, this is written to flash! |
| 74 | + */ |
| 75 | +#define BOOT_FLAG_SET 1 |
| 76 | +#define BOOT_FLAG_BAD 2 |
| 77 | +#define BOOT_FLAG_UNSET 3 |
| 78 | +#define BOOT_FLAG_ANY 4 /* NOTE: control only, not dependent on sector */ |
| 79 | + |
| 80 | +#define BOOT_MAGIC_SZ (sizeof boot_img_magic) |
| 81 | + |
| 82 | +int boot_swap_type_multi(int image_index); |
| 83 | +int boot_swap_type(void); |
| 84 | + |
| 85 | +int boot_set_pending(int permanent); |
| 86 | +int boot_set_confirmed(void); |
| 87 | +uint32_t boot_swap_info_off(const struct flash_area *fap); |
| 88 | + |
| 89 | +#define BOOT_MAGIC_ARR_SZ \ |
| 90 | + (sizeof boot_img_magic / sizeof boot_img_magic[0]) |
| 91 | + |
| 92 | +extern const uint32_t boot_img_magic[4]; |
| 93 | + |
| 94 | + |
| 95 | +#ifdef __cplusplus |
| 96 | +} |
| 97 | +#endif |
| 98 | + |
| 99 | +#endif |
0 commit comments