Changeset 78ad048 in rtems for cpukit/dtc


Ignore:
Timestamp:
Jun 21, 2018, 5:32:40 AM (17 months ago)
Author:
David Gibson <david@…>
Branches:
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/dtc/libfdt/fdt_ro.c

    r3848f14b r78ad048  
    192192                return -FDT_ERR_BADOFFSET;
    193193
    194         *address = fdt64_to_cpu(re->address);
    195         *size = fdt64_to_cpu(re->size);
     194        *address = fdt64_ld(&re->address);
     195        *size = fdt64_ld(&re->size);
    196196        return 0;
    197197}
     
    203203
    204204        for (i = 0; (re = fdt_mem_rsv(fdt, i)) != NULL; i++) {
    205                 if (fdt64_to_cpu(re->size) == 0)
     205                if (fdt64_ld(&re->size) == 0)
    206206                        return i;
    207207        }
     
    380380
    381381        if (lenp)
    382                 *lenp = fdt32_to_cpu(prop->len);
     382                *lenp = fdt32_ld(&prop->len);
    383383
    384384        return prop;
     
    417417                        break;
    418418                }
    419                 if (fdt_string_eq_(fdt, fdt32_to_cpu(prop->nameoff),
     419                if (fdt_string_eq_(fdt, fdt32_ld(&prop->nameoff),
    420420                                   name, namelen)) {
    421421                        if (poffset)
     
    470470        /* Handle realignment */
    471471        if (fdt_version(fdt) < 0x10 && (poffset + sizeof(*prop)) % 8 &&
    472             fdt32_to_cpu(prop->len) >= 8)
     472            fdt32_ld(&prop->len) >= 8)
    473473                return prop->data + 4;
    474474        return prop->data;
     
    486486                const char *name;
    487487                int namelen;
    488                 name = fdt_get_string(fdt, fdt32_to_cpu(prop->nameoff),
     488                name = fdt_get_string(fdt, fdt32_ld(&prop->nameoff),
    489489                                      &namelen);
    490490                if (!name) {
     
    498498        /* Handle realignment */
    499499        if (fdt_version(fdt) < 0x10 && (offset + sizeof(*prop)) % 8 &&
    500             fdt32_to_cpu(prop->len) >= 8)
     500            fdt32_ld(&prop->len) >= 8)
    501501                return prop->data + 4;
    502502        return prop->data;
     
    523523        }
    524524
    525         return fdt32_to_cpu(*php);
     525        return fdt32_ld(php);
    526526}
    527527
Note: See TracChangeset for help on using the changeset viewer.