blob: 5e5f5458eb73acca4079da978de4b7677d434971 [file] [log] [blame]
J-Alves2f86c1e2022-02-23 18:44:19 +00001/*
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 0x2U
17
18#define SP_PKG_FLAG_BOOT_INFO UINT32_C(0x1U << 0)
19
20/**
21 * Header for a SP Partition Package.
22 */
23struct sp_pkg_header {
24 /** Magic used to identify a SP package. Value is "SPKG". */
25 uint32_t magic;
26 /** Version number of the header. */
27 uint32_t version;
28 /** Offset in bytes to the partition manifests. */
29 uint32_t pm_offset;
30 /** Size in bytes of the partition manifest. */
31 uint32_t pm_size;
32 /** Offset in bytes to the base address of the partition binary. */
33 uint32_t img_offset;
34 /** Size in bytes of the partition binary. */
35 uint32_t img_size;
36};
37
38static inline size_t sp_pkg_get_mem_size(struct sp_pkg_header *sp_pkg)
39{
40 assert(SIZE_MAX - sp_pkg->img_offset >= (size_t)sp_pkg->img_size);
41 return (size_t)(sp_pkg->img_offset + sp_pkg->img_size);
42}
43
44bool sp_pkg_init(struct mm_stage1_locked stage1_locked, paddr_t pkg_start,
45 struct sp_pkg_header *header, struct mpool *ppool);
46
47void sp_pkg_deinit(struct mm_stage1_locked stage1_locked, vaddr_t pkg_start,
48 struct sp_pkg_header *header, struct mpool *ppool);