blob: ca15df21b067b03006c8ef5da9b351d427ae1f4b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass0fbf66b2017-05-18 20:09:02 -06002/*
3 * Copyright (c) 2017 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass0fbf66b2017-05-18 20:09:02 -06005 */
6
7#ifndef _DM_OF_EXTRA_H
8#define _DM_OF_EXTRA_H
9
10#include <dm/ofnode.h>
11
12enum fmap_compress_t {
13 FMAP_COMPRESS_NONE,
Simon Glass699c9ca2018-10-01 12:22:08 -060014 FMAP_COMPRESS_LZ4,
Simon Glass0fbf66b2017-05-18 20:09:02 -060015};
16
17enum fmap_hash_t {
18 FMAP_HASH_NONE,
19 FMAP_HASH_SHA1,
20 FMAP_HASH_SHA256,
21};
22
23/* A flash map entry, containing an offset and length */
24struct fmap_entry {
25 uint32_t offset;
26 uint32_t length;
27 uint32_t used; /* Number of bytes used in region */
28 enum fmap_compress_t compress_algo; /* Compression type */
Simon Glass699c9ca2018-10-01 12:22:08 -060029 uint32_t unc_length; /* Uncompressed length */
Simon Glass0fbf66b2017-05-18 20:09:02 -060030 enum fmap_hash_t hash_algo; /* Hash algorithm */
31 const uint8_t *hash; /* Hash value */
32 int hash_size; /* Hash size */
33};
34
35/**
36 * Read a flash entry from the fdt
37 *
Simon Glass4b580932018-06-11 13:07:17 -060038 * @param node Reference to node to read
Simon Glass0fbf66b2017-05-18 20:09:02 -060039 * @param entry Place to put offset and size of this node
40 * @return 0 if ok, -ve on error
41 */
Simon Glass4b580932018-06-11 13:07:17 -060042int ofnode_read_fmap_entry(ofnode node, struct fmap_entry *entry);
Simon Glass0fbf66b2017-05-18 20:09:02 -060043
Simon Glass2e4d8722018-06-11 13:07:18 -060044/**
45 * ofnode_decode_region() - Decode a memory region from a node
46 *
47 * Look up a property in a node which contains a memory region address and
48 * size. Then return a pointer to this address.
49 *
50 * The property must hold one address with a length. This is only tested on
51 * 32-bit machines.
52 *
53 * @param node ofnode to examine
54 * @param prop_name name of property to find
55 * @param basep Returns base address of region
56 * @param size Returns size of region
57 * @return 0 if ok, -1 on error (property not found)
58 */
59int ofnode_decode_region(ofnode node, const char *prop_name, fdt_addr_t *basep,
60 fdt_size_t *sizep);
61
62/**
63 * ofnode_decode_memory_region()- Decode a named region within a memory bank
64 *
65 * This function handles selection of a memory region. The region is
66 * specified as an offset/size within a particular type of memory.
67 *
68 * The properties used are:
69 *
70 * <mem_type>-memory<suffix> for the name of the memory bank
71 * <mem_type>-offset<suffix> for the offset in that bank
72 *
73 * The property value must have an offset and a size. The function checks
74 * that the region is entirely within the memory bank.5
75 *
76 * @param node ofnode containing the properties (-1 for /config)
77 * @param mem_type Type of memory to use, which is a name, such as
78 * "u-boot" or "kernel".
79 * @param suffix String to append to the memory/offset
80 * property names
81 * @param basep Returns base of region
82 * @param sizep Returns size of region
83 * @return 0 if OK, -ive on error
84 */
85int ofnode_decode_memory_region(ofnode config_node, const char *mem_type,
86 const char *suffix, fdt_addr_t *basep,
87 fdt_size_t *sizep);
88
Simon Glass0fbf66b2017-05-18 20:09:02 -060089#endif