Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Steve Rae | 82fce73 | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2014 Broadcom Corporation. |
Steve Rae | 82fce73 | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 6 | #include <compiler.h> |
Steve Rae | 82fce73 | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 7 | #include <part.h> |
| 8 | #include <sparse_format.h> |
| 9 | |
| 10 | #define ROUNDUP(x, y) (((x) + ((y) - 1)) & ~((y) - 1)) |
| 11 | |
Steve Rae | 8cf58db | 2016-06-07 11:19:36 -0700 | [diff] [blame] | 12 | struct sparse_storage { |
| 13 | lbaint_t blksz; |
| 14 | lbaint_t start; |
| 15 | lbaint_t size; |
| 16 | void *priv; |
Maxime Ripard | a58e9c7 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 17 | |
Steve Rae | 8cf58db | 2016-06-07 11:19:36 -0700 | [diff] [blame] | 18 | lbaint_t (*write)(struct sparse_storage *info, |
| 19 | lbaint_t blk, |
| 20 | lbaint_t blkcnt, |
| 21 | const void *buffer); |
Steve Rae | 8a99be8 | 2016-06-07 11:19:38 -0700 | [diff] [blame] | 22 | |
| 23 | lbaint_t (*reserve)(struct sparse_storage *info, |
| 24 | lbaint_t blk, |
| 25 | lbaint_t blkcnt); |
Jassi Brar | 427e669 | 2018-04-06 12:05:09 +0530 | [diff] [blame] | 26 | |
Alex Kiernan | 27b69de | 2018-05-29 15:30:40 +0000 | [diff] [blame] | 27 | void (*mssg)(const char *str, char *response); |
Steve Rae | 8cf58db | 2016-06-07 11:19:36 -0700 | [diff] [blame] | 28 | }; |
Maxime Ripard | a58e9c7 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 29 | |
Steve Rae | 82fce73 | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 30 | static inline int is_sparse_image(void *buf) |
| 31 | { |
| 32 | sparse_header_t *s_header = (sparse_header_t *)buf; |
| 33 | |
| 34 | if ((le32_to_cpu(s_header->magic) == SPARSE_HEADER_MAGIC) && |
| 35 | (le16_to_cpu(s_header->major_version) == 1)) |
| 36 | return 1; |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
Jassi Brar | 427e669 | 2018-04-06 12:05:09 +0530 | [diff] [blame] | 41 | int write_sparse_image(struct sparse_storage *info, const char *part_name, |
Alex Kiernan | 27b69de | 2018-05-29 15:30:40 +0000 | [diff] [blame] | 42 | void *data, char *response); |