Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Steve Rae | e6ca1ad | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2014 Broadcom Corporation. |
Steve Rae | e6ca1ad | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 6 | #include <compiler.h> |
Steve Rae | e6ca1ad | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 7 | #include <part.h> |
| 8 | #include <sparse_format.h> |
| 9 | |
Mattijs Korpershoek | b1aade8 | 2023-07-07 10:13:34 +0200 | [diff] [blame] | 10 | #define FASTBOOT_MAX_BLK_WRITE 16384 |
| 11 | |
Steve Rae | e6ca1ad | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 12 | #define ROUNDUP(x, y) (((x) + ((y) - 1)) & ~((y) - 1)) |
| 13 | |
Steve Rae | cc0f08cd | 2016-06-07 11:19:36 -0700 | [diff] [blame] | 14 | struct sparse_storage { |
| 15 | lbaint_t blksz; |
| 16 | lbaint_t start; |
| 17 | lbaint_t size; |
| 18 | void *priv; |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 19 | |
Steve Rae | cc0f08cd | 2016-06-07 11:19:36 -0700 | [diff] [blame] | 20 | lbaint_t (*write)(struct sparse_storage *info, |
| 21 | lbaint_t blk, |
| 22 | lbaint_t blkcnt, |
| 23 | const void *buffer); |
Steve Rae | 2c72404 | 2016-06-07 11:19:38 -0700 | [diff] [blame] | 24 | |
| 25 | lbaint_t (*reserve)(struct sparse_storage *info, |
| 26 | lbaint_t blk, |
| 27 | lbaint_t blkcnt); |
Jassi Brar | 2f83f21 | 2018-04-06 12:05:09 +0530 | [diff] [blame] | 28 | |
Alex Kiernan | c4ded03 | 2018-05-29 15:30:40 +0000 | [diff] [blame] | 29 | void (*mssg)(const char *str, char *response); |
Steve Rae | cc0f08cd | 2016-06-07 11:19:36 -0700 | [diff] [blame] | 30 | }; |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 31 | |
Steve Rae | e6ca1ad | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 32 | static 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 Brar | 2f83f21 | 2018-04-06 12:05:09 +0530 | [diff] [blame] | 43 | int write_sparse_image(struct sparse_storage *info, const char *part_name, |
Alex Kiernan | c4ded03 | 2018-05-29 15:30:40 +0000 | [diff] [blame] | 44 | void *data, char *response); |