Commit b7e0d73bad051b666c6cbf9dff381f4c48dcb8a2

Authored by Simon Glass
1 parent bed774969c

dm: core: Add a place to put extra device-tree reading functions

Some functions deal with structured data rather than simple data types.
It makes sense to have these in their own file. For now this just has a
function to read a flashmap entry. Move the data types also.

Signed-off-by: Simon Glass <sjg@chromium.org>

Showing 6 changed files with 87 additions and 23 deletions Side-by-side Diff

drivers/core/Makefile
... ... @@ -12,5 +12,5 @@
12 12 obj-$(CONFIG_$(SPL_)REGMAP) += regmap.o
13 13 obj-$(CONFIG_$(SPL_)SYSCON) += syscon-uclass.o
14 14 obj-$(CONFIG_OF_LIVE) += of_access.o of_addr.o
15   -obj-$(CONFIG_OF_CONTROL) += ofnode.o
  15 +obj-$(CONFIG_OF_CONTROL) += of_extra.o ofnode.o
drivers/core/of_extra.c
  1 +/*
  2 + * Copyright (c) 2017 Google, Inc
  3 + * Written by Simon Glass <sjg@chromium.org>
  4 + *
  5 + * SPDX-License-Identifier: GPL-2.0+
  6 + */
  7 +
  8 +#include <common.h>
  9 +#include <libfdt.h>
  10 +#include <dm/of_access.h>
  11 +#include <dm/of_extra.h>
  12 +#include <dm/ofnode.h>
  13 +
  14 +int of_read_fmap_entry(ofnode node, const char *name,
  15 + struct fmap_entry *entry)
  16 +{
  17 + const char *prop;
  18 + u32 reg[2];
  19 +
  20 + if (ofnode_read_u32_array(node, "reg", reg, 2)) {
  21 + debug("Node '%s' has bad/missing 'reg' property\n", name);
  22 + return -FDT_ERR_NOTFOUND;
  23 + }
  24 + entry->offset = reg[0];
  25 + entry->length = reg[1];
  26 + entry->used = ofnode_read_s32_default(node, "used", entry->length);
  27 + prop = ofnode_read_string(node, "compress");
  28 + entry->compress_algo = prop && !strcmp(prop, "lzo") ?
  29 + FMAP_COMPRESS_LZO : FMAP_COMPRESS_NONE;
  30 + prop = ofnode_read_string(node, "hash");
  31 + if (prop)
  32 + entry->hash_size = strlen(prop);
  33 + entry->hash_algo = prop ? FMAP_HASH_SHA256 : FMAP_HASH_NONE;
  34 + entry->hash = (uint8_t *)prop;
  35 +
  36 + return 0;
  37 +}
... ... @@ -14,6 +14,7 @@
14 14 #include <fdtdec.h>
15 15 #include <cros_ec_message.h>
16 16 #include <asm/gpio.h>
  17 +#include <dm/of_extra.h>
17 18  
18 19 /* Our configuration information */
19 20 struct cros_ec_dev {
include/dm/of_extra.h
  1 +/*
  2 + * Copyright (c) 2017 Google, Inc
  3 + * Written by Simon Glass <sjg@chromium.org>
  4 + *
  5 + * SPDX-License-Identifier: GPL-2.0+
  6 + */
  7 +
  8 +#ifndef _DM_OF_EXTRA_H
  9 +#define _DM_OF_EXTRA_H
  10 +
  11 +#include <dm/ofnode.h>
  12 +
  13 +enum fmap_compress_t {
  14 + FMAP_COMPRESS_NONE,
  15 + FMAP_COMPRESS_LZO,
  16 +};
  17 +
  18 +enum fmap_hash_t {
  19 + FMAP_HASH_NONE,
  20 + FMAP_HASH_SHA1,
  21 + FMAP_HASH_SHA256,
  22 +};
  23 +
  24 +/* A flash map entry, containing an offset and length */
  25 +struct fmap_entry {
  26 + uint32_t offset;
  27 + uint32_t length;
  28 + uint32_t used; /* Number of bytes used in region */
  29 + enum fmap_compress_t compress_algo; /* Compression type */
  30 + 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 + *
  38 + * @param node Reference to node to read
  39 + * @param name Name of node being read
  40 + * @param entry Place to put offset and size of this node
  41 + * @return 0 if ok, -ve on error
  42 + */
  43 +int of_read_fmap_entry(ofnode node, const char *name,
  44 + struct fmap_entry *entry);
  45 +
  46 +#endif
... ... @@ -815,28 +815,7 @@
815 815 int fdtdec_decode_region(const void *blob, int node, const char *prop_name,
816 816 fdt_addr_t *basep, fdt_size_t *sizep);
817 817  
818   -enum fmap_compress_t {
819   - FMAP_COMPRESS_NONE,
820   - FMAP_COMPRESS_LZO,
821   -};
822   -
823   -enum fmap_hash_t {
824   - FMAP_HASH_NONE,
825   - FMAP_HASH_SHA1,
826   - FMAP_HASH_SHA256,
827   -};
828   -
829   -/* A flash map entry, containing an offset and length */
830   -struct fmap_entry {
831   - uint32_t offset;
832   - uint32_t length;
833   - uint32_t used; /* Number of bytes used in region */
834   - enum fmap_compress_t compress_algo; /* Compression type */
835   - enum fmap_hash_t hash_algo; /* Hash algorithm */
836   - const uint8_t *hash; /* Hash value */
837   - int hash_size; /* Hash size */
838   -};
839   -
  818 +struct fmap_entry;
840 819 /**
841 820 * Read a flash entry from the fdt
842 821 *
... ... @@ -12,6 +12,7 @@
12 12 #include <fdt_support.h>
13 13 #include <fdtdec.h>
14 14 #include <asm/sections.h>
  15 +#include <dm/of_extra.h>
15 16 #include <linux/ctype.h>
16 17  
17 18 DECLARE_GLOBAL_DATA_PTR;