2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2014-09-03 17:05:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Broadcom Corporation.
|
|
|
|
*/
|
|
|
|
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <compiler.h>
|
2014-09-03 17:05:54 +00:00
|
|
|
#include <part.h>
|
|
|
|
#include <sparse_format.h>
|
|
|
|
|
2023-07-07 08:13:34 +00:00
|
|
|
#define FASTBOOT_MAX_BLK_WRITE 16384
|
|
|
|
|
2014-09-03 17:05:54 +00:00
|
|
|
#define ROUNDUP(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
|
|
|
|
|
2016-06-07 18:19:36 +00:00
|
|
|
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);
|
2016-06-07 18:19:38 +00:00
|
|
|
|
|
|
|
lbaint_t (*reserve)(struct sparse_storage *info,
|
|
|
|
lbaint_t blk,
|
|
|
|
lbaint_t blkcnt);
|
2018-04-06 06:35:09 +00:00
|
|
|
|
2018-05-29 15:30:40 +00:00
|
|
|
void (*mssg)(const char *str, char *response);
|
2016-06-07 18:19:36 +00:00
|
|
|
};
|
2015-10-15 12:34:14 +00:00
|
|
|
|
2014-09-03 17:05:54 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-04-06 06:35:09 +00:00
|
|
|
int write_sparse_image(struct sparse_storage *info, const char *part_name,
|
2018-05-29 15:30:40 +00:00
|
|
|
void *data, char *response);
|