1 | /* |
---|
2 | * Copyright (c) 2015, 2017 embedded brains GmbH. All rights reserved. |
---|
3 | * |
---|
4 | * embedded brains GmbH |
---|
5 | * Dornierstr. 4 |
---|
6 | * 82178 Puchheim |
---|
7 | * Germany |
---|
8 | * <rtems@embedded-brains.de> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #include <sys/param.h> |
---|
16 | |
---|
17 | #include <libfdt.h> |
---|
18 | |
---|
19 | #include <bsp/fdt.h> |
---|
20 | #include <bsp/linker-symbols.h> |
---|
21 | |
---|
22 | #ifndef BSP_FDT_IS_SUPPORTED |
---|
23 | #warning "BSP FDT support indication not defined" |
---|
24 | #endif |
---|
25 | |
---|
26 | #ifndef BSP_FDT_BLOB_SIZE_MAX |
---|
27 | #define BSP_FDT_BLOB_SIZE_MAX 0 |
---|
28 | #endif |
---|
29 | |
---|
30 | #ifdef BSP_FDT_BLOB_READ_ONLY |
---|
31 | static const uint32_t |
---|
32 | bsp_fdt_blob[BSP_FDT_BLOB_SIZE_MAX / sizeof(uint32_t)] = { 0xdeadbeef }; |
---|
33 | #else |
---|
34 | static uint32_t |
---|
35 | bsp_fdt_blob[BSP_FDT_BLOB_SIZE_MAX / sizeof(uint32_t)]; |
---|
36 | #endif |
---|
37 | |
---|
38 | void bsp_fdt_copy(const void *src) |
---|
39 | { |
---|
40 | const uint32_t *s = (const uint32_t *) src; |
---|
41 | #ifdef BSP_FDT_BLOB_COPY_TO_READ_ONLY_LOAD_AREA |
---|
42 | uint32_t *d = (uint32_t *) ((uintptr_t) &bsp_fdt_blob[0] |
---|
43 | - (uintptr_t) bsp_section_rodata_begin |
---|
44 | + (uintptr_t) bsp_section_rodata_load_begin); |
---|
45 | #else |
---|
46 | uint32_t *d = RTEMS_DECONST(uint32_t *, &bsp_fdt_blob[0]); |
---|
47 | #endif |
---|
48 | |
---|
49 | if (s != d) { |
---|
50 | size_t m = MIN(sizeof(bsp_fdt_blob), fdt_totalsize(src)); |
---|
51 | size_t n = (m + sizeof(*d) - 1) / sizeof(*d); |
---|
52 | size_t i; |
---|
53 | |
---|
54 | for (i = 0; i < n; ++i) { |
---|
55 | d[i] = s[i]; |
---|
56 | } |
---|
57 | |
---|
58 | rtems_cache_flush_multiple_data_lines(d, m); |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | const void *bsp_fdt_get(void) |
---|
63 | { |
---|
64 | return &bsp_fdt_blob[0]; |
---|
65 | } |
---|