xref: /openbmc/u-boot/include/sparse_format.h (revision e8f80a5a)
1*83d290c5STom Rini /* SPDX-License-Identifier: BSD-3-Clause */
2478a3287SColin Cross /*
3478a3287SColin Cross  * This is from the Android Project,
4478a3287SColin Cross  * Repository: https://android.googlesource.com/platform/system/core
5478a3287SColin Cross  * File: libsparse/sparse_format.h
6478a3287SColin Cross  * Commit: 28fa5bc347390480fe190294c6c385b6a9f0d68b
7478a3287SColin Cross  * Copyright (C) 2010 The Android Open Source Project
8478a3287SColin Cross  */
9478a3287SColin Cross 
10478a3287SColin Cross #ifndef _LIBSPARSE_SPARSE_FORMAT_H_
11478a3287SColin Cross #define _LIBSPARSE_SPARSE_FORMAT_H_
12478a3287SColin Cross #include "sparse_defs.h"
13478a3287SColin Cross 
14478a3287SColin Cross typedef struct sparse_header {
15478a3287SColin Cross   __le32	magic;		/* 0xed26ff3a */
16478a3287SColin Cross   __le16	major_version;	/* (0x1) - reject images with higher major versions */
17478a3287SColin Cross   __le16	minor_version;	/* (0x0) - allow images with higer minor versions */
18478a3287SColin Cross   __le16	file_hdr_sz;	/* 28 bytes for first revision of the file format */
19478a3287SColin Cross   __le16	chunk_hdr_sz;	/* 12 bytes for first revision of the file format */
20478a3287SColin Cross   __le32	blk_sz;		/* block size in bytes, must be a multiple of 4 (4096) */
21478a3287SColin Cross   __le32	total_blks;	/* total blocks in the non-sparse output image */
22478a3287SColin Cross   __le32	total_chunks;	/* total chunks in the sparse input image */
23478a3287SColin Cross   __le32	image_checksum; /* CRC32 checksum of the original data, counting "don't care" */
24478a3287SColin Cross 				/* as 0. Standard 802.3 polynomial, use a Public Domain */
25478a3287SColin Cross 				/* table implementation */
26478a3287SColin Cross } sparse_header_t;
27478a3287SColin Cross 
28478a3287SColin Cross #define SPARSE_HEADER_MAGIC	0xed26ff3a
29478a3287SColin Cross 
30478a3287SColin Cross #define CHUNK_TYPE_RAW		0xCAC1
31478a3287SColin Cross #define CHUNK_TYPE_FILL		0xCAC2
32478a3287SColin Cross #define CHUNK_TYPE_DONT_CARE	0xCAC3
33478a3287SColin Cross #define CHUNK_TYPE_CRC32    0xCAC4
34478a3287SColin Cross 
35478a3287SColin Cross typedef struct chunk_header {
36478a3287SColin Cross   __le16	chunk_type;	/* 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care */
37478a3287SColin Cross   __le16	reserved1;
38478a3287SColin Cross   __le32	chunk_sz;	/* in blocks in output image */
39478a3287SColin Cross   __le32	total_sz;	/* in bytes of chunk input file including chunk header and data */
40478a3287SColin Cross } chunk_header_t;
41478a3287SColin Cross 
42478a3287SColin Cross /* Following a Raw or Fill or CRC32 chunk is data.
43478a3287SColin Cross  *  For a Raw chunk, it's the data in chunk_sz * blk_sz.
44478a3287SColin Cross  *  For a Fill chunk, it's 4 bytes of the fill data.
45478a3287SColin Cross  *  For a CRC32 chunk, it's 4 bytes of CRC32
46478a3287SColin Cross  */
47478a3287SColin Cross 
48478a3287SColin Cross #endif
49