blob: 234c237b845fe592077d4be51e98ffe7cfb8ef3b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Steve Raee6ca1ad2014-09-03 10:05:54 -07002/*
3 * Copyright 2014 Broadcom Corporation.
Steve Raee6ca1ad2014-09-03 10:05:54 -07004 */
5
6#include <part.h>
7#include <sparse_format.h>
8
9#define ROUNDUP(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
10
Steve Raecc0f08cd2016-06-07 11:19:36 -070011struct sparse_storage {
12 lbaint_t blksz;
13 lbaint_t start;
14 lbaint_t size;
15 void *priv;
Maxime Riparda5d1e042015-10-15 14:34:14 +020016
Steve Raecc0f08cd2016-06-07 11:19:36 -070017 lbaint_t (*write)(struct sparse_storage *info,
18 lbaint_t blk,
19 lbaint_t blkcnt,
20 const void *buffer);
Steve Rae2c724042016-06-07 11:19:38 -070021
22 lbaint_t (*reserve)(struct sparse_storage *info,
23 lbaint_t blk,
24 lbaint_t blkcnt);
Jassi Brar2f83f212018-04-06 12:05:09 +053025
Alex Kiernanc4ded032018-05-29 15:30:40 +000026 void (*mssg)(const char *str, char *response);
Steve Raecc0f08cd2016-06-07 11:19:36 -070027};
Maxime Riparda5d1e042015-10-15 14:34:14 +020028
Steve Raee6ca1ad2014-09-03 10:05:54 -070029static inline int is_sparse_image(void *buf)
30{
31 sparse_header_t *s_header = (sparse_header_t *)buf;
32
33 if ((le32_to_cpu(s_header->magic) == SPARSE_HEADER_MAGIC) &&
34 (le16_to_cpu(s_header->major_version) == 1))
35 return 1;
36
37 return 0;
38}
39
Jassi Brar2f83f212018-04-06 12:05:09 +053040int write_sparse_image(struct sparse_storage *info, const char *part_name,
Alex Kiernanc4ded032018-05-29 15:30:40 +000041 void *data, char *response);