github.com/meulengracht/snapd@v0.0.0-20210719210640-8bde69bcc84e/include/lk/snappy_boot_v1.h (about) 1 /** 2 * Copyright (C) 2019 Canonical Ltd 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License version 3 as 6 * published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 * 16 */ 17 18 #include "snappy_boot_common.h" 19 20 #ifndef _BOOTLOADER_SNAP_BOOT_V1_H 21 #define _BOOTLOADER_SNAP_BOOT_V1_H 22 23 #define SNAP_BOOTSELECT_VERSION 0x00010001 24 #define SNAP_BOOTSELECT_VERSION_V1 0x00010001 25 26 /* number of available bootimg partitions, min 2 */ 27 #define SNAP_BOOTIMG_PART_NUM 2 28 29 /* snappy bootselect partition format structure */ 30 typedef struct SNAP_BOOT_SELECTION { 31 /* Contains value BOOTSELECT_SIGNATURE defined above */ 32 uint32_t signature; 33 /* snappy boot select version */ 34 uint32_t version; 35 36 /* snap_mode, one of: 'empty', "try", "trying" */ 37 char snap_mode[SNAP_NAME_MAX_LEN]; 38 /* current core snap revision */ 39 char snap_core[SNAP_NAME_MAX_LEN]; 40 /* try core snap revision */ 41 char snap_try_core[SNAP_NAME_MAX_LEN]; 42 /* current kernel snap revision */ 43 char snap_kernel[SNAP_NAME_MAX_LEN]; 44 /* current try kernel snap revision */ 45 char snap_try_kernel[SNAP_NAME_MAX_LEN]; 46 47 /* gadget_mode, one of: 'empty', "try", "trying" */ 48 char gadget_mode[SNAP_NAME_MAX_LEN]; 49 /* GADGET assets: current gadget assets revision */ 50 char snap_gadget[SNAP_NAME_MAX_LEN]; 51 /* GADGET assets: try gadget assets revision */ 52 char snap_try_gadget[SNAP_NAME_MAX_LEN]; 53 54 /** 55 * Reboot reason 56 * optional parameter to signal bootloader alternative reboot reasons 57 * e.g. recovery/factory-reset/boot asset update 58 */ 59 char reboot_reason[SNAP_NAME_MAX_LEN]; 60 61 /** 62 * Matrix for mapping of boot img partition to installed kernel snap revision 63 * 64 * First column represents boot image partition label (e.g. boot_a,boot_b ) 65 * value are static and should be populated at gadget built time 66 * or latest at image build time. Values are not further altered at run time. 67 * Second column represents name currently installed kernel snap 68 * e.g. pi2-kernel_123.snap 69 * initial value representing initial kernel snap revision 70 * is populated at image build time by snapd 71 * 72 * There are two rows in the matrix, representing current and previous kernel revision 73 * following describes how this matrix should be modified at different stages: 74 * - at image build time: 75 * - extracted kernel snap revision name should be filled 76 * into free slot (first row, second column) 77 * - snapd: 78 * - when new kernel snap revision is being installed, snapd cycles through 79 * matrix to find unused 'boot slot' to be used for new kernel snap revision 80 * from free slot, first column represents partition label to which kernel 81 * snap boot image should be extracted. Second column is then populated with 82 * kernel snap revision name. 83 * - snap_mode, snap_try_kernel, snap_try_core behaves same way as with u-boot 84 * - bootloader: 85 * - bootloader reads snap_mode to determine if snap_kernel or snap_kernel is used 86 * to get kernel snap revision name 87 * kernel snap revision is then used to search matrix to determine 88 * partition label to be used for current boot 89 * - bootloader NEVER alters this matrix values 90 * 91 * [ <bootimg 1 part label> ] [ <kernel snap revision installed in this boot partition> ] 92 * [ <bootimg 2 part label> ] [ <kernel snap revision installed in this boot partition> ] 93 */ 94 char bootimg_matrix[SNAP_BOOTIMG_PART_NUM][2][SNAP_NAME_MAX_LEN]; 95 96 /* name of the boot image from kernel snap to be used for extraction 97 when not defined or empty, default boot.img will be used */ 98 char bootimg_file_name[SNAP_NAME_MAX_LEN]; 99 100 /** 101 * gadget assets: Matrix for mapping of gadget asset partitions 102 * Optional boot asset tracking, based on bootloader support 103 * Some boot chains support A/B boot assets for increased robustness 104 * example being A/B TrustExecutionEnvironment 105 * This matrix can be used to track current and try boot assets for 106 * robust updates 107 * Use of Gadget_asset_matrix matches use of Bootimg_matrix 108 * 109 * [ <boot assets 1 part label> ] [ <currently installed assets revision in this partition> ] 110 * [ <boot assets 2 part label> ] [ <currently installed assets revision in this partition> ] 111 */ 112 char gadget_asset_matrix[SNAP_BOOTIMG_PART_NUM][2][SNAP_NAME_MAX_LEN]; 113 114 /* unused placeholders for additional parameters to be used in the future */ 115 char unused_key_01[SNAP_NAME_MAX_LEN]; 116 char unused_key_02[SNAP_NAME_MAX_LEN]; 117 char unused_key_03[SNAP_NAME_MAX_LEN]; 118 char unused_key_04[SNAP_NAME_MAX_LEN]; 119 char unused_key_05[SNAP_NAME_MAX_LEN]; 120 char unused_key_06[SNAP_NAME_MAX_LEN]; 121 char unused_key_07[SNAP_NAME_MAX_LEN]; 122 char unused_key_08[SNAP_NAME_MAX_LEN]; 123 char unused_key_09[SNAP_NAME_MAX_LEN]; 124 char unused_key_10[SNAP_NAME_MAX_LEN]; 125 char unused_key_11[SNAP_NAME_MAX_LEN]; 126 char unused_key_12[SNAP_NAME_MAX_LEN]; 127 char unused_key_13[SNAP_NAME_MAX_LEN]; 128 char unused_key_14[SNAP_NAME_MAX_LEN]; 129 char unused_key_15[SNAP_NAME_MAX_LEN]; 130 char unused_key_16[SNAP_NAME_MAX_LEN]; 131 char unused_key_17[SNAP_NAME_MAX_LEN]; 132 char unused_key_18[SNAP_NAME_MAX_LEN]; 133 char unused_key_19[SNAP_NAME_MAX_LEN]; 134 char unused_key_20[SNAP_NAME_MAX_LEN]; 135 136 /* unused array of 10 key - value pairs */ 137 char key_value_pairs[10][2][SNAP_NAME_MAX_LEN]; 138 139 /* crc32 value for structure */ 140 uint32_t crc32; 141 } SNAP_BOOT_SELECTION_t; 142 143 #endif // _BOOTLOADER_SNAP_BOOT_V1_H