1a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner/*
2a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner * Copyright (C) 2010 The Android Open Source Project
3a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner *
4a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner * Licensed under the Apache License, Version 2.0 (the "License");
5a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner * you may not use this file except in compliance with the License.
6a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner * You may obtain a copy of the License at
7a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner *
8a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner *      http://www.apache.org/licenses/LICENSE-2.0
9a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner *
10a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner * Unless required by applicable law or agreed to in writing, software
11a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner * distributed under the License is distributed on an "AS IS" BASIS,
12a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner * See the License for the specific language governing permissions and
14a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner * limitations under the License.
15a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner */
16a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner
17a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner#ifndef _LIBSPARSE_SPARSE_FORMAT_H_
18a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner#define _LIBSPARSE_SPARSE_FORMAT_H_
19a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner#include "sparse_defs.h"
20a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner
21a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turnertypedef struct sparse_header {
22a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner  __le32	magic;		/* 0xed26ff3a */
23a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner  __le16	major_version;	/* (0x1) - reject images with higher major versions */
24a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner  __le16	minor_version;	/* (0x0) - allow images with higer minor versions */
25a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner  __le16	file_hdr_sz;	/* 28 bytes for first revision of the file format */
26a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner  __le16	chunk_hdr_sz;	/* 12 bytes for first revision of the file format */
27a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner  __le32	blk_sz;		/* block size in bytes, must be a multiple of 4 (4096) */
28a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner  __le32	total_blks;	/* total blocks in the non-sparse output image */
29a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner  __le32	total_chunks;	/* total chunks in the sparse input image */
30a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner  __le32	image_checksum; /* CRC32 checksum of the original data, counting "don't care" */
31a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner				/* as 0. Standard 802.3 polynomial, use a Public Domain */
32a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner				/* table implementation */
33a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner} sparse_header_t;
34a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner
35a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner#define SPARSE_HEADER_MAGIC	0xed26ff3a
36a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner
37a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner#define CHUNK_TYPE_RAW		0xCAC1
38a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner#define CHUNK_TYPE_FILL		0xCAC2
39a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner#define CHUNK_TYPE_DONT_CARE	0xCAC3
40a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner#define CHUNK_TYPE_CRC32    0xCAC4
41a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner
42a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turnertypedef struct chunk_header {
43a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner  __le16	chunk_type;	/* 0xCAC1 -> raw; 0xCAC2 -> fill; 0xCAC3 -> don't care */
44a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner  __le16	reserved1;
45a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner  __le32	chunk_sz;	/* in blocks in output image */
46a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner  __le32	total_sz;	/* in bytes of chunk input file including chunk header and data */
47a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner} chunk_header_t;
48a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner
49a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner/* Following a Raw or Fill or CRC32 chunk is data.
50a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner *  For a Raw chunk, it's the data in chunk_sz * blk_sz.
51a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner *  For a Fill chunk, it's 4 bytes of the fill data.
52a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner *  For a CRC32 chunk, it's 4 bytes of CRC32
53a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner */
54a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner
55a2394cf2fab37ca4ec91e57db74f06f15a3656beDavid 'Digit' Turner#endif
56