Changeset 78ad048 in rtems for cpukit/include/libfdt.h


Ignore:
Timestamp:
Jun 21, 2018, 5:32:40 AM (2 years ago)
Author:
David Gibson <david@…>
Branches:
5, master
Children:
4fd05d3
Parents:
3848f14b
git-author:
David Gibson <david@…> (06/21/18 05:32:40)
git-committer:
Sebastian Huber <sebastian.huber@…> (07/19/18 05:01:12)
Message:

libfdt: Add helpers for accessing unaligned words

This adds some helpers to load (32 or 64 bit) words from an fdt blob, even
if they're unaligned and we're on a platform that doesn't like plain
unaligned loads and stores. We then use the helpers in a number of places.
There are two purposes for this:

1) This makes libfdt more robust against a blob loaded at an unaligned

address. It's usually good practice to load a blob at a 64-bit
alignment, but it's nice to work even then.

2) Users can use these helpers to load integer values from within property

values. These can often be unaligned, even if the blob as a whole is
aligned, since some property encodings have integers and strings mixed
together without any alignment gaps.

Signed-off-by: David Gibson <david@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/libfdt.h

    r3848f14b r78ad048  
    155155uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
    156156
     157/*
     158 * Alignment helpers:
     159 *     These helpers access words from a device tree blob.  They're
     160 *     built to work even with unaligned pointers on platforms (ike
     161 *     ARM) that don't like unaligned loads and stores
     162 */
     163
     164static inline uint32_t fdt32_ld(const fdt32_t *p)
     165{
     166        fdt32_t v;
     167
     168        memcpy(&v, p, sizeof(v));
     169        return fdt32_to_cpu(v);
     170}
     171
     172static inline uint64_t fdt64_ld(const fdt64_t *p)
     173{
     174        fdt64_t v;
     175
     176        memcpy(&v, p, sizeof(v));
     177        return fdt64_to_cpu(v);
     178}
     179
    157180/**********************************************************************/
    158181/* Traversal functions                                                */
     
    215238/**********************************************************************/
    216239#define fdt_get_header(fdt, field) \
    217         (fdt32_to_cpu(((const struct fdt_header *)(fdt))->field))
     240        (fdt32_ld(&((const struct fdt_header *)(fdt))->field))
    218241#define fdt_magic(fdt)                  (fdt_get_header(fdt, magic))
    219242#define fdt_totalsize(fdt)              (fdt_get_header(fdt, totalsize))
Note: See TracChangeset for help on using the changeset viewer.