<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body smarttemplateinserted="true">
<div id="smartTemplate4-template">Sure, I can move it to the shared
directory (riscv/shared/start).<br>
</div>
<div><br>
</div>
<div class="moz-cite-prefix">On 2022-08-17 11:16, Hesham Almatary
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CA+wsVCBYpdV_+=xYkX4zPH-9cnwgDEq5mYJ6BC137QoCLjRxBA@mail.gmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<div dir="ltr">
<div>Thanks for the patch. LGTM. I wonder if we can also reuse
that for the generic shared RISC-V BSP (e.g.,
bsps/riscv/riscv) instead of just NOEL?</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, 17 Aug 2022 at
09:58, Daniel Cederman <<a
href="mailto:cederman@gaisler.com" moz-do-not-send="true"
class="moz-txt-link-freetext">cederman@gaisler.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">Uses the first entry in
the /memory node to determine the end of the<br>
work area. Falls back on linker symbol if unable to parse
the node.<br>
---<br>
bsps/riscv/noel/start/bspgetworkarea.c | 144
+++++++++++++++++++++++++<br>
spec/build/bsps/riscv/noel/obj.yml | 1 +<br>
2 files changed, 145 insertions(+)<br>
create mode 100644 bsps/riscv/noel/start/bspgetworkarea.c<br>
<br>
diff --git a/bsps/riscv/noel/start/bspgetworkarea.c
b/bsps/riscv/noel/start/bspgetworkarea.c<br>
new file mode 100644<br>
index 0000000000..1fa051d25e<br>
--- /dev/null<br>
+++ b/bsps/riscv/noel/start/bspgetworkarea.c<br>
@@ -0,0 +1,144 @@<br>
+/* SPDX-License-Identifier: BSD-2-Clause */<br>
+<br>
+/**<br>
+ * @file<br>
+ *<br>
+ * @brief BSP specific initialization support routines<br>
+ *<br>
+ */<br>
+<br>
+/*<br>
+ * COPYRIGHT (c) 1989-2020.<br>
+ * On-Line Applications Research Corporation (OAR).<br>
+ * Cobham Gaisler AB.<br>
+ *<br>
+ * Redistribution and use in source and binary forms, with
or without<br>
+ * modification, are permitted provided that the following
conditions<br>
+ * are met:<br>
+ * 1. Redistributions of source code must retain the above
copyright<br>
+ * notice, this list of conditions and the following
disclaimer.<br>
+ * 2. Redistributions in binary form must reproduce the
above copyright<br>
+ * notice, this list of conditions and the following
disclaimer in the<br>
+ * documentation and/or other materials provided with
the distribution.<br>
+ *<br>
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS"<br>
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, THE<br>
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE<br>
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE<br>
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR<br>
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF<br>
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS<br>
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN<br>
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE)<br>
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE<br>
+ * POSSIBILITY OF SUCH DAMAGE.<br>
+ */<br>
+<br>
+#include <bsp.h><br>
+#include <bsp/fdt.h><br>
+<br>
+#include <rtems/sysinit.h><br>
+<br>
+#include <libfdt.h><br>
+<br>
+/*<br>
+ * These are provided by the linkcmds for ALL of the BSPs
which use this file.<br>
+ */<br>
+extern char WorkAreaBase[];<br>
+extern char RamEnd[];<br>
+<br>
+static Memory_Area _Memory_Areas[ 1 ];<br>
+<br>
+static const char memory_path[] = "/memory";<br>
+<br>
+static void* get_end_of_memory_from_fdt(void)<br>
+{<br>
+ const void *fdt;<br>
+ const void *val;<br>
+ int node;<br>
+ int parent;<br>
+ int ac;<br>
+ int sc;<br>
+ int len;<br>
+ uintptr_t start;<br>
+ uintptr_t size;<br>
+<br>
+ fdt = bsp_fdt_get();<br>
+<br>
+ node = fdt_path_offset_namelen(<br>
+ fdt,<br>
+ memory_path,<br>
+ (int) sizeof(memory_path) - 1<br>
+ );<br>
+<br>
+ if (node < 0) {<br>
+ return NULL;<br>
+ }<br>
+<br>
+ parent = fdt_parent_offset(fdt, node);<br>
+ if (parent < 0) {<br>
+ return NULL;<br>
+ }<br>
+<br>
+ ac = fdt_address_cells(fdt, parent);<br>
+ if (ac != 1 && ac != 2) {<br>
+ return NULL;<br>
+ }<br>
+<br>
+ sc = fdt_size_cells(fdt, parent);<br>
+ if (sc != 1 && sc != 2) {<br>
+ return NULL;<br>
+ }<br>
+<br>
+ if (sc > ac) {<br>
+ return NULL;<br>
+ }<br>
+<br>
+ val = fdt_getprop(fdt, node, "reg", &len);<br>
+ if (len < sc + ac) {<br>
+ return NULL;<br>
+ }<br>
+<br>
+ if (ac == 1) {<br>
+ start = fdt32_to_cpu(((fdt32_t *)val)[0]);<br>
+ size = fdt32_to_cpu(((fdt32_t *)val)[1]);<br>
+ }<br>
+<br>
+ if (ac == 2) {<br>
+ start = fdt64_to_cpu(((fdt64_t *)val)[0]);<br>
+<br>
+ if (sc == 1)<br>
+ size = fdt32_to_cpu(((fdt32_t *)(val+8))[0]);<br>
+ else<br>
+ size = fdt64_to_cpu(((fdt64_t *)val)[1]);<br>
+ }<br>
+<br>
+ return (void*) (start + size);<br>
+}<br>
+<br>
+static void bsp_memory_initialize( void )<br>
+{<br>
+ void *end;<br>
+<br>
+ /* get end of memory from the "/memory" node in the fdt
*/<br>
+ end = get_end_of_memory_from_fdt();<br>
+ if (end == 0) {<br>
</blockquote>
<div>NULL instead of 0?</div>
<div> <br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
+ /* fall back to linker symbol if "/memory" node not
found or invalid */<br>
+ end = RamEnd;<br>
+ }<br>
+ _Memory_Initialize( &_Memory_Areas[ 0 ],
WorkAreaBase, end );<br>
+}<br>
+<br>
+RTEMS_SYSINIT_ITEM(<br>
+ bsp_memory_initialize,<br>
+ RTEMS_SYSINIT_MEMORY,<br>
+ RTEMS_SYSINIT_ORDER_MIDDLE<br>
+);<br>
+<br>
+static const Memory_Information _Memory_Information =<br>
+ MEMORY_INFORMATION_INITIALIZER( _Memory_Areas );<br>
+<br>
+const Memory_Information *_Memory_Get( void )<br>
+{<br>
+ return &_Memory_Information;<br>
+}<br>
diff --git a/spec/build/bsps/riscv/noel/obj.yml
b/spec/build/bsps/riscv/noel/obj.yml<br>
index e1b652fa93..f9902f83b5 100644<br>
--- a/spec/build/bsps/riscv/noel/obj.yml<br>
+++ b/spec/build/bsps/riscv/noel/obj.yml<br>
@@ -22,6 +22,7 @@ source:<br>
- bsps/riscv/noel/console/console-config.c<br>
- bsps/riscv/riscv/irq/irq.c<br>
- bsps/riscv/noel/start/bsp_fatal_halt.c<br>
+- bsps/riscv/noel/start/bspgetworkarea.c<br>
- bsps/riscv/riscv/start/bspstart.c<br>
- bsps/shared/cache/nocache.c<br>
- bsps/shared/dev/btimer/btimer-cpucounter.c<br>
-- <br>
2.34.1<br>
<br>
_______________________________________________<br>
devel mailing list<br>
<a href="mailto:devel@rtems.org" target="_blank"
moz-do-not-send="true" class="moz-txt-link-freetext">devel@rtems.org</a><br>
<a href="http://lists.rtems.org/mailman/listinfo/devel"
rel="noreferrer" target="_blank" moz-do-not-send="true"
class="moz-txt-link-freetext">http://lists.rtems.org/mailman/listinfo/devel</a><br>
</blockquote>
</div>
</div>
</blockquote>
<br>
</body>
</html>