of_extra.h 2.5 KB

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