source: rtems/bsps/shared/start/bsp-fdt.c @ 02c9eb85

Last change on this file since 02c9eb85 was 02c9eb85, checked in by Christian Mauderer <christian.mauderer@…>, on 07/20/20 at 05:46:53

bsps/fdt: Make sure data is cache aligned

The cache of the fdt blob is flushed after copy. Therefore it should be
aligned.

  • Property mode set to 100644
File size: 1.6 KB
Line 
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
31static const uint32_t
32bsp_fdt_blob[BSP_FDT_BLOB_SIZE_MAX / sizeof(uint32_t)] CPU_STRUCTURE_ALIGNMENT =
33  { 0xdeadbeef };
34#else
35static uint32_t
36bsp_fdt_blob[BSP_FDT_BLOB_SIZE_MAX / sizeof(uint32_t)] CPU_STRUCTURE_ALIGNMENT;
37#endif
38
39void bsp_fdt_copy(const void *src)
40{
41  const uint32_t *s = (const uint32_t *) src;
42#ifdef BSP_FDT_BLOB_COPY_TO_READ_ONLY_LOAD_AREA
43  uint32_t *d = (uint32_t *) ((uintptr_t) &bsp_fdt_blob[0]
44    - (uintptr_t) bsp_section_rodata_begin
45    + (uintptr_t) bsp_section_rodata_load_begin);
46#else
47  uint32_t *d = RTEMS_DECONST(uint32_t *, &bsp_fdt_blob[0]);
48#endif
49
50  if (s != d) {
51    size_t m = MIN(sizeof(bsp_fdt_blob), fdt_totalsize(src));
52    size_t aligned_size = roundup2(m, CPU_CACHE_LINE_BYTES);
53    size_t n = (m + sizeof(*d) - 1) / sizeof(*d);
54    size_t i;
55
56    for (i = 0; i < n; ++i) {
57      d[i] = s[i];
58    }
59
60    rtems_cache_flush_multiple_data_lines(d, aligned_size);
61  }
62}
63
64const void *bsp_fdt_get(void)
65{
66  return &bsp_fdt_blob[0];
67}
Note: See TracBrowser for help on using the repository browser.