Steve Rae | e6ca1ad | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Broadcom Corporation. |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <part.h> |
| 8 | #include <sparse_format.h> |
| 9 | |
| 10 | #define ROUNDUP(x, y) (((x) + ((y) - 1)) & ~((y) - 1)) |
| 11 | |
Steve Rae | cc0f08cd | 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 | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 17 | |
Steve Rae | cc0f08cd | 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); |
| 22 | }; |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 23 | |
Steve Rae | e6ca1ad | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 24 | static inline int is_sparse_image(void *buf) |
| 25 | { |
| 26 | sparse_header_t *s_header = (sparse_header_t *)buf; |
| 27 | |
| 28 | if ((le32_to_cpu(s_header->magic) == SPARSE_HEADER_MAGIC) && |
| 29 | (le16_to_cpu(s_header->major_version) == 1)) |
| 30 | return 1; |
| 31 | |
| 32 | return 0; |
| 33 | } |
| 34 | |
Steve Rae | cc0f08cd | 2016-06-07 11:19:36 -0700 | [diff] [blame] | 35 | void write_sparse_image(struct sparse_storage *info, const char *part_name, |
Steve Rae | 9bc3479 | 2016-06-07 11:19:37 -0700 | [diff] [blame^] | 36 | void *data, unsigned sz); |