fdtmap.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2013, Google Inc.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are
  7. * met:
  8. *
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above
  12. * copyright notice, this list of conditions and the following disclaimer
  13. * in the documentation and/or other materials provided with the
  14. * distribution.
  15. * * Neither the name of Google Inc. nor the names of its
  16. * contributors may be used to endorse or promote products derived from
  17. * this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. * Alternatively, this software may be distributed under the terms of the
  32. * GNU General Public License ("GPL") version 2 as published by the Free
  33. * Software Foundation.
  34. */
  35. #ifndef FLASHMAP_LIB_FDTMAP_H__
  36. #define FLASHMAP_LIB_FDTMAP_H__
  37. #ifndef _GNU_SOURCE
  38. #define _GNU_SOURCE
  39. #endif
  40. #include <fcntl.h>
  41. #define FDTMAP_SIGNATURE "__FDTM__"
  42. struct romlayout;
  43. /* The header at the start of an fdtmap */
  44. struct fdtmap_hdr {
  45. char sig[8]; /* Signature (FDTMAP_SIGNATURE) */
  46. uint32_t size; /* Size of data region */
  47. uint32_t crc32; /* CRC32 of data region */
  48. /* Data follows immediately */
  49. };
  50. /**
  51. * fdtmap_add_entries_from_buf()- Add region entries from the FDTMAP
  52. *
  53. * @blob: FDT blob containing flashmap node
  54. * @rom_entries: Place to put the entries we find
  55. * @max_entries: Maximum number of entries to add
  56. * @return Number of entries added, or -1 on error
  57. */
  58. int fdtmap_add_entries_from_buf(const void *blob,
  59. struct romlayout *rom_entries, int max_entries);
  60. /*
  61. * fdtmap_find - find FDTMAP at offset in an image and copy it to buffer
  62. *
  63. * @flash: flash structure containing read function
  64. * @hdr: pointer to fmap header
  65. * @offset: offset of fmap header in image
  66. * @buf: unallocated buffer to store fmap struct
  67. *
  68. * This function allocates memory which the caller must free.
  69. *
  70. * returns 1 if found, 0 if not found, <0 to indicate failure
  71. */
  72. int fdtmap_find(struct flashctx *flash, struct fdtmap_hdr *hdr,
  73. loff_t offset, uint8_t **buf);
  74. #endif