blob: 282a0b256498cf86eb7fec85882f24c15ed6d0dc [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Steve Rae82fce732014-09-03 10:05:54 -07002/*
3 * Copyright 2014 Broadcom Corporation.
Steve Rae82fce732014-09-03 10:05:54 -07004 */
5
Simon Glass3ba929a2020-10-30 21:38:53 -06006#include <compiler.h>
Steve Rae82fce732014-09-03 10:05:54 -07007#include <part.h>
8#include <sparse_format.h>
9
Mattijs Korpershoek8b24d142023-07-07 10:13:34 +020010#define FASTBOOT_MAX_BLK_WRITE 16384
11
Steve Rae82fce732014-09-03 10:05:54 -070012#define ROUNDUP(x, y) (((x) + ((y) - 1)) & ~((y) - 1))
13
Steve Rae8cf58db2016-06-07 11:19:36 -070014struct sparse_storage {
15 lbaint_t blksz;
16 lbaint_t start;
17 lbaint_t size;
18 void *priv;
Maxime Riparda58e9c72015-10-15 14:34:14 +020019
Steve Rae8cf58db2016-06-07 11:19:36 -070020 lbaint_t (*write)(struct sparse_storage *info,
21 lbaint_t blk,
22 lbaint_t blkcnt,
23 const void *buffer);
Steve Rae8a99be82016-06-07 11:19:38 -070024
25 lbaint_t (*reserve)(struct sparse_storage *info,
26 lbaint_t blk,
27 lbaint_t blkcnt);
Jassi Brar427e6692018-04-06 12:05:09 +053028
Alex Kiernan27b69de2018-05-29 15:30:40 +000029 void (*mssg)(const char *str, char *response);
Steve Rae8cf58db2016-06-07 11:19:36 -070030};
Maxime Riparda58e9c72015-10-15 14:34:14 +020031
Steve Rae82fce732014-09-03 10:05:54 -070032static inline int is_sparse_image(void *buf)
33{
34 sparse_header_t *s_header = (sparse_header_t *)buf;
35
36 if ((le32_to_cpu(s_header->magic) == SPARSE_HEADER_MAGIC) &&
37 (le16_to_cpu(s_header->major_version) == 1))
38 return 1;
39
40 return 0;
41}
42
Jassi Brar427e6692018-04-06 12:05:09 +053043int write_sparse_image(struct sparse_storage *info, const char *part_name,
Alex Kiernan27b69de2018-05-29 15:30:40 +000044 void *data, char *response);