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 | |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 12 | typedef struct sparse_storage { |
| 13 | unsigned int block_sz; |
| 14 | unsigned int start; |
| 15 | unsigned int size; |
| 16 | const char *name; |
| 17 | |
| 18 | int (*write)(struct sparse_storage *storage, void *priv, |
| 19 | unsigned int offset, unsigned int size, |
| 20 | char *data); |
| 21 | } sparse_storage_t; |
| 22 | |
Steve Rae | e6ca1ad | 2014-09-03 10:05:54 -0700 | [diff] [blame] | 23 | static inline int is_sparse_image(void *buf) |
| 24 | { |
| 25 | sparse_header_t *s_header = (sparse_header_t *)buf; |
| 26 | |
| 27 | if ((le32_to_cpu(s_header->magic) == SPARSE_HEADER_MAGIC) && |
| 28 | (le16_to_cpu(s_header->major_version) == 1)) |
| 29 | return 1; |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
Maxime Ripard | a5d1e04 | 2015-10-15 14:34:14 +0200 | [diff] [blame] | 34 | int store_sparse_image(sparse_storage_t *storage, void *storage_priv, |
Maxime Ripard | 6c9e00e | 2015-10-15 14:34:15 +0200 | [diff] [blame] | 35 | unsigned int session_id, void *data); |