1 /* 2 * Copyright 2022 The Hafnium Authors. 3 * 4 * Use of this source code is governed by a BSD-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/BSD-3-Clause. 7 */ 8 9 #pragma once 10 11 #include "hf/check.h" 12 #include "hf/mm.h" 13 #include "hf/types.h" 14 15 #define SP_PKG_HEADER_MAGIC 0x474b5053U 16 #define SP_PKG_HEADER_VERSION_1 0x1U 17 #define SP_PKG_HEADER_VERSION_2 0x2U 18 19 #define SP_PKG_FLAG_BOOT_INFO (UINT32_C(1) << 0) 20 21 /** 22 * Header for a SP Partition Package. 23 */ 24 struct sp_pkg_header { 25 /** Magic used to identify a SP package. Value is "SPKG". */ 26 uint32_t magic; 27 /** Version number of the header. */ 28 uint32_t version; 29 /** Offset in bytes to the partition manifests. */ 30 uint32_t pm_offset; 31 /** Size in bytes of the partition manifest. */ 32 uint32_t pm_size; 33 /** Offset in bytes to the base address of the partition binary. */ 34 uint32_t img_offset; 35 /** Size in bytes of the partition binary. */ 36 uint32_t img_size; 37 }; 38 sp_pkg_get_mem_size(struct sp_pkg_header * sp_pkg)39static inline size_t sp_pkg_get_mem_size(struct sp_pkg_header *sp_pkg) 40 { 41 assert(SIZE_MAX - sp_pkg->img_offset >= (size_t)sp_pkg->img_size); 42 return (size_t)(sp_pkg->img_offset + sp_pkg->img_size); 43 } 44 45 /** Get the size of the boot information descriptors section. */ sp_pkg_get_boot_info_size(struct sp_pkg_header * sp_pkg)46static inline size_t sp_pkg_get_boot_info_size(struct sp_pkg_header *sp_pkg) 47 { 48 return sp_pkg->pm_offset; 49 } 50 51 bool sp_pkg_init(struct mm_stage1_locked stage1_locked, paddr_t pkg_start, 52 struct sp_pkg_header *header, struct mpool *ppool); 53 54 void sp_pkg_deinit(struct mm_stage1_locked stage1_locked, vaddr_t pkg_start, 55 struct sp_pkg_header *header, struct mpool *ppool); 56