image-sparse.h 836 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11
/*
 * Copyright 2014 Broadcom Corporation.
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <part.h>
#include <sparse_format.h>

#define ROUNDUP(x, y)	(((x) + ((y) - 1)) & ~((y) - 1))

12 13 14 15 16 17 18 19 20 21
struct sparse_storage {
	lbaint_t	blksz;
	lbaint_t	start;
	lbaint_t	size;
	void		*priv;

	lbaint_t	(*write)(struct sparse_storage *info,
				 lbaint_t blk,
				 lbaint_t blkcnt,
				 const void *buffer);
22 23 24 25

	lbaint_t	(*reserve)(struct sparse_storage *info,
				 lbaint_t blk,
				 lbaint_t blkcnt);
26
};
27

28 29 30 31 32 33 34 35 36 37 38
static inline int is_sparse_image(void *buf)
{
	sparse_header_t *s_header = (sparse_header_t *)buf;

	if ((le32_to_cpu(s_header->magic) == SPARSE_HEADER_MAGIC) &&
	    (le16_to_cpu(s_header->major_version) == 1))
		return 1;

	return 0;
}

39
void write_sparse_image(struct sparse_storage *info, const char *part_name,
40
			void *data, unsigned sz);