-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathimageheadertable-zynqmp.h
executable file
·149 lines (128 loc) · 5.48 KB
/
imageheadertable-zynqmp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/******************************************************************************
* Copyright 2015-2022 Xilinx, Inc.
* Copyright 2022-2023 Advanced Micro Devices, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
#pragma once
#ifndef _IMAGEHEADERTABLE_ZYNQMP_H_
#define _IMAGEHEADERTABLE_ZYNQMP_H_
/*
-------------------------------------------------------------------------------
*********************************************** H E A D E R F I L E S ***
-------------------------------------------------------------------------------
*/
#include "imageheadertable.h"
#include "partitionheadertable-zynqmp.h"
#include "bootimage.h"
#include "fileutils.h"
#include "elftools.h"
#include "bitutils.h"
/*
-------------------------------------------------------------------------------
********************************************* P R E P R O C E S S O R S ***
-------------------------------------------------------------------------------
*/
#define MAX_IHT_RESERVED_ZYNQMP 9
#define MAX_NUM_PARTITIONS_ZYNQMP 32
/* 128MB Linear QSPI range */
#define LQSPI_BASE_ADDR_ZYNQMP (0xC0000000)
#define LQSPI_SIZE_ZYNQMP (0x8000000)
#define LQSPI_RANGE_MASK_ZYNQMP (0x7FFFFFF)
/*
-------------------------------------------------------------------------------
*************************************************** S T R U C T U R E S ***
-------------------------------------------------------------------------------
*/
typedef struct
{
uint32_t version; // 0x00
uint32_t partitionTotalCount; // 0x04
uint32_t firstPartitionHeaderWordOffset; // 0x08
uint32_t firstImageHeaderWordOffset; // 0x0C
uint32_t headerAuthCertificateWordOffset; // 0x10
uint32_t bootDevice; // 0x14
uint32_t reserved[MAX_IHT_RESERVED_ZYNQMP]; // 0x18
uint32_t ihtChecksum; // 0x3C
} ZynqMpImageHeaderTableStructure;
typedef struct
{
uint32_t nextImageHeaderWordOffset; // 0x00
uint32_t partitionHeaderWordOffset; // 0x04
uint32_t dataSectionCount; // 0x08
uint32_t imageNameLength; // 0x10
char imageName[1]; // 0x14
} ZynqMpImageHeaderStructure;
/*
-------------------------------------------------------------------------------
********************************************************* C L A S S E S ***
-------------------------------------------------------------------------------
*/
/******************************************************************************/
class ZynqMpImageHeaderTable : public ImageHeaderTable
{
public:
ZynqMpImageHeaderTable();
ZynqMpImageHeaderTable(std::ifstream& ifs);
~ZynqMpImageHeaderTable();
void ValidateSecurityCombinations(Authentication::Type, Encryption::Type, Checksum::Type);
void RealignSectionDataPtr(void);
void SetImageHeaderTableVersion(uint32_t version);
void SetPartitionCount(uint32_t count);
void SetFirstPartitionHeaderOffset(uint32_t offset);
void SetFirstImageHeaderOffset(uint32_t offset);
void SetHeaderAuthCertificateOffset(uint32_t offset);
void SetReservedFields(void);
void SetChecksum(void);
void SetBootDevice(BootDevice::Type type);
uint32_t GetImageHeaderTableVersion(void);
uint32_t GetPartitionCount(void);
uint32_t GetFirstPartitionHeaderOffset(void);
uint32_t GetFirstImageHeaderOffset(void);
uint32_t GetHeaderAuthCertificateOffset(void);
uint8_t GetMaxNumOfPartitions(void) { return MAX_NUM_PARTITIONS_ZYNQMP; }
private:
ZynqMpImageHeaderTableStructure *iHTable;
};
/******************************************************************************/
class ZynqMpImageHeader : public ImageHeader
{
public:
ZynqMpImageHeader(std::string& filename);
ZynqMpImageHeader(std::ifstream& f);
~ZynqMpImageHeader();
void Build(BootImage& bi, Binary& cache);
void Link(BootImage &bi, PartitionHeader* partitionHeader, ImageHeader* nextImageheader);
void ValidateEncryptionAttributes(BootImage & bi);
void SetAuthBlock(size_t blockSize, bool flag);
void ImportFpgaDataFile(BootImage & bi);
void ImportBit(BootImage & bi);
void ImportBin(BootImage & bi);
void CreateElfPartitions(BootImage& bi, ElfFormat* elf, uint8_t proc_state);
uint8_t* AttachPmuFw(uint8_t* partition_data, uint64_t* total_size, std::string pmu_fw);
uint64_t GetExecAddrForXip(uint64_t execAddr);
Binary::Address_t GetNextImageHeaderOffset();
uint32_t GetPartitionHeaderOffset(void);
uint32_t GetDataSectionCount(void);
uint32_t GetImageNameLength(void);
void SetNextImageHeaderOffset(uint32_t addr);
void SetPartitionHeaderOffset(uint32_t addr);
void SetDataSectionCount(uint32_t cnt);
void SetImageNameLength(uint32_t len);
void SetImageName(void);
void SetBigEndian(bool);
void SetA32ExecMode(bool);
private:
ZynqMpImageHeaderStructure *imageHeader;
};
#endif