of_extra.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_LZ4,
  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. uint32_t unc_length; /* Uncompressed length */
  25. enum fmap_hash_t hash_algo; /* Hash algorithm */
  26. const uint8_t *hash; /* Hash value */
  27. int hash_size; /* Hash size */
  28. };
  29. /**
  30. * Read a flash entry from the fdt
  31. *
  32. * @param node Reference to node to read
  33. * @param entry Place to put offset and size of this node
  34. * @return 0 if ok, -ve on error
  35. */
  36. int ofnode_read_fmap_entry(ofnode node, struct fmap_entry *entry);
  37. /**
  38. * ofnode_decode_region() - Decode a memory region from a node
  39. *
  40. * Look up a property in a node which contains a memory region address and
  41. * size. Then return a pointer to this address.
  42. *
  43. * The property must hold one address with a length. This is only tested on
  44. * 32-bit machines.
  45. *
  46. * @param node ofnode to examine
  47. * @param prop_name name of property to find
  48. * @param basep Returns base address of region
  49. * @param size Returns size of region
  50. * @return 0 if ok, -1 on error (property not found)
  51. */
  52. int ofnode_decode_region(ofnode node, const char *prop_name, fdt_addr_t *basep,
  53. fdt_size_t *sizep);
  54. /**
  55. * ofnode_decode_memory_region()- Decode a named region within a memory bank
  56. *
  57. * This function handles selection of a memory region. The region is
  58. * specified as an offset/size within a particular type of memory.
  59. *
  60. * The properties used are:
  61. *
  62. * <mem_type>-memory<suffix> for the name of the memory bank
  63. * <mem_type>-offset<suffix> for the offset in that bank
  64. *
  65. * The property value must have an offset and a size. The function checks
  66. * that the region is entirely within the memory bank.5
  67. *
  68. * @param node ofnode containing the properties (-1 for /config)
  69. * @param mem_type Type of memory to use, which is a name, such as
  70. * "u-boot" or "kernel".
  71. * @param suffix String to append to the memory/offset
  72. * property names
  73. * @param basep Returns base of region
  74. * @param sizep Returns size of region
  75. * @return 0 if OK, -ive on error
  76. */
  77. int ofnode_decode_memory_region(ofnode config_node, const char *mem_type,
  78. const char *suffix, fdt_addr_t *basep,
  79. fdt_size_t *sizep);
  80. #endif