Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 0fbf66b | 2017-05-18 20:09:02 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | 0fbf66b | 2017-05-18 20:09:02 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 8 | #include <linux/libfdt.h> |
Simon Glass | 0fbf66b | 2017-05-18 20:09:02 -0600 | [diff] [blame] | 9 | #include <dm/of_access.h> |
| 10 | #include <dm/of_extra.h> |
| 11 | #include <dm/ofnode.h> |
| 12 | |
Simon Glass | 4b58093 | 2018-06-11 13:07:17 -0600 | [diff] [blame^] | 13 | int ofnode_read_fmap_entry(ofnode node, struct fmap_entry *entry) |
Simon Glass | 0fbf66b | 2017-05-18 20:09:02 -0600 | [diff] [blame] | 14 | { |
| 15 | const char *prop; |
| 16 | u32 reg[2]; |
| 17 | |
| 18 | if (ofnode_read_u32_array(node, "reg", reg, 2)) { |
Simon Glass | 4b58093 | 2018-06-11 13:07:17 -0600 | [diff] [blame^] | 19 | debug("Node '%s' has bad/missing 'reg' property\n", |
| 20 | ofnode_get_name(node)); |
| 21 | return -log_ret(ENOENT); |
Simon Glass | 0fbf66b | 2017-05-18 20:09:02 -0600 | [diff] [blame] | 22 | } |
| 23 | entry->offset = reg[0]; |
| 24 | entry->length = reg[1]; |
| 25 | entry->used = ofnode_read_s32_default(node, "used", entry->length); |
| 26 | prop = ofnode_read_string(node, "compress"); |
| 27 | entry->compress_algo = prop && !strcmp(prop, "lzo") ? |
| 28 | FMAP_COMPRESS_LZO : FMAP_COMPRESS_NONE; |
| 29 | prop = ofnode_read_string(node, "hash"); |
| 30 | if (prop) |
| 31 | entry->hash_size = strlen(prop); |
| 32 | entry->hash_algo = prop ? FMAP_HASH_SHA256 : FMAP_HASH_NONE; |
| 33 | entry->hash = (uint8_t *)prop; |
| 34 | |
| 35 | return 0; |
| 36 | } |