[PATCH 0/4] Import and Port Beagle pinmux driver

2021-03-13 Thread G S Niteesh Babu
The following series of patches import and port the beagle
pinmux driver from FreeBSD to RTEMS.

Porting this driver will avoid double initialization of
pin multiplexers once during RTEMS initialization and second
time during libBSD initialization.

UPDATE #3782

G S Niteesh Babu (4):
  bsps/shared/ofw: Add rtems_ofw_is_node_compatible
  bsp/beagle: Import Beagle pinmux from FreeBSD
  bsps/beagle: Added SOC detection using FDT
  bsp/beagle: Ported Beagle pinmux driver to RTEMS

 bsps/arm/beagle/start/bsp-soc-detect.c|  55 ++
 bsps/arm/beagle/start/bsp-soc-detect.h|  38 ++
 bsps/arm/beagle/start/bspstart.c  |  54 +-
 .../arm/ti/am335x/am335x_scm_padconf.h|  47 ++
 bsps/include/arm/ti/ti_cpuid.h|  48 ++
 bsps/include/arm/ti/ti_pinmux.h   |  87 +++
 bsps/include/ofw/ofw.h|  17 +
 .../sys/arm/ti/am335x/am335x_scm_padconf.c| 307 ++
 bsps/shared/freebsd/sys/arm/ti/ti_pinmux.c| 574 ++
 bsps/shared/ofw/ofw.c |  12 +
 spec/build/bsps/arm/beagle/obj.yml|   1 +
 spec/build/bsps/obj.yml   |   6 +
 12 files changed, 1240 insertions(+), 6 deletions(-)
 create mode 100644 bsps/arm/beagle/start/bsp-soc-detect.c
 create mode 100644 bsps/arm/beagle/start/bsp-soc-detect.h
 create mode 100644 bsps/include/arm/ti/am335x/am335x_scm_padconf.h
 create mode 100644 bsps/include/arm/ti/ti_cpuid.h
 create mode 100644 bsps/include/arm/ti/ti_pinmux.h
 create mode 100644 bsps/shared/freebsd/sys/arm/ti/am335x/am335x_scm_padconf.c
 create mode 100644 bsps/shared/freebsd/sys/arm/ti/ti_pinmux.c

-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 1/4] bsps/shared/ofw: Add rtems_ofw_is_node_compatible

2021-03-13 Thread G S Niteesh Babu
This patch extends the RTEMS OFW API by adding
rtems_ofw_find_device_by_compat

This function checks if a node has the expected compatible
property.
---
 bsps/include/ofw/ofw.h | 17 +
 bsps/shared/ofw/ofw.c  | 12 
 2 files changed, 29 insertions(+)

diff --git a/bsps/include/ofw/ofw.h b/bsps/include/ofw/ofw.h
index 411010be89..bfd91d20ea 100644
--- a/bsps/include/ofw/ofw.h
+++ b/bsps/include/ofw/ofw.h
@@ -541,6 +541,23 @@ bool rtems_ofw_node_status( phandle_t node );
  */
 phandle_t rtems_ofw_find_device_by_compat( const char *compat );
 
+/**
+ * @brief check a nodes compatible property.
+ *
+ * This routine is local to RTEMS OFW and does not have an corresponding
+ * FreeBSD OFW pair.
+ *
+ * Return true if @a compat equals @a node compatible property
+ *
+ * @param[in] node phandle of node
+ * @param[in] compat Compatible string
+ *
+ * @retval 1 If node contains the @a compat as a element in compatible
+ * property.
+ * @retval 0 Otherwise.
+ */
+bool rtems_ofw_is_node_compatible( phandle_t node, const char *compat );
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index 1c3a81785d..f4b8b63931 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -690,3 +690,15 @@ phandle_t rtems_ofw_find_device_by_compat( const char 
*compat )
   offset = fdt_node_offset_by_compatible(fdtp, -1, compat);
   return rtems_fdt_offset_to_phandle(offset);
 }
+
+bool rtems_ofw_is_node_compatible(
+  phandle_t node,
+  const char *compat
+)
+{
+  int offset;
+
+  offset = rtems_fdt_phandle_to_offset(node);
+
+  return fdt_node_check_compatible(fdtp, offset, compat) == 0;
+}
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 2/4] bsp/beagle: Import Beagle pinmux from FreeBSD

2021-03-13 Thread G S Niteesh Babu
This patch imports the beagle pinmux driver from FreeBSD into
RTEMS. Previously this driver was placed in RTEMS-libBSD but
this caused double initialization of few pins once during RTEMS
initialization and second time during libBSD initialization.
The following patches port the driver from FreeBSD to RTEMS and
will remove the driver from RTEMS-libBSD.

RTEMS Ticket Update: #3784

FreeBSD head: ca12b7e9534b10af022fed60c043984dbaf4003d

The following files have been imported from FreeBSD:
1) freebsd/sys/arm/ti/am335x/am335x_scm_padconf.h
2) freebsd/sys/arm/ti/am335x/am335x_scm_padconf.c
3) freebsd/sys/arm/ti/ti_pinmux.h
4) freebsd/sys/arm/ti/ti_pinmux.c
---
 .../arm/ti/am335x/am335x_scm_padconf.h|  47 ++
 bsps/include/arm/ti/ti_pinmux.h   |  80 +++
 .../sys/arm/ti/am335x/am335x_scm_padconf.c| 303 
 bsps/shared/freebsd/sys/arm/ti/ti_pinmux.c| 461 ++
 4 files changed, 891 insertions(+)
 create mode 100644 bsps/include/arm/ti/am335x/am335x_scm_padconf.h
 create mode 100644 bsps/include/arm/ti/ti_pinmux.h
 create mode 100644 bsps/shared/freebsd/sys/arm/ti/am335x/am335x_scm_padconf.c
 create mode 100644 bsps/shared/freebsd/sys/arm/ti/ti_pinmux.c

diff --git a/bsps/include/arm/ti/am335x/am335x_scm_padconf.h 
b/bsps/include/arm/ti/am335x/am335x_scm_padconf.h
new file mode 100644
index 00..afbb15381f
--- /dev/null
+++ b/bsps/include/arm/ti/am335x/am335x_scm_padconf.h
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 2012 Damjan Marion 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef AM335X_SCM_PADCONF_H
+#define AM335X_SCM_PADCONF_H
+
+#define SLEWCTRL   (0x01 << 6) /* faster(0) or slower(1) slew rate. */
+#define RXACTIVE   (0x01 << 5) /* Input enable value for the Pad */
+#define PULLTYPESEL(0x01 << 4) /* Pad pullup/pulldown type selection */
+#define PULLUDEN   (0x01 << 3) /* Pullup/pulldown disabled */
+
+#define PADCONF_OUTPUT (PULLUDEN)
+#define PADCONF_OUTPUT_PULLUP  (PULLTYPESEL)
+#define PADCONF_OUTPUT_PULLDOWN(0)
+#define PADCONF_INPUT  (RXACTIVE | PULLUDEN)
+#define PADCONF_INPUT_PULLUP   (RXACTIVE | PULLTYPESEL)
+#define PADCONF_INPUT_PULLDOWN (RXACTIVE)
+#define PADCONF_INPUT_PULLUP_SLOW  (PADCONF_INPUT_PULLUP | SLEWCTRL)
+
+extern const struct ti_pinmux_device ti_am335x_pinmux_dev;
+
+#endif /* AM335X_SCM_PADCONF_H */
\ No newline at end of file
diff --git a/bsps/include/arm/ti/ti_pinmux.h b/bsps/include/arm/ti/ti_pinmux.h
new file mode 100644
index 00..52409df61d
--- /dev/null
+++ b/bsps/include/arm/ti/ti_pinmux.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2010
+ * Ben Gray .
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *must display the following acknowledgement:
+ * This product includes software developed by Ben Gray.
+ * 4. The name of the company nor the name of the author may be used to
+ *endorse or promote products derived from this software without specific
+ *prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BEN GRAY ``AS IS'' AND ANY EXPRESS OR
+ *

[PATCH 3/4] bsps/beagle: Added SOC detection using FDT

2021-03-13 Thread G S Niteesh Babu
Detects the SOC type using FDT and also replaces the ti_cpuid.h
header in FreeBSD with custom one.
---
 bsps/arm/beagle/start/bsp-soc-detect.c | 55 ++
 bsps/arm/beagle/start/bsp-soc-detect.h | 38 ++
 bsps/arm/beagle/start/bspstart.c   | 23 ---
 bsps/include/arm/ti/ti_cpuid.h | 48 ++
 spec/build/bsps/arm/beagle/obj.yml |  1 +
 5 files changed, 159 insertions(+), 6 deletions(-)
 create mode 100644 bsps/arm/beagle/start/bsp-soc-detect.c
 create mode 100644 bsps/arm/beagle/start/bsp-soc-detect.h
 create mode 100644 bsps/include/arm/ti/ti_cpuid.h

diff --git a/bsps/arm/beagle/start/bsp-soc-detect.c 
b/bsps/arm/beagle/start/bsp-soc-detect.c
new file mode 100644
index 00..445c8881ff
--- /dev/null
+++ b/bsps/arm/beagle/start/bsp-soc-detect.c
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup arm_Beagle
+ *
+ * @brief
+ */
+
+/*
+ * Copyright (C) <2020> Niteesh Babu 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+#include 
+#include 
+#include "bsp-soc-detect.h"
+
+int _ti_chip;
+
+void bsp_soc_detect( void )
+{
+  const void *fdt = bsp_fdt_get();
+
+  if (fdt_node_offset_by_compatible(fdt, -1, "ti_am33xx") != FDT_ERR_NOTFOUND) 
{
+_ti_chip = CHIP_AM335X;
+  } else if (fdt_node_offset_by_compatible(fdt, -1, "ti_omap3") != 
FDT_ERR_NOTFOUND) {
+_ti_chip = CHIP_OMAP_3;
+  } else {
+printk("Unknown platform");
+_ti_chip = -1;
+  }
+}
diff --git a/bsps/arm/beagle/start/bsp-soc-detect.h 
b/bsps/arm/beagle/start/bsp-soc-detect.h
new file mode 100644
index 00..545bba3eaf
--- /dev/null
+++ b/bsps/arm/beagle/start/bsp-soc-detect.h
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup arm_Beagle
+ *
+ * @brief
+ */
+
+/*
+ * Copyright (C) <2020> Niteesh Babu 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+
+void bsp_soc_detect( void );
diff --git a/bsps/arm/beagle/start/bspstart.c b/bsps/arm/beagle/start/bspstart.c
index 3c05f2a9cd..0a6f1b4a64 100644
--- a/bsps/arm/beagle/start/bspstart.c
+++ b/bsps/arm/beagle/start/bspstart.c
@@ -19,17 +19,28 @@
 #include 
 #include 
 #include 
+#include "bsp-soc-detect.h"
 
 #include "bspdebug.h"
 
 void bsp_start(void)
 {
-#if IS_DM3730
-  const char* type = "dm3730-based";
-#endif
-#if IS_AM335X
-  const char* type = "am335x-based";
-#endif
+  c

[PATCH libBSD] arm/ti/ti_pinmux: Remove TI pinmux driver

2021-03-13 Thread G S Niteesh Babu
The TI driver has been moved to RTEMS so the driver can be removed
from libBSD.

The following files have been removed from libBSD and moved to
RTEMS.
1) ti/am335x/am335x_scm_padconf.c
2) ti/am335x/am335x_scm_padconf.h
3) ti/ti_pinmux.c
4) ti/ti_pinmux.h

Update #3784
---
 .../sys/arm/ti/am335x/am335x_scm_padconf.c| 305 
 .../sys/arm/ti/am335x/am335x_scm_padconf.h|  47 --
 freebsd/sys/arm/ti/ti_pinmux.c| 463 --
 freebsd/sys/arm/ti/ti_pinmux.h|  80 ---
 libbsd.py |   4 -
 rtemsbsd/include/bsp/nexus-devices.h  |   1 -
 .../machine/rtems-bsd-kernel-namespace.h  |   5 -
 7 files changed, 905 deletions(-)
 delete mode 100644 freebsd/sys/arm/ti/am335x/am335x_scm_padconf.c
 delete mode 100644 freebsd/sys/arm/ti/am335x/am335x_scm_padconf.h
 delete mode 100644 freebsd/sys/arm/ti/ti_pinmux.c
 delete mode 100644 freebsd/sys/arm/ti/ti_pinmux.h

diff --git a/freebsd/sys/arm/ti/am335x/am335x_scm_padconf.c 
b/freebsd/sys/arm/ti/am335x/am335x_scm_padconf.c
deleted file mode 100644
index 8823b6af..
--- a/freebsd/sys/arm/ti/am335x/am335x_scm_padconf.c
+++ /dev/null
@@ -1,305 +0,0 @@
-#include 
-
-/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
- *
- * Copyright (c) 2012 Damjan Marion 
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *notice, this list of conditions and the following disclaimer in the
- *documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include 
-__FBSDID("$FreeBSD$");
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-
-#include 
-
-#define _PIN(r, b, gp, gm, m0, m1, m2, m3, m4, m5, m6, m7) \
-   {   .reg_off = r, \
-   .gpio_pin = gp, \
-   .gpio_mode = gm, \
-   .ballname = b, \
-   .muxmodes[0] = m0, \
-   .muxmodes[1] = m1, \
-   .muxmodes[2] = m2, \
-   .muxmodes[3] = m3, \
-   .muxmodes[4] = m4, \
-   .muxmodes[5] = m5, \
-   .muxmodes[6] = m6, \
-   .muxmodes[7] = m7, \
-   }
-
-const static struct ti_pinmux_padstate ti_padstate_devmap[] = {
-   {"output",  PADCONF_OUTPUT },
-   {"output_pullup",   PADCONF_OUTPUT_PULLUP },
-   {"input",   PADCONF_INPUT },
-   {"input_pulldown",  PADCONF_INPUT_PULLDOWN },
-   {"input_pullup",PADCONF_INPUT_PULLUP },
-   {"i2c", PADCONF_INPUT_PULLUP_SLOW },
-   { .state = NULL }
-};
-
-const static struct ti_pinmux_padconf ti_padconf_devmap[] = {
-   _PIN(0x000, "GPMC_AD0", 32, 7,"gpmc_ad0", "mmc1_dat0", NULL, 
NULL, NULL, NULL, NULL, "gpio1_0"),
-   _PIN(0x004, "GPMC_AD1", 33, 7,"gpmc_ad1", "mmc1_dat1", NULL, 
NULL, NULL, NULL, NULL, "gpio1_1"),
-   _PIN(0x008, "GPMC_AD2", 34, 7,"gpmc_ad2", "mmc1_dat2", NULL, 
NULL, NULL, NULL, NULL, "gpio1_2"),
-   _PIN(0x00C, "GPMC_AD3", 35, 7,"gpmc_ad3", "mmc1_dat3", NULL, 
NULL, NULL, NULL, NULL, "gpio1_3"),
-   _PIN(0x010, "GPMC_AD4", 36, 7,"gpmc_ad4", "mmc1_dat4", NULL, 
NULL, NULL, NULL, NULL, "gpio1_4"),
-   _PIN(0x014, "GPMC_AD5", 37, 7,"gpmc_ad5", "mmc1_dat5", NULL, 
NULL, NULL, NULL, NULL, "gpio1_5"),
-   _PIN(0x018, "GPMC_AD6", 38, 7,"gpmc_ad6", "mmc1_dat6", NULL, 
NULL, NULL, NULL, NULL, "gpio1_6"),
-   _PIN(0x01C, "GPMC_AD7", 39, 7,"gpmc_ad7", "mmc1_dat7", NULL, 
NULL, NULL, NULL, NULL, "gpio1_7"),
-   _PIN(0x020, "GPMC_AD8", 22, 7, "gpmc_ad8", "lcd_data23", 
"mmc1_dat0", "mmc2_dat4", "ehrpwm2A", NULL, NULL, "gpio0_22"),
-   _PIN(0x024, "GPMC_AD9", 23, 7, "gpmc_ad9", "lcd_data22", 
"mmc

[PATCH] rtems-fdt/rtems-fdt.c: Fix bug in loop termination

2021-03-17 Thread G S Niteesh Babu
The while loop, loops infinitely in case of raw FDT data.
The loop condition (size) is not modified during iterations.
---
 cpukit/libmisc/rtems-fdt/rtems-fdt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/cpukit/libmisc/rtems-fdt/rtems-fdt.c 
b/cpukit/libmisc/rtems-fdt/rtems-fdt.c
index 0ea365314f..7747ba9bf8 100644
--- a/cpukit/libmisc/rtems-fdt/rtems-fdt.c
+++ b/cpukit/libmisc/rtems-fdt/rtems-fdt.c
@@ -580,7 +580,7 @@ rtems_fdt_load (const char* filename, rtems_fdt_handle* 
handle)
 close (bf);
 return -RTEMS_FDT_ERR_READ_FAIL;
   }
-  r -= size;
+  size -= r;
   buf += r;
 }
   }
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH RTEMS] bsps/beagle: Refactored i2c driver

2021-03-22 Thread G S Niteesh Babu
Refactored the i2c driver to parse register values from the device
tree rather than hardcoding them. But still the clocks have to
initialized manually.
---
 bsps/arm/beagle/i2c/bbb-i2c.c | 100 --
 bsps/arm/beagle/include/bsp.h |   4 ++
 bsps/arm/beagle/include/bsp/i2c.h |  32 +-
 bsps/arm/beagle/start/bspstart.c  |  53 +++-
 4 files changed, 96 insertions(+), 93 deletions(-)

diff --git a/bsps/arm/beagle/i2c/bbb-i2c.c b/bsps/arm/beagle/i2c/bbb-i2c.c
index b2a7cf814d..c315b6fc3b 100644
--- a/bsps/arm/beagle/i2c/bbb-i2c.c
+++ b/bsps/arm/beagle/i2c/bbb-i2c.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 typedef struct bbb_i2c_bus {
   i2c_bus base;
@@ -34,12 +35,6 @@ typedef struct bbb_i2c_bus {
 volatile uint32_t *i2c_clkctrl;
 volatile uint32_t *clkstctrl;
   } clkregs;
-  struct {
-volatile uint32_t *conf_sda;
-uint32_t mmode_sda;
-volatile uint32_t *conf_scl;
-uint32_t mmode_scl;
-  } pinregs;
   rtems_id task_id;
   rtems_vector_number irq;
   i2c_msg *buffer;
@@ -56,19 +51,29 @@ typedef struct bbb_i2c_bus {
 #else
 #define debug_print(fmt, args...)
 #endif
+/*
+ * Here we assume the number of i2c nodes
+ * will be less than 100.
+ */
+#define PATH_LEN strlen("/dev/i2c-xx")
 
 static int am335x_i2c_fill_registers(
   bbb_i2c_bus *bus,
-  uintptr_t register_base
+  phandle_tnode
 )
 {
-  /* FIXME: The pin handling should be replaced by a proper pin handling during
-   * initialization. This one is heavily board specific. */
-#if ! IS_AM335X
-  printk ("The I2C driver currently only works on Beagle Bone. Please add your 
pin configs.");
-  return EINVAL;
-#endif
-  bus->regs = (volatile bbb_i2c_regs *) register_base;
+  ssize_t rv;
+  rtems_ofw_memory_area reg;
+
+  rv = rtems_ofw_get_reg(node, ®, sizeof(reg));
+  if (rv <= 0)
+return EINVAL;
+
+  bus->regs = (volatile bbb_i2c_regs *)reg.start;
+
+  /*
+   * FIXME: Implement a clock driver to parse and setup clocks
+   */
   switch ((intptr_t) bus->regs) {
   case AM335X_I2C0_BASE:
 bus->clkregs.ctrl_clkctrl = ®(AM335X_SOC_CM_WKUP_REGS +
@@ -77,10 +82,6 @@ static int am335x_i2c_fill_registers(
  AM335X_CM_WKUP_I2C0_CLKCTRL);
 bus->clkregs.clkstctrl = ®(AM335X_SOC_CM_WKUP_REGS +
AM335X_CM_WKUP_CLKSTCTRL);
-bus->pinregs.conf_sda = ®(AM335X_PADCONF_BASE + AM335X_CONF_I2C0_SDA);
-bus->pinregs.mmode_sda = 0;
-bus->pinregs.conf_scl = ®(AM335X_PADCONF_BASE + AM335X_CONF_I2C0_SCL);
-bus->pinregs.mmode_scl = 0;
 break;
   case AM335X_I2C1_BASE:
 bus->clkregs.ctrl_clkctrl = ®(AM335X_SOC_CM_WKUP_REGS +
@@ -88,10 +89,6 @@ static int am335x_i2c_fill_registers(
 bus->clkregs.i2c_clkctrl = ®(AM335X_CM_PER_ADDR +
  AM335X_CM_PER_I2C1_CLKCTRL);
 bus->clkregs.clkstctrl = NULL;
-bus->pinregs.conf_sda = ®(AM335X_PADCONF_BASE + AM335X_CONF_SPI0_D1);
-bus->pinregs.mmode_sda = 2;
-bus->pinregs.conf_scl = ®(AM335X_PADCONF_BASE + AM335X_CONF_SPI0_CS0);
-bus->pinregs.mmode_scl = 2;
 break;
   case AM335X_I2C2_BASE:
 bus->clkregs.ctrl_clkctrl = ®(AM335X_SOC_CM_WKUP_REGS +
@@ -99,24 +96,12 @@ static int am335x_i2c_fill_registers(
 bus->clkregs.i2c_clkctrl = ®(AM335X_CM_PER_ADDR +
  AM335X_CM_PER_I2C2_CLKCTRL);
 bus->clkregs.clkstctrl = NULL;
-bus->pinregs.conf_sda = ®(AM335X_PADCONF_BASE + AM335X_CONF_UART1_CTSN);
-bus->pinregs.mmode_sda = 3;
-bus->pinregs.conf_scl = ®(AM335X_PADCONF_BASE + AM335X_CONF_UART1_RTSN);
-bus->pinregs.mmode_scl = 3;
 break;
   default:
 return EINVAL;
   }
-  return 0;
-}
 
-static void am335x_i2c_pinmux( bbb_i2c_bus *bus )
-{
-  *bus->pinregs.conf_sda =
-( BBB_RXACTIVE | BBB_SLEWCTRL | bus->pinregs.mmode_sda);
-
-  *bus->pinregs.conf_scl =
-( BBB_RXACTIVE | BBB_SLEWCTRL | bus->pinregs.mmode_scl);
+  return 0;
 }
 
 static void am335x_i2c_module_clk_enable( bbb_i2c_bus *bus )
@@ -453,18 +438,16 @@ static void am335x_i2c_destroy( i2c_bus *base )
   i2c_bus_destroy_and_free( &bus->base );
 }
 
-int am335x_i2c_bus_register(
-  const char *bus_path,
-  uintptr_t   register_base,
-  uint32_tinput_clock,
-  rtems_vector_number irq
+static int am335x_i2c_bus_register(
+  phandle_t   node
 )
 {
-  bbb_i2c_bus  *bus;
-  rtems_status_code sc;
-  int   err;
-
-  (void) input_clock; /* FIXME: Unused. Left for compatibility. */
+  bbb_i2c_bus*bus;
+  rtems_status_code   sc;
+  rtems_vector_number irq;
+  int err;
+  int unit;
+  charbus_path[PATH_LEN];
 
   bus = (bbb_i2c_bus *) i2c_bus_alloc_and_init( sizeof( *bus ) );
 
@@ -472,15 +455,24 @@ int am335x_i2c_bus_register(
 return -1;
   }
 
+  unit = beagle_get_node_unit(node);
+
+  snprintf(bus_path, PATH_LEN, "/dev/i2c-%d", unit);
+
+  err = rtems_ofw_get_interrupts(node

[PATCH RTEMS-docs] user/bsps/arm/beagle: Update i2c initialization instructions

2021-04-10 Thread G S Niteesh Babu
The new i2c driver in the beagle BSP uses FDT based initialization.
This updates the documentation of the BSP about the same.
---
 user/bsps/arm/beagle.rst | 41 +++-
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/user/bsps/arm/beagle.rst b/user/bsps/arm/beagle.rst
index ac49b1c..d20942e 100644
--- a/user/bsps/arm/beagle.rst
+++ b/user/bsps/arm/beagle.rst
@@ -67,23 +67,38 @@ Add the following to a file named uEnv.txt:
 I2C Driver
 --
 
-The Beagle has the `i2c-0` device registered at initialization. For registering
-`i2c-1` and `i2c-2` ``bbb_register_i2c_1()`` and
-``bbb_register_i2c_2()`` wrapper functions are respectively used.
+The Beagle i2c initialization is based on the device tree. To initialize a i2c
+device, the user has to enable the respective node in the device tree using
+overlays.
 
-For registering an I2C device with a custom path (say `/dev/i2c-3`) the
-function ``am335x_i2c_bus_register()`` has to be used.
+For registering an I2C device with a custom path (say `/dev/i2c-eeprom`) an
+overlay has to be provided. The overlay must add an additional attribute
+`rtems,path` with the custom path as value to the respective i2c node.
 
-The function prototype is given below:
+For example,
 
-.. code-block:: C
+.. code-block::
+ /dts-v1/;
+
+ / {
+compatible = "ti,am335x-bone-black", "ti,am335x-bone", "ti,am33xx";
+
+fragment@0 {
+   target = <0x>;
+
+   __overlay__ {
+  compatible = "rtems,bsp-i2c", "ti,omap4-i2c";
+  status = "okay";
+  rtems,path = "/dev/i2c-eeprom";
+   };
+};
+
+__fixups__ {
+   i2c0 = "/fragment@0:target:0";
+};
+ };
 
-   int am335x_i2c_bus_register(
-   const char *bus_path,
-   uintptr_t   register_base,
-   uint32_tinput_clock,
-   rtems_vector_number irq
-   );
+The above example registers a custom path `/dev/i2c-eeprom` for i2c0.
 
 SPI Driver
 --
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH RTEMS v2 0/1] bsp/beagle: Refactored i2c driver and Updated

2021-04-10 Thread G S Niteesh Babu
The following two patches update the Beagle BSP i2c driver to use
device tree based initialization and the documentation related to
it.

G S Niteesh Babu (1):
  bsps/beagle: Refactored i2c driver

 bsps/arm/beagle/i2c/bbb-i2c.c | 122 ++
 bsps/arm/beagle/include/bsp.h |   4 +
 bsps/arm/beagle/include/bsp/i2c.h |  32 +---
 bsps/arm/beagle/start/bspstart.c  |  51 +
 4 files changed, 114 insertions(+), 95 deletions(-)

-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH RTEMS v2 1/1] bsps/beagle: Refactored i2c driver

2021-04-10 Thread G S Niteesh Babu
Refactored the i2c driver to parse register values from the device
tree rather than hardcoding them. But still the clocks have to
initialized manually.
---
 bsps/arm/beagle/i2c/bbb-i2c.c | 122 ++
 bsps/arm/beagle/include/bsp.h |   4 +
 bsps/arm/beagle/include/bsp/i2c.h |  32 +---
 bsps/arm/beagle/start/bspstart.c  |  51 +
 4 files changed, 114 insertions(+), 95 deletions(-)

diff --git a/bsps/arm/beagle/i2c/bbb-i2c.c b/bsps/arm/beagle/i2c/bbb-i2c.c
index b2a7cf814d..b842fd820a 100644
--- a/bsps/arm/beagle/i2c/bbb-i2c.c
+++ b/bsps/arm/beagle/i2c/bbb-i2c.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 
 typedef struct bbb_i2c_bus {
   i2c_bus base;
@@ -34,12 +35,6 @@ typedef struct bbb_i2c_bus {
 volatile uint32_t *i2c_clkctrl;
 volatile uint32_t *clkstctrl;
   } clkregs;
-  struct {
-volatile uint32_t *conf_sda;
-uint32_t mmode_sda;
-volatile uint32_t *conf_scl;
-uint32_t mmode_scl;
-  } pinregs;
   rtems_id task_id;
   rtems_vector_number irq;
   i2c_msg *buffer;
@@ -56,19 +51,22 @@ typedef struct bbb_i2c_bus {
 #else
 #define debug_print(fmt, args...)
 #endif
+/*
+ * Here we assume the number of i2c nodes
+ * will be less than 100.
+ */
+#define PATH_LEN (strlen("/dev/i2c-xx") + 1)
 
 static int am335x_i2c_fill_registers(
   bbb_i2c_bus *bus,
-  uintptr_t register_base
+  uint32_t base
 )
 {
-  /* FIXME: The pin handling should be replaced by a proper pin handling during
-   * initialization. This one is heavily board specific. */
-#if ! IS_AM335X
-  printk ("The I2C driver currently only works on Beagle Bone. Please add your 
pin configs.");
-  return EINVAL;
-#endif
-  bus->regs = (volatile bbb_i2c_regs *) register_base;
+  bus->regs = (volatile bbb_i2c_regs *)base;
+
+  /*
+   * FIXME: Implement a clock driver to parse and setup clocks
+   */
   switch ((intptr_t) bus->regs) {
   case AM335X_I2C0_BASE:
 bus->clkregs.ctrl_clkctrl = ®(AM335X_SOC_CM_WKUP_REGS +
@@ -77,10 +75,6 @@ static int am335x_i2c_fill_registers(
  AM335X_CM_WKUP_I2C0_CLKCTRL);
 bus->clkregs.clkstctrl = ®(AM335X_SOC_CM_WKUP_REGS +
AM335X_CM_WKUP_CLKSTCTRL);
-bus->pinregs.conf_sda = ®(AM335X_PADCONF_BASE + AM335X_CONF_I2C0_SDA);
-bus->pinregs.mmode_sda = 0;
-bus->pinregs.conf_scl = ®(AM335X_PADCONF_BASE + AM335X_CONF_I2C0_SCL);
-bus->pinregs.mmode_scl = 0;
 break;
   case AM335X_I2C1_BASE:
 bus->clkregs.ctrl_clkctrl = ®(AM335X_SOC_CM_WKUP_REGS +
@@ -88,10 +82,6 @@ static int am335x_i2c_fill_registers(
 bus->clkregs.i2c_clkctrl = ®(AM335X_CM_PER_ADDR +
  AM335X_CM_PER_I2C1_CLKCTRL);
 bus->clkregs.clkstctrl = NULL;
-bus->pinregs.conf_sda = ®(AM335X_PADCONF_BASE + AM335X_CONF_SPI0_D1);
-bus->pinregs.mmode_sda = 2;
-bus->pinregs.conf_scl = ®(AM335X_PADCONF_BASE + AM335X_CONF_SPI0_CS0);
-bus->pinregs.mmode_scl = 2;
 break;
   case AM335X_I2C2_BASE:
 bus->clkregs.ctrl_clkctrl = ®(AM335X_SOC_CM_WKUP_REGS +
@@ -99,24 +89,12 @@ static int am335x_i2c_fill_registers(
 bus->clkregs.i2c_clkctrl = ®(AM335X_CM_PER_ADDR +
  AM335X_CM_PER_I2C2_CLKCTRL);
 bus->clkregs.clkstctrl = NULL;
-bus->pinregs.conf_sda = ®(AM335X_PADCONF_BASE + AM335X_CONF_UART1_CTSN);
-bus->pinregs.mmode_sda = 3;
-bus->pinregs.conf_scl = ®(AM335X_PADCONF_BASE + AM335X_CONF_UART1_RTSN);
-bus->pinregs.mmode_scl = 3;
 break;
   default:
 return EINVAL;
   }
-  return 0;
-}
-
-static void am335x_i2c_pinmux( bbb_i2c_bus *bus )
-{
-  *bus->pinregs.conf_sda =
-( BBB_RXACTIVE | BBB_SLEWCTRL | bus->pinregs.mmode_sda);
 
-  *bus->pinregs.conf_scl =
-( BBB_RXACTIVE | BBB_SLEWCTRL | bus->pinregs.mmode_scl);
+  return 0;
 }
 
 static void am335x_i2c_module_clk_enable( bbb_i2c_bus *bus )
@@ -453,36 +431,34 @@ static void am335x_i2c_destroy( i2c_bus *base )
   i2c_bus_destroy_and_free( &bus->base );
 }
 
-int am335x_i2c_bus_register(
-  const char *bus_path,
-  uintptr_t   register_base,
-  uint32_tinput_clock,
-  rtems_vector_number irq
+static int am335x_i2c_bus_register(
+  uint32_t reg_base,
+  rtems_vector_number irq,
+  const char *bus_path
 )
 {
-  bbb_i2c_bus  *bus;
-  rtems_status_code sc;
-  int   err;
-
-  (void) input_clock; /* FIXME: Unused. Left for compatibility. */
+  bbb_i2c_bus*bus;
+  rtems_status_code   sc;
+  int err;
 
   bus = (bbb_i2c_bus *) i2c_bus_alloc_and_init( sizeof( *bus ) );
+  bus->irq = irq;
 
   if ( bus == NULL ) {
 return -1;
   }
 
-  bus->irq = irq;
-
-  err = am335x_i2c_fill_registers(bus, register_base);
+  err = am335x_i2c_fill_registers(bus, reg_base);
   if (err != 0) {
+printf("i2c: invalid register base\n");
 ( *bus->base.destroy )( &bus->base );
 rtems_set_errno_and_return_minus_one( err );
   }
-  am335x_i2c_module_clk_enable(bus);
-  am335x_

[PATCH libBSD] iicbus/rtems-i2c.c: Add rtems, path as an additional bus path

2021-04-18 Thread G S Niteesh Babu
Adds "rtems,path" as an additional bus path for the i2c driver.
Previously the bus path was provided in "rtems,i2c-path" property
only.
---
 rtemsbsd/sys/dev/iicbus/rtems-i2c.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/rtemsbsd/sys/dev/iicbus/rtems-i2c.c 
b/rtemsbsd/sys/dev/iicbus/rtems-i2c.c
index b965f248..7ac7a7c4 100644
--- a/rtemsbsd/sys/dev/iicbus/rtems-i2c.c
+++ b/rtemsbsd/sys/dev/iicbus/rtems-i2c.c
@@ -87,9 +87,12 @@ rtems_i2c_attach(device_t dev)
 
len = OF_getprop_alloc(node, "rtems,i2c-path", &sc->path);
if (len == -1){
-   device_printf(sc->dev, "Path not found in Device Tree");
-   OF_prop_free(sc->path);
-   return (ENXIO);
+   len = OF_getprop_alloc(node, "rtems,path", &sc->path);
+   if (len == -1) {
+   device_printf(sc->dev, "Path not found in Device Tree");
+   OF_prop_free(sc->path);
+   return (ENXIO);
+   }
}
 
if ((sc->sc_iicbus = device_add_child(sc->dev, "iicbus", -1)) == NULL) {
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH libBSD v2] iicbus/rtems-i2c.c: Add rtems, path as an additional bus path

2021-04-19 Thread G S Niteesh Babu
Adds "rtems,path" as an additional bus path for the i2c driver.
Previously the bus path was provided in "rtems,i2c-path" property
only.
---
 rtemsbsd/sys/dev/iicbus/rtems-i2c.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/rtemsbsd/sys/dev/iicbus/rtems-i2c.c 
b/rtemsbsd/sys/dev/iicbus/rtems-i2c.c
index b965f248..0fb14d1a 100644
--- a/rtemsbsd/sys/dev/iicbus/rtems-i2c.c
+++ b/rtemsbsd/sys/dev/iicbus/rtems-i2c.c
@@ -87,9 +87,11 @@ rtems_i2c_attach(device_t dev)
 
len = OF_getprop_alloc(node, "rtems,i2c-path", &sc->path);
if (len == -1){
-   device_printf(sc->dev, "Path not found in Device Tree");
-   OF_prop_free(sc->path);
-   return (ENXIO);
+   len = OF_getprop_alloc(node, "rtems,path", &sc->path);
+   if (len == -1) {
+   device_printf(sc->dev, "Path not found in Device Tree");
+   return (ENXIO);
+   }
}
 
if ((sc->sc_iicbus = device_add_child(sc->dev, "iicbus", -1)) == NULL) {
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] bsps/shared/ofw: Fix coverity defects

2021-04-28 Thread G S Niteesh Babu
This patch adds asserts to fix coverity defects
1) CID 1474437 (Out-of-bounds access)
2) CID 1474436 (Out-of-bounds access)

>From manual inspection, out of bounds access cannot occur due to
bounds checking but coverity fails to detect the checks.
We are adding asserts as a secondary check.
---
 bsps/shared/ofw/ofw.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index f4b8b63931..808fa85d81 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -42,6 +42,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static void *fdtp = NULL;
 
@@ -186,6 +187,7 @@ ssize_t rtems_ofw_get_prop(
   const void *prop;
   int offset;
   int len;
+  int copy_len;
   uint32_t cpuid;
 
   offset = rtems_fdt_phandle_to_offset(node);
@@ -226,7 +228,9 @@ ssize_t rtems_ofw_get_prop(
 return -1;
   }
 
-  bcopy(prop, buf, MIN(len, bufsize));
+  copy_len = MIN(len, bufsize);
+  _Assert(copy_len <= bufsize);
+  memmove(prop, buf, copy_len);
 
   return len;
 }
@@ -637,6 +641,12 @@ int rtems_ofw_get_reg(
 range.child_bus = fdt32_to_cpu(ptr[j].child_bus);
 range.size = fdt32_to_cpu(ptr[j].size);
 
+/*
+ * buf[i + 1] should upperbound the access for buf[i].
+ * Thus by making sure buf[i + 1] <= (buf + size) we
+ * can be sure buf[i] will always be inbounds.
+ */
+_Assert(buf[i + 1] <= (buf + size));
 if (buf[i].start >= range.child_bus &&
 buf[i].start < range.child_bus + range.size) {
   offset = range.parent_bus - range.child_bus;
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v2] bsps/shared/ofw: Fix coverity defects

2021-05-01 Thread G S Niteesh Babu
This patch adds asserts to fix coverity defects
1) CID 1474437 (Out-of-bounds access)
2) CID 1474436 (Out-of-bounds access)

>From manual inspection, out of bounds access cannot occur due to
bounds checking but coverity fails to detect the checks.
We are adding asserts as a secondary check.
---
 bsps/shared/ofw/ofw.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index f4b8b63931..0e0a7033ab 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -42,6 +42,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static void *fdtp = NULL;
 
@@ -186,6 +187,7 @@ ssize_t rtems_ofw_get_prop(
   const void *prop;
   int offset;
   int len;
+  int copy_len;
   uint32_t cpuid;
 
   offset = rtems_fdt_phandle_to_offset(node);
@@ -226,7 +228,9 @@ ssize_t rtems_ofw_get_prop(
 return -1;
   }
 
-  bcopy(prop, buf, MIN(len, bufsize));
+  copy_len = MIN(len, bufsize);
+  _Assert(copy_len <= bufsize);
+  memmove(prop, buf, copy_len);
 
   return len;
 }
@@ -637,6 +641,12 @@ int rtems_ofw_get_reg(
 range.child_bus = fdt32_to_cpu(ptr[j].child_bus);
 range.size = fdt32_to_cpu(ptr[j].size);
 
+/**
+ * (buf + size - (sizeof(buf[0]) - 1) is the last valid
+ * address for buf[i]. If buf[i] points to any address larger
+ * than this, it will be an out of bound access
+ */
+_Assert(&buf[i] < (buf + size - (sizeof(buf[0]) - 1)));
 if (buf[i].start >= range.child_bus &&
 buf[i].start < range.child_bus + range.size) {
   offset = range.parent_bus - range.child_bus;
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] bsps/raspberrypi/console: Fix default console device

2021-05-01 Thread G S Niteesh Babu
When no console argument is given, the driver defaults to pl011
this results in no output in case of Rpi3 whose primary uart is
miniuart.
This patch fixes that by defaulting to the primary uart when no
console option is provided.
---
 bsps/arm/raspberrypi/console/console-config.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/bsps/arm/raspberrypi/console/console-config.c 
b/bsps/arm/raspberrypi/console/console-config.c
index 6b8eb80aa4..bd3a8d34c2 100644
--- a/bsps/arm/raspberrypi/console/console-config.c
+++ b/bsps/arm/raspberrypi/console/console-config.c
@@ -165,10 +165,16 @@ static void console_select( void )
 }
   }else {
 /**
- * If no command line option was given, default to PL011.
+ * If no console option was given we default to the primary uarts.
+ * The initialization of the uart's and BSP_output_char is already done
+ * in the uart_probe function called before this. So now we can safely
+ * compare BSP_output_char.
  */
-BSP_output_char = output_char_pl011;
-link(PL011, CONSOLE_DEVICE_NAME);
+if (BSP_output_char == output_char_pl011) {
+  link(PL011, CONSOLE_DEVICE_NAME);
+}else {
+  link(MINIUART, CONSOLE_DEVICE_NAME);
+}
   }
 }
 
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v3] bsps/shared/ofw: Fix coverity defects

2021-05-06 Thread G S Niteesh Babu
This patch adds asserts to fix coverity defects
1) CID 1474437 (Out-of-bounds access)
2) CID 1474436 (Out-of-bounds access)

>From manual inspection, out of bounds access cannot occur due to
bounds checking but coverity fails to detect the checks.
We are adding asserts as a secondary check.
---
 bsps/shared/ofw/ofw.c | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index f4b8b63931..f7638b98ef 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -42,6 +42,7 @@
 #include 
 #include 
 #include 
+#include 
 
 static void *fdtp = NULL;
 
@@ -186,6 +187,7 @@ ssize_t rtems_ofw_get_prop(
   const void *prop;
   int offset;
   int len;
+  int copy_len;
   uint32_t cpuid;
 
   offset = rtems_fdt_phandle_to_offset(node);
@@ -226,7 +228,9 @@ ssize_t rtems_ofw_get_prop(
 return -1;
   }
 
-  bcopy(prop, buf, MIN(len, bufsize));
+  copy_len = MIN(len, bufsize);
+  _Assert(copy_len <= bufsize);
+  memmove(buf, prop, copy_len);
 
   return len;
 }
@@ -637,6 +641,12 @@ int rtems_ofw_get_reg(
 range.child_bus = fdt32_to_cpu(ptr[j].child_bus);
 range.size = fdt32_to_cpu(ptr[j].size);
 
+/**
+ * (buf + size - (sizeof(buf[0]) - 1) is the last valid
+ * address for buf[i]. If buf[i] points to any address larger
+ * than this, it will be an out of bound access
+ */
+_Assert(&buf[i] < (buf + size - (sizeof(buf[0]) - 1)));
 if (buf[i].start >= range.child_bus &&
 buf[i].start < range.child_bus + range.size) {
   offset = range.parent_bus - range.child_bus;
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] bsp/beagle: Update console to new Termios device API.

2020-03-15 Thread G S Niteesh Babu
This patch updates the console to use new Termios device API.
Update #3034
---
 bsps/arm/beagle/console/console-config.c | 66 +++-
 1 file changed, 41 insertions(+), 25 deletions(-)

diff --git a/bsps/arm/beagle/console/console-config.c 
b/bsps/arm/beagle/console/console-config.c
index 78af5f6a93..860a44cb00 100644
--- a/bsps/arm/beagle/console/console-config.c
+++ b/bsps/arm/beagle/console/console-config.c
@@ -41,6 +41,8 @@
 #define TX_FIFO_E (1<<5)
 #define RX_FIFO_E (1<<0)
 
+#define UART0 "/dev/ttyS0"
+
 static uint8_t beagle_uart_get_register(uintptr_t addr, uint8_t i)
 {
   uint8_t v;
@@ -65,34 +67,27 @@ static void beagle_uart_set_register(uintptr_t addr, 
uint8_t i, uint8_t val)
   reg [i] = val;
 }
 
-console_tbl Console_Configuration_Ports [] = {
-{
-  .sDeviceName = "/dev/ttyS0",
-  .deviceType = SERIAL_NS16550,
-#if CONSOLE_POLLED /* option to facilitate running the tests */
-  .pDeviceFns = &ns16550_fns_polled,
-#else
-  .pDeviceFns = &ns16550_fns,
-#endif
-  .ulMargin = 16,
-  .ulHysteresis = 8,
-  .pDeviceParams = (void *) CONSOLE_BAUD,
-  .ulCtrlPort1 = BSP_CONSOLE_UART_BASE,
-  .ulDataPort = BSP_CONSOLE_UART_BASE,
-  .ulIntVector = BSP_CONSOLE_UART_IRQ,
-  .getRegister = beagle_uart_get_register,
-  .setRegister = beagle_uart_set_register,
-  .ulClock = UART_CLOCK,  /* 48MHz base clock */
-},
-};
-
-unsigned long Console_Configuration_Count = 1;
+ns16550_context uart_context;
 
 static int init_needed = 1; // don't rely on bss being 0
 
 static void beagle_console_init(void)
 {
   if(init_needed) {
+ns16550_context *ctx;
+
+/*
+   *  Don't rely on BSS being 0
+*/
+memset(&uart_context, 0, sizeof(uart_context));
+ctx = &uart_context;
+
+ctx->port = BSP_CONSOLE_UART_BASE;
+ctx->get_reg = beagle_uart_get_register;
+ctx->set_reg = beagle_uart_set_register;
+ctx->clock = UART_CLOCK;
+ctx->initial_baud = CONSOLE_BAUD;
+
 const uint32_t div = UART_CLOCK / 16 / CONSOLE_BAUD;
 CONSOLE_SYSC = 2;
 while ((CONSOLE_SYSS & 1) == 0)
@@ -120,6 +115,8 @@ static void beagle_console_init(void)
 CONSOLE_LCR = 0x03;
 CONSOLE_ACR = 0x00;
 init_needed = 0;
+
+BSP_output_char = uart_write_polled;
   }
 }
 
@@ -127,15 +124,17 @@ static void beagle_console_init(void)
 
 static void uart_write_polled( char c )
 {
-  if(init_needed) beagle_console_init();
-
   while( ( CONSOLE_LSR & TX_FIFO_E ) == 0 )
 ;
   CONSOLE_THR8 = c;
 }
 
 static void _BSP_put_char( char c ) {
-   uart_write_polled( c );
+
+  if ( init_needed ) {
+beagle_console_init();
+  }
+  uart_write_polled( c );
 }
 
 static int _BSP_get_char(void)
@@ -147,6 +146,23 @@ static int _BSP_get_char(void)
   }
 }
 
+rtems_status_code console_initialize(
+  rtems_device_major_number major,
+  rtems_device_minor_number minor,
+  void *arg
+)
+{
+  rtems_termios_initialize();
+  rtems_termios_device_install(
+UART0,
+&ns16550_handler_polled,
+NULL,
+&uart_context.base
+  );
+
+  return RTEMS_SUCCESSFUL;
+}
+
 BSP_output_char_function_type BSP_output_char = _BSP_put_char;
 
 BSP_polling_getchar_function_type BSP_poll_char = _BSP_get_char;
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v2] bsp/beagle: Update console to new Termios device API.

2020-03-15 Thread G S Niteesh Babu
This patch updates the console to use new Termios device API.
Update #3034
---
 bsps/arm/beagle/console/console-config.c | 66 +++-
 1 file changed, 41 insertions(+), 25 deletions(-)

diff --git a/bsps/arm/beagle/console/console-config.c 
b/bsps/arm/beagle/console/console-config.c
index 78af5f6a93..860a44cb00 100644
--- a/bsps/arm/beagle/console/console-config.c
+++ b/bsps/arm/beagle/console/console-config.c
@@ -41,6 +41,8 @@
 #define TX_FIFO_E (1<<5)
 #define RX_FIFO_E (1<<0)
 
+#define UART0 "/dev/ttyS0"
+
 static uint8_t beagle_uart_get_register(uintptr_t addr, uint8_t i)
 {
   uint8_t v;
@@ -65,34 +67,27 @@ static void beagle_uart_set_register(uintptr_t addr, 
uint8_t i, uint8_t val)
   reg [i] = val;
 }
 
-console_tbl Console_Configuration_Ports [] = {
-{
-  .sDeviceName = "/dev/ttyS0",
-  .deviceType = SERIAL_NS16550,
-#if CONSOLE_POLLED /* option to facilitate running the tests */
-  .pDeviceFns = &ns16550_fns_polled,
-#else
-  .pDeviceFns = &ns16550_fns,
-#endif
-  .ulMargin = 16,
-  .ulHysteresis = 8,
-  .pDeviceParams = (void *) CONSOLE_BAUD,
-  .ulCtrlPort1 = BSP_CONSOLE_UART_BASE,
-  .ulDataPort = BSP_CONSOLE_UART_BASE,
-  .ulIntVector = BSP_CONSOLE_UART_IRQ,
-  .getRegister = beagle_uart_get_register,
-  .setRegister = beagle_uart_set_register,
-  .ulClock = UART_CLOCK,  /* 48MHz base clock */
-},
-};
-
-unsigned long Console_Configuration_Count = 1;
+ns16550_context uart_context;
 
 static int init_needed = 1; // don't rely on bss being 0
 
 static void beagle_console_init(void)
 {
   if(init_needed) {
+ns16550_context *ctx;
+
+/*
+   *  Don't rely on BSS being 0
+*/
+memset(&uart_context, 0, sizeof(uart_context));
+ctx = &uart_context;
+
+ctx->port = BSP_CONSOLE_UART_BASE;
+ctx->get_reg = beagle_uart_get_register;
+ctx->set_reg = beagle_uart_set_register;
+ctx->clock = UART_CLOCK;
+ctx->initial_baud = CONSOLE_BAUD;
+
 const uint32_t div = UART_CLOCK / 16 / CONSOLE_BAUD;
 CONSOLE_SYSC = 2;
 while ((CONSOLE_SYSS & 1) == 0)
@@ -120,6 +115,8 @@ static void beagle_console_init(void)
 CONSOLE_LCR = 0x03;
 CONSOLE_ACR = 0x00;
 init_needed = 0;
+
+BSP_output_char = uart_write_polled;
   }
 }
 
@@ -127,15 +124,17 @@ static void beagle_console_init(void)
 
 static void uart_write_polled( char c )
 {
-  if(init_needed) beagle_console_init();
-
   while( ( CONSOLE_LSR & TX_FIFO_E ) == 0 )
 ;
   CONSOLE_THR8 = c;
 }
 
 static void _BSP_put_char( char c ) {
-   uart_write_polled( c );
+
+  if ( init_needed ) {
+beagle_console_init();
+  }
+  uart_write_polled( c );
 }
 
 static int _BSP_get_char(void)
@@ -147,6 +146,23 @@ static int _BSP_get_char(void)
   }
 }
 
+rtems_status_code console_initialize(
+  rtems_device_major_number major,
+  rtems_device_minor_number minor,
+  void *arg
+)
+{
+  rtems_termios_initialize();
+  rtems_termios_device_install(
+UART0,
+&ns16550_handler_polled,
+NULL,
+&uart_context.base
+  );
+
+  return RTEMS_SUCCESSFUL;
+}
+
 BSP_output_char_function_type BSP_output_char = _BSP_put_char;
 
 BSP_polling_getchar_function_type BSP_poll_char = _BSP_get_char;
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH rtems-docs] user/raspberrypi: Fix typo

2020-03-16 Thread G S Niteesh Babu
enable-uart should be enable_uart in config.txt
---
 user/bsps/arm/raspberrypi.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/user/bsps/arm/raspberrypi.rst b/user/bsps/arm/raspberrypi.rst
index 72889a5..c26f4b5 100644
--- a/user/bsps/arm/raspberrypi.rst
+++ b/user/bsps/arm/raspberrypi.rst
@@ -46,7 +46,7 @@ Make sure you have these lines below, in your ``config.txt``.
 
 .. code-block:: none
 
- enable-uart=1
+ enable_uart=1
  kernel_address=0x20
  kernel=kernel.img
 
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] user/gsoc: GSoC Getting Started Instructions

2020-03-17 Thread G S Niteesh Babu
---
 user/index.rst   |   1 +
 user/start/gsoc.rst  | 453 +++
 user/start/index.rst |   1 +
 3 files changed, 455 insertions(+)
 create mode 100644 user/start/gsoc.rst

diff --git a/user/index.rst b/user/index.rst
index 0e644c9..f253ea6 100644
--- a/user/index.rst
+++ b/user/index.rst
@@ -10,6 +10,7 @@ RTEMS User Manual (|version|).
 
 .. topic:: Copyrights and License
 
+| |copy| 2020 Niteesh Babu
 | |copy| 2019 Vijay Kumar Banerjee
 | |copy| 2018 Amaan Cheval
 | |copy| 2018 Marçal Comajoan Cara
diff --git a/user/start/gsoc.rst b/user/start/gsoc.rst
new file mode 100644
index 000..071c1cc
--- /dev/null
+++ b/user/start/gsoc.rst
@@ -0,0 +1,453 @@
+.. comment: SPDX-License-Identifier: CC-BY-SA-4.0
+
+.. comment: Copyright (C) 2020 Niteesh Babu 
+.. comment: All rights reserved.
+
+
+.. _QuickStartGSoC:
+
+GSoC Getting Started
+
+
+The goal of this page is to help you get RTEMS compiled and running so you can
+start with the real work.
+
+Please join the :r:list:`users` and :r:list:`devel` mailing lists and ask 
questions.
+Help correct any deficiencies in the code or documentation you spot, including
+those on the wiki. The ultimate goal of GSoC is to help you become part of the
+open source community.
+
+.. _QuickStartConfigureComputer:
+
+Configure a Development Computer
+
+
+You will be best served by using a GNU/Linux environment, which could be in a
+virtual machine, for example that uses `​Virtualbox 
`_
+and should run on most modern desktop systems. You should also be able to work
+with a MacOS or Windows system, but might encounter more difficulty than a *nix
+environment.
+
+Feel free to ask questions on the rtems-users mailing list in case you face
+trouble with the steps. If you want tools for another architecture, replace
+sparc in the RSB directions with another architecture, such as arm or mips. You
+can also use the RSB to build RTEMS directly, but we recommend that you learn
+how to build RTEMS by itself with the compiler tools generated by RSB.
+
+As you will be compiling a lot of code, it is recommended to have a reasonably
+fast development machine.
+
+The instructions in this chapter will help you in quickly setting up a
+development environment. For a detailed set of instruction please refer to the
+:ref:`QuickStart` chapter.
+
+You need tools for your host’s operating system to build the RTEMS tool suite
+from source. Please have a look at the :ref:`host-computer` chapter for the
+instructions to install the tools.
+
+Choosing an Installation Prefix
+---
+
+The term ``prefix`` refers to the path on your computer where the software is 
to
+be installed.
+In this case, we choose the home directory ``$HOME/rtems`` as our prefix.
+
+.. code-block:: none
+
+  mkdir $HOME/rtems
+
+Getting Sources
+---
+
+We obtain the source code for the :ref:`RTEMS Source Builder (RSB) ` and
+RTEMS from the RTEMS :r:url:`git`.
+
+The :ref:`RTEMS Source Builder (RSB) ` is the tool used to build RTEMS
+packages from source. We will be using the RSB to build RTEMS the source.
+Please have a look at the :ref:`RTEMS Source Builder (RSB) ` for more
+information.
+
+We'll clone to the repositories to ``$HOME/rtems/src``.
+
+.. code-block:: none
+
+  mkdir -p $HOME/rtems/src
+  cd $HOME/rtems/src
+  git clone git://git.rtems.org/rtems-source-builder.git rsb
+  git clone git://git.rtems.org/rtems.git
+
+Building the Tool suite
+---
+
+Once you have cloned the repositories and installed the required tools for
+your host operating system. You can start building the tools suite for your 
BSP.
+The tools suite is the collection of compiler, debugger, Assembler and other
+tools required for developing the software.
+
+You can check if your host is set up correctly using ``sb-check`` tool provided
+in the RSB repository.
+
+.. code-block:: none
+
+  cd $HOME/rtems/src/rsb/source-builder
+  ./sb-check
+
+If you installed all the required tools you should have the following output.
+
+.. code-block:: none
+
+  RTEMS Source Builder - Check, 5 (0b7e87143b76)
+  Environment is ok
+
+.. note:: The numbers may vary depending on the RSB release.
+
+The tool suite for RTEMS and the RTEMS sources are tightly coupled. For 
example,
+do not use a RTEMS version 5 tool suite with RTEMS version 4.11 sources and 
vice
+versa. In simple words, make sure you clone both the repositories at the same
+time.
+
+The tools suite is architecture specific. In this guide we will be building the
+tools suite for the SPARC architecture. So the tool suite name is sparc-rtems5.
+You can build the tools suite for other architectures like ARM, RISCV by
+replacing the architecture name. For example, for ARM the tools suite name 
would
+be arm-rtems5.
+
+The following command builds and installs the tools suite in the path mentioned
+in the prefix option

[PATCH docs] user/bsps: Remove gdbarmsim

2020-03-19 Thread G S Niteesh Babu
Remove gdbarmsim from list of BSPs in docs. Since, the BSPs has
been removed from RTEMS by Joel.
---
 user/bsps/arm/gdbarmsim.rst | 8 
 1 file changed, 8 deletions(-)
 delete mode 100644 user/bsps/arm/gdbarmsim.rst

diff --git a/user/bsps/arm/gdbarmsim.rst b/user/bsps/arm/gdbarmsim.rst
deleted file mode 100644
index 26ea90c..000
--- a/user/bsps/arm/gdbarmsim.rst
+++ /dev/null
@@ -1,8 +0,0 @@
-.. SPDX-License-Identifier: CC-BY-SA-4.0
-
-.. Copyright (C) 2019 TBD
-
-gdbarmsim
-=
-
-TODO.
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v3] bsp/beagle: Update console to new Termios API.

2020-03-23 Thread G S Niteesh Babu
This patch updates the console driver to new Termios API.

Update #3034
---
 bsps/arm/beagle/console/console-config.c | 117 +--
 c/src/lib/libbsp/arm/beagle/Makefile.am  |   4 +-
 2 files changed, 69 insertions(+), 52 deletions(-)

diff --git a/bsps/arm/beagle/console/console-config.c 
b/bsps/arm/beagle/console/console-config.c
index 78af5f6a93..b2246571f8 100644
--- a/bsps/arm/beagle/console/console-config.c
+++ b/bsps/arm/beagle/console/console-config.c
@@ -21,12 +21,15 @@
  *
  * Modified by Ben Gras  to make
  * interrupt-driven uart i/o work for beagleboards; beaglebone support added.
+ *
+ * Modified by Niteesh Babu G S 
+ * Update console to new termios API.
  */
 
-#include 
 #include 
 
 #include 
+#include 
 
 #include 
 #include 
@@ -41,6 +44,8 @@
 #define TX_FIFO_E (1<<5)
 #define RX_FIFO_E (1<<0)
 
+#define BEAGLE_UART0 "/dev/ttyS0"
+
 static uint8_t beagle_uart_get_register(uintptr_t addr, uint8_t i)
 {
   uint8_t v;
@@ -65,77 +70,91 @@ static void beagle_uart_set_register(uintptr_t addr, 
uint8_t i, uint8_t val)
   reg [i] = val;
 }
 
-console_tbl Console_Configuration_Ports [] = {
-{
-  .sDeviceName = "/dev/ttyS0",
-  .deviceType = SERIAL_NS16550,
-#if CONSOLE_POLLED /* option to facilitate running the tests */
-  .pDeviceFns = &ns16550_fns_polled,
-#else
-  .pDeviceFns = &ns16550_fns,
-#endif
-  .ulMargin = 16,
-  .ulHysteresis = 8,
-  .pDeviceParams = (void *) CONSOLE_BAUD,
-  .ulCtrlPort1 = BSP_CONSOLE_UART_BASE,
-  .ulDataPort = BSP_CONSOLE_UART_BASE,
-  .ulIntVector = BSP_CONSOLE_UART_IRQ,
-  .getRegister = beagle_uart_get_register,
-  .setRegister = beagle_uart_set_register,
-  .ulClock = UART_CLOCK,  /* 48MHz base clock */
-},
-};
-
-unsigned long Console_Configuration_Count = 1;
-
-static int init_needed = 1; // don't rely on bss being 0
+static ns16550_context uart_context;
+static void uart_write_polled( char c );
 
 static void beagle_console_init(void)
 {
-  if(init_needed) {
-const uint32_t div = UART_CLOCK / 16 / CONSOLE_BAUD;
-CONSOLE_SYSC = 2;
-while ((CONSOLE_SYSS & 1) == 0)
-  ;
-if ((CONSOLE_LSR & (CONSOLE_LSR_THRE | CONSOLE_LSR_TEMT)) == 
CONSOLE_LSR_THRE) {
-  CONSOLE_LCR = 0x83;
-  CONSOLE_DLL = div;
-  CONSOLE_DLM = (div >> 8) & 0xff;
-  CONSOLE_LCR = 0x03;
-  CONSOLE_ACR = 0x00;
-}
+  ns16550_context *ctx;
+  static bool initialized = false;
 
-while ((CONSOLE_LSR & CONSOLE_LSR_TEMT) == 0)
-  ;
+  if ( initialized ) {
+return ;
+  }
 
-CONSOLE_LCR = 0x80 | 0x03;
-CONSOLE_DLL = 0x00;
-CONSOLE_DLM = 0x00;
-CONSOLE_LCR = 0x03;
-CONSOLE_MCR = 0x03;
-CONSOLE_FCR = 0x07;
+  /*
+   * Don't rely on BSS being zeroed
+   */
+  memset(&uart_context, 0, sizeof(uart_context));
+  ctx = &uart_context;
+
+  ctx->port = BSP_CONSOLE_UART_BASE;
+  ctx->irq = BSP_CONSOLE_UART_IRQ;
+  ctx->set_reg = beagle_uart_set_register;
+  ctx->get_reg = beagle_uart_get_register;
+  ctx->initial_baud = CONSOLE_BAUD;
+  ctx->clock = UART_CLOCK;
+
+  const uint32_t div = UART_CLOCK / 16 / CONSOLE_BAUD;
+  CONSOLE_SYSC = 2;
+  while ((CONSOLE_SYSS & 1) == 0)
+;
+  if ((CONSOLE_LSR & (CONSOLE_LSR_THRE | CONSOLE_LSR_TEMT)) == 
CONSOLE_LSR_THRE) {
 CONSOLE_LCR = 0x83;
 CONSOLE_DLL = div;
 CONSOLE_DLM = (div >> 8) & 0xff;
 CONSOLE_LCR = 0x03;
 CONSOLE_ACR = 0x00;
-init_needed = 0;
   }
+  while ((CONSOLE_LSR & CONSOLE_LSR_TEMT) == 0)
+;
+  CONSOLE_LCR = 0x80 | 0x03;
+  CONSOLE_DLL = 0x00;
+  CONSOLE_DLM = 0x00;
+  CONSOLE_LCR = 0x03;
+  CONSOLE_MCR = 0x03;
+  CONSOLE_FCR = 0x07;
+  CONSOLE_LCR = 0x83;
+  CONSOLE_DLL = div;
+  CONSOLE_DLM = (div >> 8) & 0xff;
+  CONSOLE_LCR = 0x03;
+  CONSOLE_ACR = 0x00;
+
+  BSP_output_char = uart_write_polled;
 }
 
 #define CONSOLE_THR8 (*(volatile uint8_t *) (BSP_CONSOLE_UART_BASE + 0x00))
 
 static void uart_write_polled( char c )
 {
-  if(init_needed) beagle_console_init();
-
   while( ( CONSOLE_LSR & TX_FIFO_E ) == 0 )
 ;
   CONSOLE_THR8 = c;
 }
 
+rtems_status_code console_initialize(
+  rtems_device_major_number major,
+  rtems_device_minor_number minor,
+  void *arg
+)
+{
+  rtems_termios_initialize();
+
+  beagle_console_init();
+
+  rtems_termios_device_install(
+BEAGLE_UART0,
+&ns16550_handler_polled,
+NULL,
+&uart_context.base
+  );
+
+  return RTEMS_SUCCESSFUL;
+}
+
 static void _BSP_put_char( char c ) {
-   uart_write_polled( c );
+  beagle_console_init();
+  uart_write_polled( c );
 }
 
 static int _BSP_get_char(void)
diff --git a/c/src/lib/libbsp/arm/beagle/Makefile.am 
b/c/src/lib/libbsp/arm/beagle/Makefile.am
index e37472373c..1cd9920b2f 100644
--- a/c/src/lib/libbsp/arm/beagle/Makefile.am
+++ b/c/src/lib/libbsp/arm/beagle/Makefile.am
@@ -62,9 +62,7 @@ librtemsbsp_a_SOURCES += 
../../../../../../bsps/shared/irq/irq-default-handler.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/arm/beagle/irq/irq.c
 
 # Console
-librtemsbsp_a_SOURCES += 
.

[PATCH 1/2] bsp/raspberrypi: Fix build warnings.

2020-03-28 Thread G S Niteesh Babu
1) _Memory_Initialize makes pointer from integer w
ithout a cast.
2) printf format error, expects %u but %lu provided.
---
 bsps/arm/raspberrypi/irq/irq.c | 2 +-
 bsps/arm/raspberrypi/start/bspstarthooks.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/bsps/arm/raspberrypi/irq/irq.c b/bsps/arm/raspberrypi/irq/irq.c
index 9e1bcfc1bc..73dcad298f 100644
--- a/bsps/arm/raspberrypi/irq/irq.c
+++ b/bsps/arm/raspberrypi/irq/irq.c
@@ -157,7 +157,7 @@ void bsp_interrupt_vector_disable(rtems_vector_number 
vector)
 
 void bsp_interrupt_handler_default(rtems_vector_number vector)
 {
-printk("spurious interrupt: %lu\n", vector);
+printk("spurious interrupt: %u\n", vector);
 }
 
 rtems_status_code bsp_interrupt_facility_initialize(void)
diff --git a/bsps/arm/raspberrypi/start/bspstarthooks.c 
b/bsps/arm/raspberrypi/start/bspstarthooks.c
index fd6aa53059..eb6546db1c 100644
--- a/bsps/arm/raspberrypi/start/bspstarthooks.c
+++ b/bsps/arm/raspberrypi/start/bspstarthooks.c
@@ -184,7 +184,9 @@ static void bsp_memory_initialize(void)
 {
   _Memory_Initialize(
 &_Memory_Areas[0],
+(void *)
 raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].begin,
+(void *)
 raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end
   );
 }
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 2/2] gpio/gpio-support: Fix build warnings.

2020-03-28 Thread G S Niteesh Babu
Fixes "array subscript is outside array bounds" in gpio-support.c
---
 bsps/shared/dev/gpio/gpio-support.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/bsps/shared/dev/gpio/gpio-support.c 
b/bsps/shared/dev/gpio/gpio-support.c
index 9c053dc151..04f1c8ca90 100644
--- a/bsps/shared/dev/gpio/gpio-support.c
+++ b/bsps/shared/dev/gpio/gpio-support.c
@@ -325,6 +325,7 @@ static rtems_status_code get_pin_bitmask(
   ACQUIRE_LOCK(gpio_bank_state[bank].lock);
 }
 else if ( bank != *bank_number ) {
+  assert ( *bank_number >= 0 && *bank_number < GPIO_BANK_COUNT );
   RELEASE_LOCK(gpio_bank_state[*bank_number].lock);
 
   return RTEMS_UNSATISFIED;
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v2] bsp/raspberrypi: Fix build warnings.

2020-03-28 Thread G S Niteesh Babu
1) _Memory_Initialize makes pointer from integer
without a cast.
2) printf format error, expects %u but %lu provided.
---
 bsps/arm/raspberrypi/irq/irq.c | 4 +++-
 bsps/arm/raspberrypi/start/bspstarthooks.c | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/bsps/arm/raspberrypi/irq/irq.c b/bsps/arm/raspberrypi/irq/irq.c
index 9e1bcfc1bc..835cdf97d9 100644
--- a/bsps/arm/raspberrypi/irq/irq.c
+++ b/bsps/arm/raspberrypi/irq/irq.c
@@ -32,6 +32,8 @@
 #include 
 #include 
 
+#include 
+
 #ifdef RTEMS_SMP
 #include 
 #include 
@@ -157,7 +159,7 @@ void bsp_interrupt_vector_disable(rtems_vector_number 
vector)
 
 void bsp_interrupt_handler_default(rtems_vector_number vector)
 {
-printk("spurious interrupt: %lu\n", vector);
+printk("spurious interrupt: %" PRIdrtems_vector_number "\n", vector);
 }
 
 rtems_status_code bsp_interrupt_facility_initialize(void)
diff --git a/bsps/arm/raspberrypi/start/bspstarthooks.c 
b/bsps/arm/raspberrypi/start/bspstarthooks.c
index fd6aa53059..eb6546db1c 100644
--- a/bsps/arm/raspberrypi/start/bspstarthooks.c
+++ b/bsps/arm/raspberrypi/start/bspstarthooks.c
@@ -184,7 +184,9 @@ static void bsp_memory_initialize(void)
 {
   _Memory_Initialize(
 &_Memory_Areas[0],
+(void *)
 raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].begin,
+(void *)
 raspberrypi_mmu_config_table[ARMV7_CP15_START_WORKSPACE_ENTRY_INDEX].end
   );
 }
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH docs] user/bsp-build: Fix broken cross references.

2020-04-02 Thread G S Niteesh Babu
The QuickStartBSPBuild_Manual and QuickStartBSPBuild_RSB are
missing the underscore in front. This breaks any reference to
them from other sections.
---
 user/start/bsp-build.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/user/start/bsp-build.rst b/user/start/bsp-build.rst
index 33ecb29..59da2fd 100644
--- a/user/start/bsp-build.rst
+++ b/user/start/bsp-build.rst
@@ -29,7 +29,7 @@ use one of the listed methods to build the BSP.
 In the output in this section the base directory :file:`$HOME/quick-start` was
 replaced by ``$BASE``.
 
-.. QuickStartBSPBuild_RSB:
+.. _QuickStartBSPBuild_RSB:
 
 RSB BSP Build
 -
@@ -92,7 +92,7 @@ The RSB BSP build can be customised with following RSB 
command line options:
 If you have built a BSP with the RSB, you can move on to
 :ref:`QuickStartBSPTest`.
 
-.. QuickStartBSPBuild_Manual:
+.. _QuickStartBSPBuild_Manual:
 
 Manual BSP Build
 
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH docs] start/gsoc: GSoC Getting started instructions.

2020-04-02 Thread G S Niteesh Babu
Added instructions to setup development environment for students
interested in GSoC.
---
 user/index.rst   |   1 +
 user/start/gsoc.rst  | 132 +++
 user/start/index.rst |   1 +
 3 files changed, 134 insertions(+)
 create mode 100644 user/start/gsoc.rst

diff --git a/user/index.rst b/user/index.rst
index 7b584c5..4e91994 100644
--- a/user/index.rst
+++ b/user/index.rst
@@ -10,6 +10,7 @@ RTEMS User Manual (|version|).
 
 .. topic:: Copyrights and License
 
+| |copy| 2020 Niteesh Babu
 | |copy| 2019 Vijay Kumar Banerjee
 | |copy| 2018 Amaan Cheval
 | |copy| 2018 Marçal Comajoan Cara
diff --git a/user/start/gsoc.rst b/user/start/gsoc.rst
new file mode 100644
index 000..62154ff
--- /dev/null
+++ b/user/start/gsoc.rst
@@ -0,0 +1,132 @@
+.. SPDX-License-Identifier: CC-BY-SA-4.0
+
+.. Copyright (C) 2020 Niteesh Babu 
+
+.. _QuickStartGSoC:
+
+GSoC Getting Started
+
+
+The goal of this page is to help new users, especially students get RTEMS
+compiled and running so they can start with the real work.
+
+Please join the :r:list:`users` and :r:list:`devel` and ask
+questions. Help correct any deficiencies in the code or documentation you spot,
+including those on the wiki. The ultimate goal of GSoC is to help you become
+part of the open source community.
+
+This section will help you to quickly setup a development environment without
+delving into the details. For more information you can go through the other
+subsections under :ref:`Quick Start ` chapter or ask on the
+:r:list:`devel`.
+
+You will be best served by using a GNU/Linux environment, which could be in a
+virtual machine, for example that uses `​Virtualbox 
`_
+and should run on most modern desktop systems. You should also be able to work
+with a MacOS or Windows system, but might encounter more difficulty than a *nix
+environment.
+
+Setting up a development environment consists of the following steps.
+
+1) Installing dependencies for your host operating system.
+2) Choosing an installation prefix.
+3) Downloading the source code.
+4) Installing the tool suite.
+5) Building the Board Support Package (BSP).
+6) Testing the Board Support Package (BSP).
+
+Installing Dependencies
+---
+
+You need tools for your host’s operating system to build the RTEMS tool suite
+from source. Please have a look at the :ref:`host-computer` chapter for the
+instructions to install the tools for your OS.
+
+Choosing an installation prefix
+---
+
+The term ``prefix`` refers to the path on your computer where the software is 
to
+be installed.
+You can refer to the :ref:`Prefix ` section for details on
+choosing an installation prefix.
+
+Downloading the Sources
+---
+
+We will be using Git to clone the sources for RTEMS and RSB. This is the
+preferred way if you are planning to make contributions to the RTEMS project.
+
+Please refer to the :ref:`QuickStartSources_Git` section for instructions on
+obtaining sources using Git.
+
+Installing the Tool Suite
+-
+
+The Tools suite is the collection of tools required to build the BSP. This
+includes the compiler, debugger, assembler and other tools. These tools are
+architecture-specific. We will be installing the SPARC tool suite since we are
+building a SPARC based BSP.
+
+Please refer to the :ref:`QuickStartTools` section for instructions on
+building and installing the tool suite.
+
+Building the Board Support Package
+--
+
+There are two ways of building a BSP. We could either ask RSB to build the BSP
+or manually build it. In this section will we be building it manually.
+Please refer the :ref:`QuickStartBSPBuild_Manual` section for the
+instructions.
+
+Testing the Board Support Package
+-
+
+Testing is an essential part of RTEMS development process. The main reason for
+choosing the SPARC erc32 BSP is that, it has very good simulator support. This
+will allow you to test your changes without the need for SPARC hardware.
+
+Please refer to :ref:`QuickStartBSPTest` for instructions on testing the BSP.
+
+Prove You Can Work On RTEMS
+---
+
+This section is only for students interested in Google Summer of Code.
+
+You have to finish the following task to prove that you can work on RTEMS.
+
+Modify the hello world example to include a new different print statement.
+Something like "Hello from The Dark Side!". Then send us enough to prove to us
+that you did this. We want to know you can work with RTEMS.
+
+Create a patch of your changes and send it to :r:list:`devel` along with the
+screenshot of the output.
+
+If you followed this guide, this hello world modification will likely need to 
be
+made in ``$HOME/quick-start/src/rtems/testsuites/samples/hello/init.c``.
+To test your changes, you have to build the BSP again. This could be done b

[PATCH 0/2 rtems-release] Add script to branch repositories.

2020-05-01 Thread G S Niteesh Babu
The following patches add a script to rtems-release
to automate branching of repositories for rtems
release. 

G S Niteesh Babu (2):
  rtems-release-defaults: Added rtems_repos to rtems-release-defaults.
  rtems-release-branch: Added a script file to branch repositories.

 rtems-release-branch   | 146 +
 rtems-release-defaults |  11 
 2 files changed, 157 insertions(+)
 create mode 100755 rtems-release-branch

-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 2/2] rtems-release-branch: Added a script file to branch repositories.

2020-05-01 Thread G S Niteesh Babu
---
 rtems-release-branch | 146 +++
 1 file changed, 146 insertions(+)
 create mode 100755 rtems-release-branch

diff --git a/rtems-release-branch b/rtems-release-branch
new file mode 100755
index 000..ae8e06c
--- /dev/null
+++ b/rtems-release-branch
@@ -0,0 +1,146 @@
+#! /bin/sh
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2020 Niteesh Babu 
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+set -e
+
+#
+# This is the top level RTEMS release script. Supply the version and and the
+# release.
+#
+. ./rtems-release-version
+echo "RTEMS Release, v${rtems_release_version}"
+
+#
+# Global release top path.
+#
+export release_top=${PWD}
+
+#
+# Usage for this tool.
+#
+usage() {
+ echo "Usage: $0 [-t] [-p] user version" 1>&2
+ echo " where:" 1>&2
+ echo "  user : Your git user name" 1>&2
+ echo "  version  : The version of RTEMS, eg 5" 1>&2
+ echo "  -t   : Git protocol will be used for cloning (for testing)." 
1>&2
+ echo "  -p   : Push the changes." 1>&2
+ exit 1
+}
+
+#
+# Defaults.
+#
+. ${release_top}/rtems-release-defaults
+
+#
+# Option defaults
+#
+clone_url=
+push=no
+
+#
+# Manage the command line.
+#
+while getopts "tp" opt; do
+ case "${opt}" in
+  t)
+   clone_url=git://git.rtems.org
+   ;;
+  p)
+   push=yes
+   ;;
+  *)
+   usage
+   ;;
+ esac
+done
+shift $((OPTIND-1))
+
+if [ $# -ne 2 ]; then
+ echo "error: 2 arguments must be supplied, your git user name, version. See 
-h for help"
+ exit 1
+fi
+user=$1
+version=$2
+
+#
+# Check if clone_url is empty.
+#
+if [ -z "${clone_url}" ]; then
+ clone_url=ssh://${user}@dispatch.rtems.org/data/git
+fi
+
+#
+# The branching workspace.
+#
+ws_branch=${version}-branched
+
+#
+# Version configuration. Overrides defaults.
+#
+if [ -f rtems-release-${version}-conf ]; then
+ rtems_release_conf=rtems-release-${version}-conf
+ . rtems-release-${version}-conf
+fi
+
+#
+# Clean the branched directory away.
+#
+rm -rf ${ws_branch}
+mkdir ${ws_branch}
+
+#
+# Clone and branch the repositories.
+#
+cd ${ws_branch}
+ for r in ${rtems_repos}
+ do
+  echo "git clone ${clone_url}/${r} ${r}"
+  git clone ${clone_url}/${r} ${r}
+  cd ${r}
+   echo "git checkout -b ${version} origin/master"
+   git checkout -b ${version} origin/master
+   cd ..
+ done
+
+ if [ ${push} = yes ]; then
+  for r in ${rtems_repos}
+  do
+   cd ${r}
+echo "git push origin ${version}"
+git push origin ${version}
+cd ..
+  done
+ fi
+ cd ..
+
+exit 0
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 1/2] rtems-release-defaults: Added rtems_repos to rtems-release-defaults.

2020-05-01 Thread G S Niteesh Babu
rtems_repos is variable which contains all rtems_repositories.
For eg: rtems_repos="rtems.git rtems-examples.git etc."
---
 rtems-release-defaults | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/rtems-release-defaults b/rtems-release-defaults
index 60d9721..fc30157 100755
--- a/rtems-release-defaults
+++ b/rtems-release-defaults
@@ -74,6 +74,17 @@ rtems_rsb_hash="rtems-tools rtems"
 rtems_packages="rtems-source-builder rtems rtems-tools rtems-libbsd"
 rtems_packages="${rtems_packages} rtems-examples rtems-docs"
 
+#
+# RTEMS repositories
+#
+rtems_repos=""
+for r in ${rtems_packages}
+do
+  rtems_repos="${rtems_repos} "${r}.git
+done
+
+rtems_repos="${rtems_repos} rtems-release.git"
+
 #
 # Where we collect the sources and docs.
 #
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH rtems] libfreebsd: RTEMS to FreeBSD porting helper header

2020-05-27 Thread G S Niteesh Babu
This file serve the purpose as rtems-bsd-kernel-space.h in the
rtems-libbsd.
This file is intended to be included in every source file that
is to imported from FreeBSD. This is to reduce the number of
redefinitions for commonly used functions like malloc, free
and KASSERT.
---
 cpukit/libfreebsd/rtems-freebsd-helper.h | 44 
 1 file changed, 44 insertions(+)
 create mode 100644 cpukit/libfreebsd/rtems-freebsd-helper.h

diff --git a/cpukit/libfreebsd/rtems-freebsd-helper.h 
b/cpukit/libfreebsd/rtems-freebsd-helper.h
new file mode 100644
index 00..8135a1caf5
--- /dev/null
+++ b/cpukit/libfreebsd/rtems-freebsd-helper.h
@@ -0,0 +1,44 @@
+
+/* SPDX-License-Identifier: BSD-2-Clause
+
+ *
+ * @file
+ *
+ * @ingroup LIBFREEBSD
+ *
+ * @brief
+ */
+
+/*
+ * Copyright (C) <2020> Niteesh Babu 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H
+#define _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H
+
+#define KASSERT(cnd, msg)   assert(cnd)
+#define malloc(size, type, flags)   malloc(size)
+#define free(addr, type)free(addr)
+
+#endif /* _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H */
\ No newline at end of file
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 2/5] bsps/shared/freebsd: Added ofw_if.h

2020-05-28 Thread G S Niteesh Babu
This file is the RTEMS implementation of ofw_if.h in FreeBSD. The
ofw_if.h in FreeBSD is an autogenerated header file that maps the
OF_function calls to their respective implementation. But in RTEMS
this file maps the OF_functions directly to their FDT implementation.
---
 bsps/shared/freebsd/dev/ofw/ofw_if.h | 63 
 1 file changed, 63 insertions(+)
 create mode 100644 bsps/shared/freebsd/dev/ofw/ofw_if.h

diff --git a/bsps/shared/freebsd/dev/ofw/ofw_if.h 
b/bsps/shared/freebsd/dev/ofw/ofw_if.h
new file mode 100644
index 00..7b9bcaa24a
--- /dev/null
+++ b/bsps/shared/freebsd/dev/ofw/ofw_if.h
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: BSD-2-Clause
+
+ *
+ * @file
+ *
+ * @ingroup LIBFREEBSDOFW
+ *
+ * @brief Declaration of OFW functions.
+ */
+
+/*
+ * Copyright (C) <2020> Niteesh Babu 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LIBFREEBSD_OFW_IF_H
+#define _LIBFREEBSD_OFW_IF_H
+
+#include 
+#include "openfirm.h"
+
+typedef void*  ofw_t;
+
+int OFW_INIT(ofw_t ofw_obj, void *cookie);
+phandle_t OFW_PEER(ofw_t ofw_obj, phandle_t node);
+phandle_t OFW_CHILD(ofw_t ofw_obj, phandle_t node);
+phandle_t OFW_PARENT(ofw_t ofw_obj, phandle_t node);
+phandle_t OFW_INSTANCE_TO_PACKAGE(ofw_t ofw_obj, ihandle_t instance);
+ssize_t OFW_GETPROPLEN(ofw_t ofw_obj, phandle_t package, const char *propname);
+ssize_t OFW_GETPROP(ofw_t ofw_obj, phandle_t package, const char *propname,
+void *buf, size_t buflen);
+int OFW_NEXTPROP(ofw_t ofw_obj, phandle_t package, const char *prev, char *buf,
+size_t size);
+int OFW_SETPROP(ofw_t ofw_obj, phandle_t package, const char *propname,
+const void *buf, size_t len);
+ssize_t OFW_CANON(ofw_t ofw_obj, const char *device, char *buf, size_t len);
+phandle_t OFW_FINDDEVICE(ofw_t ofw_obj, const char *device);
+ssize_t OFW_INSTANCE_TO_PATH(ofw_t ofw_obj, ihandle_t instance, char *buf,
+size_t len);
+ssize_t OFW_PACKAGE_TO_PATH(ofw_t ofw_obj, phandle_t package, char *buf,
+size_t len);
+
+#endif /* _LIBFREEBSD_OFW_IF_H */
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 4/5] bsps/shared/freebsd: Port OFW to RTEMS

2020-05-28 Thread G S Niteesh Babu
The following files have been ported to RTEMS
1) openfirm.h
2) openfirm.c
3) ofw_fdt.c
---
 bsps/shared/freebsd/dev/ofw/ofw_fdt.c  | 116 -
 bsps/shared/freebsd/dev/ofw/openfirm.c |  59 -
 bsps/shared/freebsd/dev/ofw/openfirm.h |  18 
 3 files changed, 190 insertions(+), 3 deletions(-)

diff --git a/bsps/shared/freebsd/dev/ofw/ofw_fdt.c 
b/bsps/shared/freebsd/dev/ofw/ofw_fdt.c
index e4f72e8142..436da199d9 100644
--- a/bsps/shared/freebsd/dev/ofw/ofw_fdt.c
+++ b/bsps/shared/freebsd/dev/ofw/ofw_fdt.c
@@ -29,10 +29,13 @@
  * SUCH DAMAGE.
  */
 
+#ifndef __rtems__
 #include 
 __FBSDID("$FreeBSD$");
+#endif /* __rtems__ */
 
 #include 
+#ifndef __rtems__
 #include 
 #include 
 #include 
@@ -45,9 +48,19 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#endif /* __rtems__ */
 
 #include "ofw_if.h"
-
+#ifdef __rtems__
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "openfirm.h"
+#endif /* __rtems__ */
+
+#ifndef __rtems__
 #ifdef DEBUG
 #define debugf(fmt, args...) do { printf("%s(): ", __func__);  \
 printf(fmt,##args); } while (0)
@@ -63,6 +76,7 @@ __FBSDID("$FreeBSD$");
 #define FDT_MARVELL
 #endif
 #endif
+#endif /* __rtems__ */
 
 static int ofw_fdt_init(ofw_t, void *);
 static phandle_t ofw_fdt_peer(ofw_t, phandle_t);
@@ -78,6 +92,7 @@ static ssize_t ofw_fdt_canon(ofw_t, const char *, char *, 
size_t);
 static phandle_t ofw_fdt_finddevice(ofw_t, const char *);
 static ssize_t ofw_fdt_instance_to_path(ofw_t, ihandle_t, char *, size_t);
 static ssize_t ofw_fdt_package_to_path(ofw_t, phandle_t, char *, size_t);
+#ifndef __rtems__
 static int ofw_fdt_interpret(ofw_t, const char *, int, cell_t *);
 
 static ofw_method_t ofw_fdt_methods[] = {
@@ -104,9 +119,11 @@ static ofw_def_t ofw_fdt = {
0
 };
 OFW_DEF(ofw_fdt);
+#endif /* __rtems__ */
 
 static void *fdtp = NULL;
 
+#ifndef __rtems__
 static int
 sysctl_handle_dtb(SYSCTL_HANDLER_ARGS)
 {
@@ -127,6 +144,22 @@ sysctl_register_fdt_oid(void *arg)
sysctl_handle_dtb, "", "Device Tree Blob");
 }
 SYSINIT(dtb_oid, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_fdt_oid, NULL);
+#else /* __rtems__ */
+static void
+ofw_init(void)
+{
+   int rv;
+   void *fdt;
+   fdt = bsp_fdt_get();
+   rv = ofw_fdt_init(NULL, fdt);
+   assert(rv == 0);
+}
+RTEMS_SYSINIT_ITEM(
+   ofw_init,
+   RTEMS_SYSINIT_BSP_START,
+   RTEMS_SYSINIT_ORDER_FIRST
+);
+#endif /* __rtems__ */
 
 static int
 ofw_fdt_init(ofw_t ofw, void *data)
@@ -297,7 +330,11 @@ ofw_fdt_getprop(ofw_t ofw, phandle_t package, const char 
*propname, void *buf,
if (prop == NULL)
return (-1);
 
+#ifndef __rtems__
bcopy(prop, buf, min(len, buflen));
+#else /* __rtems__ */
+   memcpy(buf, prop, MIN(len, buflen));
+#endif /* __rtems__ */
 
return (len);
 }
@@ -407,6 +444,7 @@ ofw_fdt_package_to_path(ofw_t ofw, phandle_t package, char 
*buf, size_t len)
return (-1);
 }
 
+#ifndef __rtems__
 #if defined(FDT_MARVELL)
 static int
 ofw_fdt_fixup(ofw_t ofw)
@@ -476,4 +514,78 @@ ofw_fdt_interpret(ofw_t ofw, const char *cmd, int nret, 
cell_t *retvals)
 #else
return (0);
 #endif
-}
\ No newline at end of file
+}
+#endif /* __rtems__ */
+
+#ifdef __rtems__
+int OFW_INIT(ofw_t ofw_obj, void *cookie)
+{
+   return ofw_fdt_init(ofw_obj, cookie);
+}
+
+phandle_t OFW_PEER(ofw_t ofw_obj, phandle_t node)
+{
+   return ofw_fdt_peer(ofw_obj, node);
+}
+
+phandle_t OFW_CHILD(ofw_t ofw_obj, phandle_t node)
+{
+   return ofw_fdt_child(ofw_obj, node);
+}
+
+phandle_t OFW_PARENT(ofw_t ofw_obj, phandle_t node)
+{
+   return ofw_fdt_parent(ofw_obj, node);
+}
+
+phandle_t OFW_INSTANCE_TO_PACKAGE(ofw_t ofw_obj, ihandle_t instance)
+{
+   return ofw_fdt_instance_to_package(ofw_obj, instance);
+}
+
+ssize_t OFW_GETPROPLEN(ofw_t ofw_obj, phandle_t package, const char *propname)
+{
+   return ofw_fdt_getproplen(ofw_obj, package, propname);
+}
+
+ssize_t OFW_GETPROP(ofw_t ofw_obj, phandle_t package, const char *propname,
+void *buf, size_t buflen
+)
+{
+   return ofw_fdt_getprop(ofw_obj, package, propname, buf, buflen);
+}
+
+int OFW_NEXTPROP(ofw_t ofw_obj, phandle_t package, const char *prev, char *buf,
+size_t size)
+{
+   return ofw_fdt_nextprop(ofw_obj, package, prev, buf, size);
+}
+
+int OFW_SETPROP(ofw_t ofw_obj, phandle_t package, const char *propname,
+const void *buf, size_t len)
+{
+   return ofw_fdt_setprop(ofw_obj, package, propname, buf, len);
+}
+
+ssize_t OFW_CANON(ofw_t ofw_obj, const char *device, char *buf, size_t len)
+{
+   return ofw_fdt_canon(ofw_obj, device, buf, len);
+}
+
+phandle_t OFW_FINDDEVICE(ofw_t ofw_obj, const char *device)
+{
+   return ofw_fdt_finddevice(ofw_obj, device);
+}
+
+ssize_t OFW_INSTANCE_TO_PATH(ofw_t ofw_obj, ihandle_t instance, char *buf,
+size_t len)
+{
+   return ofw_fdt_instance_to_path(ofw_obj, instance, buf, len);
+}
+
+ssize_t OFW_PACKAGE_TO_PATH(ofw_t ofw_obj, pha

[PATCH 3/5] bsps/shared/freebsd: RTEMS to FreeBSD porting helper header

2020-05-28 Thread G S Niteesh Babu
This file serve the purpose as rtems-bsd-kernel-space.h in the
rtems-libbsd.
This file is intended to be included in every source file that
is to imported from FreeBSD. This is to reduce the number of
redefinitions for commonly used functions like malloc, free
and KASSERT.
---
 bsps/shared/freebsd/rtems-freebsd-helper.h | 44 ++
 1 file changed, 44 insertions(+)
 create mode 100644 bsps/shared/freebsd/rtems-freebsd-helper.h

diff --git a/bsps/shared/freebsd/rtems-freebsd-helper.h 
b/bsps/shared/freebsd/rtems-freebsd-helper.h
new file mode 100644
index 00..8135a1caf5
--- /dev/null
+++ b/bsps/shared/freebsd/rtems-freebsd-helper.h
@@ -0,0 +1,44 @@
+
+/* SPDX-License-Identifier: BSD-2-Clause
+
+ *
+ * @file
+ *
+ * @ingroup LIBFREEBSD
+ *
+ * @brief
+ */
+
+/*
+ * Copyright (C) <2020> Niteesh Babu 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H
+#define _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H
+
+#define KASSERT(cnd, msg)   assert(cnd)
+#define malloc(size, type, flags)   malloc(size)
+#define free(addr, type)free(addr)
+
+#endif /* _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H */
\ No newline at end of file
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 1/5] bsps/shared/freebsd: Import OFW files from FreeBSD.

2020-05-28 Thread G S Niteesh Babu
freebsd head: b8c57b4

The following files have been imported from FreeBSD to implement
OF_* functions into RTEMS.
1) openfirm.h
2) openfirm.c
3) ofw_fdt.c
---
 bsps/shared/freebsd/dev/ofw/ofw_fdt.c  | 479 ++
 bsps/shared/freebsd/dev/ofw/openfirm.c | 848 +
 bsps/shared/freebsd/dev/ofw/openfirm.h | 187 ++
 3 files changed, 1514 insertions(+)
 create mode 100644 bsps/shared/freebsd/dev/ofw/ofw_fdt.c
 create mode 100644 bsps/shared/freebsd/dev/ofw/openfirm.c
 create mode 100644 bsps/shared/freebsd/dev/ofw/openfirm.h

diff --git a/bsps/shared/freebsd/dev/ofw/ofw_fdt.c 
b/bsps/shared/freebsd/dev/ofw/ofw_fdt.c
new file mode 100644
index 00..e4f72e8142
--- /dev/null
+++ b/bsps/shared/freebsd/dev/ofw/ofw_fdt.c
@@ -0,0 +1,479 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2009-2010 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Semihalf under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+__FBSDID("$FreeBSD$");
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "ofw_if.h"
+
+#ifdef DEBUG
+#define debugf(fmt, args...) do { printf("%s(): ", __func__);  \
+printf(fmt,##args); } while (0)
+#else
+#define debugf(fmt, args...)
+#endif
+
+#if defined(__arm__)
+#if defined(SOC_MV_ARMADAXP) || defined(SOC_MV_ARMADA38X) || \
+defined(SOC_MV_DISCOVERY) || defined(SOC_MV_DOVE) || \
+defined(SOC_MV_FREY) || defined(SOC_MV_KIRKWOOD) || \
+defined(SOC_MV_LOKIPLUS) || defined(SOC_MV_ORION)
+#define FDT_MARVELL
+#endif
+#endif
+
+static int ofw_fdt_init(ofw_t, void *);
+static phandle_t ofw_fdt_peer(ofw_t, phandle_t);
+static phandle_t ofw_fdt_child(ofw_t, phandle_t);
+static phandle_t ofw_fdt_parent(ofw_t, phandle_t);
+static phandle_t ofw_fdt_instance_to_package(ofw_t, ihandle_t);
+static ssize_t ofw_fdt_getproplen(ofw_t, phandle_t, const char *);
+static ssize_t ofw_fdt_getprop(ofw_t, phandle_t, const char *, void *, size_t);
+static int ofw_fdt_nextprop(ofw_t, phandle_t, const char *, char *, size_t);
+static int ofw_fdt_setprop(ofw_t, phandle_t, const char *, const void *,
+size_t);
+static ssize_t ofw_fdt_canon(ofw_t, const char *, char *, size_t);
+static phandle_t ofw_fdt_finddevice(ofw_t, const char *);
+static ssize_t ofw_fdt_instance_to_path(ofw_t, ihandle_t, char *, size_t);
+static ssize_t ofw_fdt_package_to_path(ofw_t, phandle_t, char *, size_t);
+static int ofw_fdt_interpret(ofw_t, const char *, int, cell_t *);
+
+static ofw_method_t ofw_fdt_methods[] = {
+   OFWMETHOD(ofw_init, ofw_fdt_init),
+   OFWMETHOD(ofw_peer, ofw_fdt_peer),
+   OFWMETHOD(ofw_child,ofw_fdt_child),
+   OFWMETHOD(ofw_parent,   ofw_fdt_parent),
+   OFWMETHOD(ofw_instance_to_package,  ofw_fdt_instance_to_package),
+   OFWMETHOD(ofw_getproplen,   ofw_fdt_getproplen),
+   OFWMETHOD(ofw_getprop,  ofw_fdt_getprop),
+   OFWMETHOD(ofw_nextprop, ofw_fdt_nextprop),
+   OFWMETHOD(ofw_setprop,  ofw_fdt_setprop),
+   OFWMETHOD(ofw_canon,ofw_fdt_canon),
+   OFWMETHOD(ofw_finddevice,   ofw_fdt_finddevice),
+   OFWMETHOD(ofw_instance_to_path, ofw_fdt_instance_to_path),
+   OFWMETHOD(ofw_package_to_path,  ofw_fdt_package_to_path),
+   OFWMETHOD(ofw_interpret,ofw_fdt_interpret),
+   { 0, 0 }
+};
+
+static ofw_def_t ofw_fdt = {
+   OFW_FDT,
+   ofw_fdt_methods,
+   0
+};
+OFW_DEF

[PATCH 5/5] bsps/shared/freebsd: Added OFW sources files to Makefile

2020-05-28 Thread G S Niteesh Babu
Added OFW source files to shared-sources.am under bsps/shared.
---
 bsps/shared/shared-sources.am | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/bsps/shared/shared-sources.am b/bsps/shared/shared-sources.am
index 3c07770bb2..445f7115b6 100644
--- a/bsps/shared/shared-sources.am
+++ b/bsps/shared/shared-sources.am
@@ -37,6 +37,8 @@ librtemsbsp_a_SOURCES += 
../../../../../../bsps/shared/dev/serial/serprobe.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/z85c30.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/dev/serial/z85c30_reg.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/start/bootcard.c
+librtemsbsp_a_SOURCES += 
../../../../../../bsps/shared/freebsd/dev/ofw/ofw_fdt.c
+librtemsbsp_a_SOURCES += 
../../../../../../bsps/shared/freebsd/dev/ofw/openfirm.c
 if HAS_NETWORKING
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/net/cs8900.c
 librtemsbsp_a_SOURCES += ../../../../../../bsps/shared/net/dec21140.c
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 5/5] cpukit/Makefile: Add libfreebsd source files.

2020-06-04 Thread G S Niteesh Babu
---
 cpukit/Makefile.am | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
index 51f38c84c7..1335d41038 100644
--- a/cpukit/Makefile.am
+++ b/cpukit/Makefile.am
@@ -342,6 +342,8 @@ librtemscpu_a_SOURCES += libmisc/uuid/uuid_time.c
 librtemscpu_a_SOURCES += libmisc/xz/xz_crc32.c
 librtemscpu_a_SOURCES += libmisc/xz/xz_dec_lzma2.c
 librtemscpu_a_SOURCES += libmisc/xz/xz_dec_stream.c
+librtemscpu_a_SOURCES += libfreebsd/dev/ofw/ofw_fdt.c
+librtemscpu_a_SOURCES += libfreebsd/dev/ofw/openfirm.c
 librtemscpu_a_SOURCES += libfs/src/defaults/default_are_nodes_equal.c
 librtemscpu_a_SOURCES += libfs/src/defaults/default_chown.c
 librtemscpu_a_SOURCES += libfs/src/defaults/default_clone.c
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 0/5] OFW port to RTEMS

2020-06-04 Thread G S Niteesh Babu
Hello,

The following series of patches port OFW from FreeBSD to RTEMS.
This patch has been tested on a Raspberry Pi 3 with a small test
application which retrives basic node properties.

G S Niteesh Babu (5):
  libfreebsd: Import OFW files from FreeBSD.
  libfreebsd: Added ofw_if.h
  libfreebsd: FreeBSD porting helper header
  libfreebsd: Port OFW to RTEMS
  cpukit/Makefile: Add libfreebsd source files.

 cpukit/Makefile.am   |   2 +
 cpukit/libfreebsd/dev/ofw/ofw_fdt.c  | 592 +++
 cpukit/libfreebsd/dev/ofw/ofw_if.h   |  63 ++
 cpukit/libfreebsd/dev/ofw/openfirm.c | 905 +++
 cpukit/libfreebsd/dev/ofw/openfirm.h | 205 +
 cpukit/libfreebsd/rtems-freebsd-helper.h |  45 ++
 6 files changed, 1812 insertions(+)
 create mode 100644 cpukit/libfreebsd/dev/ofw/ofw_fdt.c
 create mode 100644 cpukit/libfreebsd/dev/ofw/ofw_if.h
 create mode 100644 cpukit/libfreebsd/dev/ofw/openfirm.c
 create mode 100644 cpukit/libfreebsd/dev/ofw/openfirm.h
 create mode 100644 cpukit/libfreebsd/rtems-freebsd-helper.h

-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 1/5] libfreebsd: Import OFW files from FreeBSD.

2020-06-04 Thread G S Niteesh Babu
freebsd head: b8c57b4

The following files have been imported from FreeBSD to implement
OF_* functions into RTEMS.
1) openfirm.h
2) openfirm.c
3) ofw_fdt.c
---
 cpukit/libfreebsd/dev/ofw/ofw_fdt.c  | 479 +++
 cpukit/libfreebsd/dev/ofw/openfirm.c | 848 +++
 cpukit/libfreebsd/dev/ofw/openfirm.h | 187 ++
 3 files changed, 1514 insertions(+)
 create mode 100644 cpukit/libfreebsd/dev/ofw/ofw_fdt.c
 create mode 100644 cpukit/libfreebsd/dev/ofw/openfirm.c
 create mode 100644 cpukit/libfreebsd/dev/ofw/openfirm.h

diff --git a/cpukit/libfreebsd/dev/ofw/ofw_fdt.c 
b/cpukit/libfreebsd/dev/ofw/ofw_fdt.c
new file mode 100644
index 00..e4f72e8142
--- /dev/null
+++ b/cpukit/libfreebsd/dev/ofw/ofw_fdt.c
@@ -0,0 +1,479 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2009-2010 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Semihalf under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+__FBSDID("$FreeBSD$");
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "ofw_if.h"
+
+#ifdef DEBUG
+#define debugf(fmt, args...) do { printf("%s(): ", __func__);  \
+printf(fmt,##args); } while (0)
+#else
+#define debugf(fmt, args...)
+#endif
+
+#if defined(__arm__)
+#if defined(SOC_MV_ARMADAXP) || defined(SOC_MV_ARMADA38X) || \
+defined(SOC_MV_DISCOVERY) || defined(SOC_MV_DOVE) || \
+defined(SOC_MV_FREY) || defined(SOC_MV_KIRKWOOD) || \
+defined(SOC_MV_LOKIPLUS) || defined(SOC_MV_ORION)
+#define FDT_MARVELL
+#endif
+#endif
+
+static int ofw_fdt_init(ofw_t, void *);
+static phandle_t ofw_fdt_peer(ofw_t, phandle_t);
+static phandle_t ofw_fdt_child(ofw_t, phandle_t);
+static phandle_t ofw_fdt_parent(ofw_t, phandle_t);
+static phandle_t ofw_fdt_instance_to_package(ofw_t, ihandle_t);
+static ssize_t ofw_fdt_getproplen(ofw_t, phandle_t, const char *);
+static ssize_t ofw_fdt_getprop(ofw_t, phandle_t, const char *, void *, size_t);
+static int ofw_fdt_nextprop(ofw_t, phandle_t, const char *, char *, size_t);
+static int ofw_fdt_setprop(ofw_t, phandle_t, const char *, const void *,
+size_t);
+static ssize_t ofw_fdt_canon(ofw_t, const char *, char *, size_t);
+static phandle_t ofw_fdt_finddevice(ofw_t, const char *);
+static ssize_t ofw_fdt_instance_to_path(ofw_t, ihandle_t, char *, size_t);
+static ssize_t ofw_fdt_package_to_path(ofw_t, phandle_t, char *, size_t);
+static int ofw_fdt_interpret(ofw_t, const char *, int, cell_t *);
+
+static ofw_method_t ofw_fdt_methods[] = {
+   OFWMETHOD(ofw_init, ofw_fdt_init),
+   OFWMETHOD(ofw_peer, ofw_fdt_peer),
+   OFWMETHOD(ofw_child,ofw_fdt_child),
+   OFWMETHOD(ofw_parent,   ofw_fdt_parent),
+   OFWMETHOD(ofw_instance_to_package,  ofw_fdt_instance_to_package),
+   OFWMETHOD(ofw_getproplen,   ofw_fdt_getproplen),
+   OFWMETHOD(ofw_getprop,  ofw_fdt_getprop),
+   OFWMETHOD(ofw_nextprop, ofw_fdt_nextprop),
+   OFWMETHOD(ofw_setprop,  ofw_fdt_setprop),
+   OFWMETHOD(ofw_canon,ofw_fdt_canon),
+   OFWMETHOD(ofw_finddevice,   ofw_fdt_finddevice),
+   OFWMETHOD(ofw_instance_to_path, ofw_fdt_instance_to_path),
+   OFWMETHOD(ofw_package_to_path,  ofw_fdt_package_to_path),
+   OFWMETHOD(ofw_interpret,ofw_fdt_interpret),
+   { 0, 0 }
+};
+
+static ofw_def_t ofw_fdt = {
+   OFW_FDT,
+   ofw_fdt_methods,
+   0
+};
+OFW_DEF(ofw_fdt);
+
+s

[PATCH 3/5] libfreebsd: FreeBSD porting helper header

2020-06-04 Thread G S Niteesh Babu
This file serve the purpose as rtems-bsd-kernel-space.h in the
rtems-libbsd.
This file is intended to be included in every source file that
is to imported from FreeBSD. This is to reduce the number of
redefinitions for commonly used functions like malloc, free
and KASSERT.
---
 cpukit/libfreebsd/rtems-freebsd-helper.h | 45 
 1 file changed, 45 insertions(+)
 create mode 100644 cpukit/libfreebsd/rtems-freebsd-helper.h

diff --git a/cpukit/libfreebsd/rtems-freebsd-helper.h 
b/cpukit/libfreebsd/rtems-freebsd-helper.h
new file mode 100644
index 00..1b9b7609f9
--- /dev/null
+++ b/cpukit/libfreebsd/rtems-freebsd-helper.h
@@ -0,0 +1,45 @@
+
+/* SPDX-License-Identifier: BSD-2-Clause
+
+ *
+ * @file
+ *
+ * @ingroup LIBFREEBSD
+ *
+ * @brief
+ */
+
+/*
+ * Copyright (C) <2020> Niteesh Babu 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H
+#define _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H
+
+#define _KERNEL1
+#define KASSERT(cnd, msg)  assert(cnd)
+#define malloc(size, type, flags)  malloc(size)
+#define free(addr, type)   free(addr)
+
+#endif /* _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H */
\ No newline at end of file
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 2/5] libfreebsd: Added ofw_if.h

2020-06-04 Thread G S Niteesh Babu
This file is the RTEMS implementation of ofw_if.h in FreeBSD. The
ofw_if.h in FreeBSD is an autogenerated header file that maps the
OF_function calls to their respective implementation. But in RTEMS
this file maps the OF_functions directly to their FDT implementation.
---
 cpukit/libfreebsd/dev/ofw/ofw_if.h | 63 ++
 1 file changed, 63 insertions(+)
 create mode 100644 cpukit/libfreebsd/dev/ofw/ofw_if.h

diff --git a/cpukit/libfreebsd/dev/ofw/ofw_if.h 
b/cpukit/libfreebsd/dev/ofw/ofw_if.h
new file mode 100644
index 00..7b9bcaa24a
--- /dev/null
+++ b/cpukit/libfreebsd/dev/ofw/ofw_if.h
@@ -0,0 +1,63 @@
+/* SPDX-License-Identifier: BSD-2-Clause
+
+ *
+ * @file
+ *
+ * @ingroup LIBFREEBSDOFW
+ *
+ * @brief Declaration of OFW functions.
+ */
+
+/*
+ * Copyright (C) <2020> Niteesh Babu 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LIBFREEBSD_OFW_IF_H
+#define _LIBFREEBSD_OFW_IF_H
+
+#include 
+#include "openfirm.h"
+
+typedef void*  ofw_t;
+
+int OFW_INIT(ofw_t ofw_obj, void *cookie);
+phandle_t OFW_PEER(ofw_t ofw_obj, phandle_t node);
+phandle_t OFW_CHILD(ofw_t ofw_obj, phandle_t node);
+phandle_t OFW_PARENT(ofw_t ofw_obj, phandle_t node);
+phandle_t OFW_INSTANCE_TO_PACKAGE(ofw_t ofw_obj, ihandle_t instance);
+ssize_t OFW_GETPROPLEN(ofw_t ofw_obj, phandle_t package, const char *propname);
+ssize_t OFW_GETPROP(ofw_t ofw_obj, phandle_t package, const char *propname,
+void *buf, size_t buflen);
+int OFW_NEXTPROP(ofw_t ofw_obj, phandle_t package, const char *prev, char *buf,
+size_t size);
+int OFW_SETPROP(ofw_t ofw_obj, phandle_t package, const char *propname,
+const void *buf, size_t len);
+ssize_t OFW_CANON(ofw_t ofw_obj, const char *device, char *buf, size_t len);
+phandle_t OFW_FINDDEVICE(ofw_t ofw_obj, const char *device);
+ssize_t OFW_INSTANCE_TO_PATH(ofw_t ofw_obj, ihandle_t instance, char *buf,
+size_t len);
+ssize_t OFW_PACKAGE_TO_PATH(ofw_t ofw_obj, phandle_t package, char *buf,
+size_t len);
+
+#endif /* _LIBFREEBSD_OFW_IF_H */
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 4/5] libfreebsd: Port OFW to RTEMS

2020-06-04 Thread G S Niteesh Babu
The following files have been ported to RTEMS
1) openfirm.h
2) openfirm.c
3) ofw_fdt.c
---
 cpukit/libfreebsd/dev/ofw/ofw_fdt.c  | 117 ++-
 cpukit/libfreebsd/dev/ofw/openfirm.c |  59 +-
 cpukit/libfreebsd/dev/ofw/openfirm.h |  18 +
 3 files changed, 191 insertions(+), 3 deletions(-)

diff --git a/cpukit/libfreebsd/dev/ofw/ofw_fdt.c 
b/cpukit/libfreebsd/dev/ofw/ofw_fdt.c
index e4f72e8142..5341440789 100644
--- a/cpukit/libfreebsd/dev/ofw/ofw_fdt.c
+++ b/cpukit/libfreebsd/dev/ofw/ofw_fdt.c
@@ -29,10 +29,13 @@
  * SUCH DAMAGE.
  */
 
+#ifndef __rtems__
 #include 
 __FBSDID("$FreeBSD$");
+#endif /* __rtems__ */
 
 #include 
+#ifndef __rtems__
 #include 
 #include 
 #include 
@@ -45,9 +48,18 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#endif /* __rtems__ */
 
 #include "ofw_if.h"
-
+#ifdef __rtems__
+#include 
+#include 
+#include 
+#include 
+#include "openfirm.h"
+#endif /* __rtems__ */
+
+#ifndef __rtems__
 #ifdef DEBUG
 #define debugf(fmt, args...) do { printf("%s(): ", __func__);  \
 printf(fmt,##args); } while (0)
@@ -63,6 +75,7 @@ __FBSDID("$FreeBSD$");
 #define FDT_MARVELL
 #endif
 #endif
+#endif /* __rtems__ */
 
 static int ofw_fdt_init(ofw_t, void *);
 static phandle_t ofw_fdt_peer(ofw_t, phandle_t);
@@ -78,6 +91,7 @@ static ssize_t ofw_fdt_canon(ofw_t, const char *, char *, 
size_t);
 static phandle_t ofw_fdt_finddevice(ofw_t, const char *);
 static ssize_t ofw_fdt_instance_to_path(ofw_t, ihandle_t, char *, size_t);
 static ssize_t ofw_fdt_package_to_path(ofw_t, phandle_t, char *, size_t);
+#ifndef __rtems__
 static int ofw_fdt_interpret(ofw_t, const char *, int, cell_t *);
 
 static ofw_method_t ofw_fdt_methods[] = {
@@ -104,9 +118,11 @@ static ofw_def_t ofw_fdt = {
0
 };
 OFW_DEF(ofw_fdt);
+#endif /* __rtems__ */
 
 static void *fdtp = NULL;
 
+#ifndef __rtems__
 static int
 sysctl_handle_dtb(SYSCTL_HANDLER_ARGS)
 {
@@ -127,6 +143,24 @@ sysctl_register_fdt_oid(void *arg)
sysctl_handle_dtb, "", "Device Tree Blob");
 }
 SYSINIT(dtb_oid, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_fdt_oid, NULL);
+#else /* __rtems__ */
+const void* bsp_fdt_get(void);
+static void
+ofw_init(void)
+{
+   int rv;
+   const void *fdt;
+
+   fdt = bsp_fdt_get();
+   rv = ofw_fdt_init(NULL, fdt);
+   assert(rv == 0);
+}
+RTEMS_SYSINIT_ITEM(
+   ofw_init,
+   RTEMS_SYSINIT_BSP_START,
+   RTEMS_SYSINIT_ORDER_FIRST
+);
+#endif /* __rtems__ */
 
 static int
 ofw_fdt_init(ofw_t ofw, void *data)
@@ -297,7 +331,11 @@ ofw_fdt_getprop(ofw_t ofw, phandle_t package, const char 
*propname, void *buf,
if (prop == NULL)
return (-1);
 
+#ifndef __rtems__
bcopy(prop, buf, min(len, buflen));
+#else /* __rtems__ */
+   memcpy(buf, prop, MIN(len, buflen));
+#endif /* __rtems__ */
 
return (len);
 }
@@ -407,6 +445,7 @@ ofw_fdt_package_to_path(ofw_t ofw, phandle_t package, char 
*buf, size_t len)
return (-1);
 }
 
+#ifndef __rtems__
 #if defined(FDT_MARVELL)
 static int
 ofw_fdt_fixup(ofw_t ofw)
@@ -476,4 +515,78 @@ ofw_fdt_interpret(ofw_t ofw, const char *cmd, int nret, 
cell_t *retvals)
 #else
return (0);
 #endif
-}
\ No newline at end of file
+}
+#endif /* __rtems__ */
+
+#ifdef __rtems__
+int OFW_INIT(ofw_t ofw_obj, void *cookie)
+{
+   return ofw_fdt_init(ofw_obj, cookie);
+}
+
+phandle_t OFW_PEER(ofw_t ofw_obj, phandle_t node)
+{
+   return ofw_fdt_peer(ofw_obj, node);
+}
+
+phandle_t OFW_CHILD(ofw_t ofw_obj, phandle_t node)
+{
+   return ofw_fdt_child(ofw_obj, node);
+}
+
+phandle_t OFW_PARENT(ofw_t ofw_obj, phandle_t node)
+{
+   return ofw_fdt_parent(ofw_obj, node);
+}
+
+phandle_t OFW_INSTANCE_TO_PACKAGE(ofw_t ofw_obj, ihandle_t instance)
+{
+   return ofw_fdt_instance_to_package(ofw_obj, instance);
+}
+
+ssize_t OFW_GETPROPLEN(ofw_t ofw_obj, phandle_t package, const char *propname)
+{
+   return ofw_fdt_getproplen(ofw_obj, package, propname);
+}
+
+ssize_t OFW_GETPROP(ofw_t ofw_obj, phandle_t package, const char *propname,
+void *buf, size_t buflen
+)
+{
+   return ofw_fdt_getprop(ofw_obj, package, propname, buf, buflen);
+}
+
+int OFW_NEXTPROP(ofw_t ofw_obj, phandle_t package, const char *prev, char *buf,
+size_t size)
+{
+   return ofw_fdt_nextprop(ofw_obj, package, prev, buf, size);
+}
+
+int OFW_SETPROP(ofw_t ofw_obj, phandle_t package, const char *propname,
+const void *buf, size_t len)
+{
+   return ofw_fdt_setprop(ofw_obj, package, propname, buf, len);
+}
+
+ssize_t OFW_CANON(ofw_t ofw_obj, const char *device, char *buf, size_t len)
+{
+   return ofw_fdt_canon(ofw_obj, device, buf, len);
+}
+
+phandle_t OFW_FINDDEVICE(ofw_t ofw_obj, const char *device)
+{
+   return ofw_fdt_finddevice(ofw_obj, device);
+}
+
+ssize_t OFW_INSTANCE_TO_PATH(ofw_t ofw_obj, ihandle_t instance, char *buf,
+size_t len)
+{
+   return ofw_fdt_instance_to_path(ofw_obj, instance, buf, len);
+}
+
+ssize_t OFW_PACKAGE_TO_PATH

[PATCH RTEMS v2 4/6] bsp/fatal.h: Add FATAL codes for libfreebsd

2020-06-11 Thread G S Niteesh Babu
---
 bsps/include/bsp/fatal.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/bsps/include/bsp/fatal.h b/bsps/include/bsp/fatal.h
index 3f8e1eb591..c22f8a2f52 100644
--- a/bsps/include/bsp/fatal.h
+++ b/bsps/include/bsp/fatal.h
@@ -156,6 +156,10 @@ typedef enum {
   RISCV_FATAL_NO_TLCLOCK_FREQUENCY_IN_DEVICE_TREE
 } bsp_fatal_code;
 
+typedef enum {
+  LIBFREEBSD_FATAL_INVALID_FDT = BSP_FATAL_CODE_BLOCK(14)
+} libfreebsd_fatal_code;
+
 RTEMS_NO_RETURN static inline void
 bsp_fatal( bsp_fatal_code code )
 {
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH RTEMS v2 2/6] libfreebsd: Added ofw_if.h

2020-06-11 Thread G S Niteesh Babu
This file is the RTEMS implementation of ofw_if.h in FreeBSD. The
ofw_if.h in FreeBSD is an autogenerated header file that maps the
OF_function calls to their respective implementation. But in RTEMS
this file maps the OF_functions directly to their FDT implementation.
---
 cpukit/libfreebsd/dev/ofw/ofw_if.h | 62 ++
 1 file changed, 62 insertions(+)
 create mode 100644 cpukit/libfreebsd/dev/ofw/ofw_if.h

diff --git a/cpukit/libfreebsd/dev/ofw/ofw_if.h 
b/cpukit/libfreebsd/dev/ofw/ofw_if.h
new file mode 100644
index 00..b27864a032
--- /dev/null
+++ b/cpukit/libfreebsd/dev/ofw/ofw_if.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: BSD-2-Clause
+
+ *
+ * @file
+ *
+ * @ingroup LIBFREEBSD
+ *
+ * @brief Declaration of OFW functions.
+ */
+
+/*
+ * Copyright (C) <2020> Niteesh Babu 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LIBFREEBSD_OFW_IF_H
+#define _LIBFREEBSD_OFW_IF_H
+
+#include "openfirm.h"
+
+typedef void*  ofw_t;
+
+int OFW_INIT(ofw_t ofw_obj, void *cookie);
+phandle_t OFW_PEER(ofw_t ofw_obj, phandle_t node);
+phandle_t OFW_CHILD(ofw_t ofw_obj, phandle_t node);
+phandle_t OFW_PARENT(ofw_t ofw_obj, phandle_t node);
+phandle_t OFW_INSTANCE_TO_PACKAGE(ofw_t ofw_obj, ihandle_t instance);
+ssize_t OFW_GETPROPLEN(ofw_t ofw_obj, phandle_t package, const char *propname);
+ssize_t OFW_GETPROP(ofw_t ofw_obj, phandle_t package, const char *propname,
+   void *buf, size_t buflen);
+int OFW_NEXTPROP(ofw_t ofw_obj, phandle_t package, const char *prev, char *buf,
+   size_t size);
+int OFW_SETPROP(ofw_t ofw_obj, phandle_t package, const char *propname,
+   const void *buf, size_t len);
+ssize_t OFW_CANON(ofw_t ofw_obj, const char *device, char *buf, size_t len);
+phandle_t OFW_FINDDEVICE(ofw_t ofw_obj, const char *device);
+ssize_t OFW_INSTANCE_TO_PATH(ofw_t ofw_obj, ihandle_t instance, char *buf,
+   size_t len);
+ssize_t OFW_PACKAGE_TO_PATH(ofw_t ofw_obj, phandle_t package, char *buf,
+   size_t len);
+
+#endif /* _LIBFREEBSD_OFW_IF_H */
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH RTEMS v2 1/6] libfreebsd: Import OFW files from FreeBSD.

2020-06-11 Thread G S Niteesh Babu
freebsd head: b8c57b4

The following files have been imported from FreeBSD to implement
OF_* functions into RTEMS.
1) openfirm.h
2) openfirm.c
3) ofw_fdt.c
---
 cpukit/libfreebsd/dev/ofw/ofw_fdt.c  | 479 +++
 cpukit/libfreebsd/dev/ofw/openfirm.c | 848 +++
 cpukit/libfreebsd/dev/ofw/openfirm.h | 187 ++
 3 files changed, 1514 insertions(+)
 create mode 100644 cpukit/libfreebsd/dev/ofw/ofw_fdt.c
 create mode 100644 cpukit/libfreebsd/dev/ofw/openfirm.c
 create mode 100644 cpukit/libfreebsd/dev/ofw/openfirm.h

diff --git a/cpukit/libfreebsd/dev/ofw/ofw_fdt.c 
b/cpukit/libfreebsd/dev/ofw/ofw_fdt.c
new file mode 100644
index 00..e4f72e8142
--- /dev/null
+++ b/cpukit/libfreebsd/dev/ofw/ofw_fdt.c
@@ -0,0 +1,479 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2009-2010 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Semihalf under sponsorship from
+ * the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include 
+__FBSDID("$FreeBSD$");
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "ofw_if.h"
+
+#ifdef DEBUG
+#define debugf(fmt, args...) do { printf("%s(): ", __func__);  \
+printf(fmt,##args); } while (0)
+#else
+#define debugf(fmt, args...)
+#endif
+
+#if defined(__arm__)
+#if defined(SOC_MV_ARMADAXP) || defined(SOC_MV_ARMADA38X) || \
+defined(SOC_MV_DISCOVERY) || defined(SOC_MV_DOVE) || \
+defined(SOC_MV_FREY) || defined(SOC_MV_KIRKWOOD) || \
+defined(SOC_MV_LOKIPLUS) || defined(SOC_MV_ORION)
+#define FDT_MARVELL
+#endif
+#endif
+
+static int ofw_fdt_init(ofw_t, void *);
+static phandle_t ofw_fdt_peer(ofw_t, phandle_t);
+static phandle_t ofw_fdt_child(ofw_t, phandle_t);
+static phandle_t ofw_fdt_parent(ofw_t, phandle_t);
+static phandle_t ofw_fdt_instance_to_package(ofw_t, ihandle_t);
+static ssize_t ofw_fdt_getproplen(ofw_t, phandle_t, const char *);
+static ssize_t ofw_fdt_getprop(ofw_t, phandle_t, const char *, void *, size_t);
+static int ofw_fdt_nextprop(ofw_t, phandle_t, const char *, char *, size_t);
+static int ofw_fdt_setprop(ofw_t, phandle_t, const char *, const void *,
+size_t);
+static ssize_t ofw_fdt_canon(ofw_t, const char *, char *, size_t);
+static phandle_t ofw_fdt_finddevice(ofw_t, const char *);
+static ssize_t ofw_fdt_instance_to_path(ofw_t, ihandle_t, char *, size_t);
+static ssize_t ofw_fdt_package_to_path(ofw_t, phandle_t, char *, size_t);
+static int ofw_fdt_interpret(ofw_t, const char *, int, cell_t *);
+
+static ofw_method_t ofw_fdt_methods[] = {
+   OFWMETHOD(ofw_init, ofw_fdt_init),
+   OFWMETHOD(ofw_peer, ofw_fdt_peer),
+   OFWMETHOD(ofw_child,ofw_fdt_child),
+   OFWMETHOD(ofw_parent,   ofw_fdt_parent),
+   OFWMETHOD(ofw_instance_to_package,  ofw_fdt_instance_to_package),
+   OFWMETHOD(ofw_getproplen,   ofw_fdt_getproplen),
+   OFWMETHOD(ofw_getprop,  ofw_fdt_getprop),
+   OFWMETHOD(ofw_nextprop, ofw_fdt_nextprop),
+   OFWMETHOD(ofw_setprop,  ofw_fdt_setprop),
+   OFWMETHOD(ofw_canon,ofw_fdt_canon),
+   OFWMETHOD(ofw_finddevice,   ofw_fdt_finddevice),
+   OFWMETHOD(ofw_instance_to_path, ofw_fdt_instance_to_path),
+   OFWMETHOD(ofw_package_to_path,  ofw_fdt_package_to_path),
+   OFWMETHOD(ofw_interpret,ofw_fdt_interpret),
+   { 0, 0 }
+};
+
+static ofw_def_t ofw_fdt = {
+   OFW_FDT,
+   ofw_fdt_methods,
+   0
+};
+OFW_DEF(ofw_fdt);
+
+s

[PATCH RTEMS v2 6/6] cpukit/Makefile: Add libfreebsd source files.

2020-06-11 Thread G S Niteesh Babu
---
 cpukit/Makefile.am | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
index 51f38c84c7..1335d41038 100644
--- a/cpukit/Makefile.am
+++ b/cpukit/Makefile.am
@@ -342,6 +342,8 @@ librtemscpu_a_SOURCES += libmisc/uuid/uuid_time.c
 librtemscpu_a_SOURCES += libmisc/xz/xz_crc32.c
 librtemscpu_a_SOURCES += libmisc/xz/xz_dec_lzma2.c
 librtemscpu_a_SOURCES += libmisc/xz/xz_dec_stream.c
+librtemscpu_a_SOURCES += libfreebsd/dev/ofw/ofw_fdt.c
+librtemscpu_a_SOURCES += libfreebsd/dev/ofw/openfirm.c
 librtemscpu_a_SOURCES += libfs/src/defaults/default_are_nodes_equal.c
 librtemscpu_a_SOURCES += libfs/src/defaults/default_chown.c
 librtemscpu_a_SOURCES += libfs/src/defaults/default_clone.c
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH RTEMS v2 5/6] libfreebsd: Port OFW to RTEMS

2020-06-11 Thread G S Niteesh Babu
The following files have been ported to RTEMS
1) openfirm.h
2) openfirm.c
3) ofw_fdt.c
---
 cpukit/libfreebsd/dev/ofw/ofw_fdt.c  | 146 ++-
 cpukit/libfreebsd/dev/ofw/openfirm.c |  58 ++-
 cpukit/libfreebsd/dev/ofw/openfirm.h |  17 
 3 files changed, 219 insertions(+), 2 deletions(-)

diff --git a/cpukit/libfreebsd/dev/ofw/ofw_fdt.c 
b/cpukit/libfreebsd/dev/ofw/ofw_fdt.c
index e4f72e8142..aba170d67a 100644
--- a/cpukit/libfreebsd/dev/ofw/ofw_fdt.c
+++ b/cpukit/libfreebsd/dev/ofw/ofw_fdt.c
@@ -30,9 +30,12 @@
  */
 
 #include 
+#ifndef __rtems__
 __FBSDID("$FreeBSD$");
+#endif /* __rtems__ */
 
 #include 
+#ifndef __rtems__
 #include 
 #include 
 #include 
@@ -45,9 +48,20 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#endif /* __rtems__ */
 
 #include "ofw_if.h"
 
+#ifdef __rtems__
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "openfirm.h"
+#endif /* __rtems__ */
+
+#ifndef __rtems__
 #ifdef DEBUG
 #define debugf(fmt, args...) do { printf("%s(): ", __func__);  \
 printf(fmt,##args); } while (0)
@@ -63,6 +77,7 @@ __FBSDID("$FreeBSD$");
 #define FDT_MARVELL
 #endif
 #endif
+#endif /* __rtems__ */
 
 static int ofw_fdt_init(ofw_t, void *);
 static phandle_t ofw_fdt_peer(ofw_t, phandle_t);
@@ -78,6 +93,7 @@ static ssize_t ofw_fdt_canon(ofw_t, const char *, char *, 
size_t);
 static phandle_t ofw_fdt_finddevice(ofw_t, const char *);
 static ssize_t ofw_fdt_instance_to_path(ofw_t, ihandle_t, char *, size_t);
 static ssize_t ofw_fdt_package_to_path(ofw_t, phandle_t, char *, size_t);
+#ifndef __rtems__
 static int ofw_fdt_interpret(ofw_t, const char *, int, cell_t *);
 
 static ofw_method_t ofw_fdt_methods[] = {
@@ -104,9 +120,11 @@ static ofw_def_t ofw_fdt = {
0
 };
 OFW_DEF(ofw_fdt);
+#endif /* __rtems__ */
 
 static void *fdtp = NULL;
 
+#ifndef __rtems__
 static int
 sysctl_handle_dtb(SYSCTL_HANDLER_ARGS)
 {
@@ -127,6 +145,27 @@ sysctl_register_fdt_oid(void *arg)
sysctl_handle_dtb, "", "Device Tree Blob");
 }
 SYSINIT(dtb_oid, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_fdt_oid, NULL);
+#else /* __rtems__ */
+const void* bsp_fdt_get(void);
+static void
+ofw_init(void)
+{
+   int rv;
+   const void *fdt;
+
+   fdt = bsp_fdt_get();
+   rv = ofw_fdt_init(NULL, fdt);
+
+   /* Fatal if invalid FDT is provided */
+   if (rv != 0)
+   bsp_fatal(LIBFREEBSD_FATAL_INVALID_FDT);
+}
+RTEMS_SYSINIT_ITEM(
+   ofw_init,
+   RTEMS_SYSINIT_BSP_START,
+   RTEMS_SYSINIT_ORDER_FIRST
+);
+#endif /* __rtems__ */
 
 static int
 ofw_fdt_init(ofw_t ofw, void *data)
@@ -297,7 +336,11 @@ ofw_fdt_getprop(ofw_t ofw, phandle_t package, const char 
*propname, void *buf,
if (prop == NULL)
return (-1);
 
+#ifndef __rtems__
bcopy(prop, buf, min(len, buflen));
+#else /* __rtems__ */
+   memcpy(buf, prop, MIN(len, buflen));
+#endif /* __rtems__ */
 
return (len);
 }
@@ -407,6 +450,7 @@ ofw_fdt_package_to_path(ofw_t ofw, phandle_t package, char 
*buf, size_t len)
return (-1);
 }
 
+#ifndef __rtems__
 #if defined(FDT_MARVELL)
 static int
 ofw_fdt_fixup(ofw_t ofw)
@@ -476,4 +520,104 @@ ofw_fdt_interpret(ofw_t ofw, const char *cmd, int nret, 
cell_t *retvals)
 #else
return (0);
 #endif
-}
\ No newline at end of file
+}
+#endif /* __rtems__ */
+
+#ifdef __rtems__
+int
+OFW_INIT(ofw_t ofw_obj, void *cookie)
+{
+
+   return (ofw_fdt_init(ofw_obj, cookie));
+}
+
+phandle_t
+OFW_PEER(ofw_t ofw_obj, phandle_t node)
+{
+
+   return (ofw_fdt_peer(ofw_obj, node));
+}
+
+phandle_t
+OFW_CHILD(ofw_t ofw_obj, phandle_t node)
+{
+
+   return (ofw_fdt_child(ofw_obj, node));
+}
+
+phandle_t
+OFW_PARENT(ofw_t ofw_obj, phandle_t node)
+{
+
+   return (ofw_fdt_parent(ofw_obj, node));
+}
+
+phandle_t
+OFW_INSTANCE_TO_PACKAGE(ofw_t ofw_obj, ihandle_t instance)
+{
+
+   return (ofw_fdt_instance_to_package(ofw_obj, instance));
+}
+
+ssize_t
+OFW_GETPROPLEN(ofw_t ofw_obj, phandle_t package, const char *propname)
+{
+
+   return (ofw_fdt_getproplen(ofw_obj, package, propname));
+}
+
+ssize_t
+OFW_GETPROP(ofw_t ofw_obj, phandle_t package, const char *propname,
+void *buf, size_t buflen
+)
+{
+
+   return (ofw_fdt_getprop(ofw_obj, package, propname, buf, buflen));
+}
+
+int
+OFW_NEXTPROP(ofw_t ofw_obj, phandle_t package, const char *prev, char *buf,
+size_t size)
+{
+
+   return (ofw_fdt_nextprop(ofw_obj, package, prev, buf, size));
+}
+
+int
+OFW_SETPROP(ofw_t ofw_obj, phandle_t package, const char *propname,
+const void *buf, size_t len)
+{
+
+   return (ofw_fdt_setprop(ofw_obj, package, propname, buf, len));
+}
+
+ssize_t
+OFW_CANON(ofw_t ofw_obj, const char *device, char *buf, size_t len)
+{
+
+   return (ofw_fdt_canon(ofw_obj, device, buf, len));
+}
+
+phandle_t
+OFW_FINDDEVICE(ofw_t ofw_obj, const char *device)
+{
+
+   return (ofw_fdt_finddevice(ofw_obj, device));
+}
+
+ssize_t
+OFW_INSTANCE_TO_PATH(ofw_t ofw_obj, ihandl

[PATCH RTEMS v2 3/6] libfreebsd: FreeBSD porting helper header

2020-06-11 Thread G S Niteesh Babu
This file serve the purpose as rtems-bsd-kernel-space.h in the
rtems-libbsd.
This file is intended to be included in every source file that
is to imported from FreeBSD. This is to reduce the number of
redefinitions for commonly used functions like malloc, free
and KASSERT.
---
 cpukit/libfreebsd/rtems-freebsd-helper.h | 47 
 1 file changed, 47 insertions(+)
 create mode 100644 cpukit/libfreebsd/rtems-freebsd-helper.h

diff --git a/cpukit/libfreebsd/rtems-freebsd-helper.h 
b/cpukit/libfreebsd/rtems-freebsd-helper.h
new file mode 100644
index 00..d6edd6a01e
--- /dev/null
+++ b/cpukit/libfreebsd/rtems-freebsd-helper.h
@@ -0,0 +1,47 @@
+
+/* SPDX-License-Identifier: BSD-2-Clause
+
+ *
+ * @file
+ *
+ * @ingroup LIBFREEBSD
+ *
+ * @brief
+ */
+
+/*
+ * Copyright (C) <2020> Niteesh Babu 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H
+#define _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H
+#include 
+#include 
+
+#define_KERNEL 1
+#defineKASSERT(cnd, msg)   assert(cnd)
+#definemalloc(size, type, flags)   malloc(size)
+#definefree(addr, type)free(addr)
+
+#endif /* _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H */
\ No newline at end of file
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] bsp/fdt.h: Move bsp/fdt.h to cpukit

2020-07-02 Thread G S Niteesh Babu
This commit move the bsp/fdt.h header to cpukit/include/rtems.
The reason for this is, with inclusion of libfreebsd there are
cases where their is need for bsp_fdt_get(). And with this
header under bsps directory it is not possible to include it
under a cpukit directory.
---
 bsps/include/bsp/fdt.h | 86 +-
 cpukit/include/rtems/fdt.h | 69 ++
 2 files changed, 99 insertions(+), 56 deletions(-)
 create mode 100644 cpukit/include/rtems/fdt.h

diff --git a/bsps/include/bsp/fdt.h b/bsps/include/bsp/fdt.h
index 4ed05b136c..4a7c3dfb24 100644
--- a/bsps/include/bsp/fdt.h
+++ b/bsps/include/bsp/fdt.h
@@ -1,67 +1,41 @@
-/*
- * Copyright (c) 2015, 2017 embedded brains GmbH.  All rights reserved.
- *
- *  embedded brains GmbH
- *  Dornierstr. 4
- *  82178 Puchheim
- *  Germany
- *  
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
- */
-
-#ifndef LIBBSP_SHARED_FDT_H
-#define LIBBSP_SHARED_FDT_H
-
-#include 
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-/*
- * BSPs that implement the FDT support functions must define
- * BSP_FDT_IS_SUPPORTED.
- */
+/* SPDX-License-Identifier: BSD-2-Clause */
 
 /**
- * @brief Copies the specified source FDT to a dedicated global data area.
+ * @file
  *
- * The source FDT is usually provided by a bootloader and may be located in a
- * memory area that is used by the program.  The low-level initialization
- * should copy the FDT for later use.
+ * @ingroup RTEMSBSPsShared
  *
- * The copy can be accessed by bsp_fdt_get().
- *
- * @param[in] src The source FDT.
  */
-void bsp_fdt_copy(const void *src);
 
-/**
- * @brief Returns the FDT of the BSP.
- *
- * @return The FDT of the BSP.
+/*
+ * Copyright (C) <2020>, Niteesh G S 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
  */
-const void *bsp_fdt_get(void);
 
-/**
- * @brief Maps the interrupt number of the FDT to the interrupt vector used by
- * the interrupt management.
- *
- * This function is used by the libbsd to implement the OFW_BUS_MAP_INTR bus
- * method.
- *
- * @param[in] intr The FDT interrupt number cells.
- * @param[in] icells The FDT interrupt cell count.
- *
- * @return The interrupt vector of the FDT interrupt number.
- */
-uint32_t bsp_fdt_map_intr(const uint32_t *intr, size_t icells);
+#ifndef LIBBSP_SHARED_FDT_H
+#define LIBBSP_SHARED_FDT_H
 
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+#include 
+#include 
 
 #endif /* LIBBSP_SHARED_FDT_H */
diff --git a/cpukit/include/rtems/fdt.h b/cpukit/include/rtems/fdt.h
new file mode 100644
index 00..149f7ff906
--- /dev/null
+++ b/cpukit/include/rtems/fdt.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2015, 2017 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  
+ *
+ * Modified by Niteesh G S 
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifndef RTEMS_FDT_H
+#define RTEMS_FDT_H
+
+#include 
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ * BSPs that implement the FDT support functions must define
+ * BSP_FDT_IS_SUPPORTED.
+ */
+
+/**
+ * @brief Copies the specified source FDT to a dedicated global data area.
+ *
+ * The source FDT is usually provided by a bootloader and may be located in a
+ * memory area that is used by the program.  The low-level initialization
+ * should copy the FDT for later use.
+ *
+ * The copy can be accessed by bsp_fdt_get().
+ *
+ * @param[in] src The source FDT.
+ */

[PATCH] eng: fix typo in coding-file-hdr.rst

2020-07-02 Thread G S Niteesh Babu
---
 eng/coding-file-hdr.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/eng/coding-file-hdr.rst b/eng/coding-file-hdr.rst
index 6355173..cda631a 100644
--- a/eng/coding-file-hdr.rst
+++ b/eng/coding-file-hdr.rst
@@ -96,7 +96,7 @@ Use the following guidelines and template for C and C++ 
header files (here
 
 .. code-block:: c
 
-/* SPDX-License-Identifier: BSD-2-Clause
+/* SPDX-License-Identifier: BSD-2-Clause */
 
 /**
  * @file
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH RTEMS 1/7] bsp/fdt.h: Move bsp/fdt.h to cpukit

2020-07-14 Thread G S Niteesh Babu
This commit move the bsp/fdt.h header to cpukit/include/rtems.
The reason for this is, with inclusion of libfreebsd there are
cases where their is need for bsp_fdt_get(). And with this
header under bsps directory it is not possible to include it
under a cpukit directory.
---
 bsps/include/bsp/fdt.h| 86 +++
 cpukit/include/rtems/fdt.h| 69 +
 spec/build/cpukit/librtemscpu.yml |  1 +
 3 files changed, 100 insertions(+), 56 deletions(-)
 create mode 100644 cpukit/include/rtems/fdt.h

diff --git a/bsps/include/bsp/fdt.h b/bsps/include/bsp/fdt.h
index 4ed05b136c..4a7c3dfb24 100644
--- a/bsps/include/bsp/fdt.h
+++ b/bsps/include/bsp/fdt.h
@@ -1,67 +1,41 @@
-/*
- * Copyright (c) 2015, 2017 embedded brains GmbH.  All rights reserved.
- *
- *  embedded brains GmbH
- *  Dornierstr. 4
- *  82178 Puchheim
- *  Germany
- *  
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rtems.org/license/LICENSE.
- */
-
-#ifndef LIBBSP_SHARED_FDT_H
-#define LIBBSP_SHARED_FDT_H
-
-#include 
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-/*
- * BSPs that implement the FDT support functions must define
- * BSP_FDT_IS_SUPPORTED.
- */
+/* SPDX-License-Identifier: BSD-2-Clause */
 
 /**
- * @brief Copies the specified source FDT to a dedicated global data area.
+ * @file
  *
- * The source FDT is usually provided by a bootloader and may be located in a
- * memory area that is used by the program.  The low-level initialization
- * should copy the FDT for later use.
+ * @ingroup RTEMSBSPsShared
  *
- * The copy can be accessed by bsp_fdt_get().
- *
- * @param[in] src The source FDT.
  */
-void bsp_fdt_copy(const void *src);
 
-/**
- * @brief Returns the FDT of the BSP.
- *
- * @return The FDT of the BSP.
+/*
+ * Copyright (C) <2020>, Niteesh G S 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
  */
-const void *bsp_fdt_get(void);
 
-/**
- * @brief Maps the interrupt number of the FDT to the interrupt vector used by
- * the interrupt management.
- *
- * This function is used by the libbsd to implement the OFW_BUS_MAP_INTR bus
- * method.
- *
- * @param[in] intr The FDT interrupt number cells.
- * @param[in] icells The FDT interrupt cell count.
- *
- * @return The interrupt vector of the FDT interrupt number.
- */
-uint32_t bsp_fdt_map_intr(const uint32_t *intr, size_t icells);
+#ifndef LIBBSP_SHARED_FDT_H
+#define LIBBSP_SHARED_FDT_H
 
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
+#include 
+#include 
 
 #endif /* LIBBSP_SHARED_FDT_H */
diff --git a/cpukit/include/rtems/fdt.h b/cpukit/include/rtems/fdt.h
new file mode 100644
index 00..149f7ff906
--- /dev/null
+++ b/cpukit/include/rtems/fdt.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2015, 2017 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  
+ *
+ * Modified by Niteesh G S 
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifndef RTEMS_FDT_H
+#define RTEMS_FDT_H
+
+#include 
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/*
+ * BSPs that implement the FDT support functions must define
+ * BSP_FDT_IS_SUPPORTED.
+ */
+
+/**
+ * @brief Copies the specified source FDT to a dedicated global data area.
+ *
+ * The source FDT is usually provided by a bootloader and may be located in a
+ * memory area that is used by the program.  The low-level initialization
+ * should copy the FDT for later use.
+ *
+ * The copy can be accessed by bsp_fdt_get().

[PATCH RTEMS 4/7] libfreebsd: FreeBSD porting helper header

2020-07-14 Thread G S Niteesh Babu
This file serve the purpose as rtems-bsd-kernel-space.h in the
rtems-libbsd.
This file is intended to be included in every source file that
is to imported from FreeBSD. This is to reduce the number of
redefinitions for commonly used functions like malloc, free
and KASSERT.
---
 cpukit/libfreebsd/rtems-freebsd-helper.h | 47 
 1 file changed, 47 insertions(+)
 create mode 100644 cpukit/libfreebsd/rtems-freebsd-helper.h

diff --git a/cpukit/libfreebsd/rtems-freebsd-helper.h 
b/cpukit/libfreebsd/rtems-freebsd-helper.h
new file mode 100644
index 00..963f56b1f8
--- /dev/null
+++ b/cpukit/libfreebsd/rtems-freebsd-helper.h
@@ -0,0 +1,47 @@
+
+/* SPDX-License-Identifier: BSD-2-Clause
+
+ *
+ * @file
+ *
+ * @ingroup LIBFREEBSD
+ *
+ * @brief
+ */
+
+/*
+ * Copyright (C) <2020> Niteesh Babu 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H
+#define _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H
+#include 
+#include 
+
+#define _KERNEL1
+#define KASSERT(cnd, msg)  assert(cnd)
+#define malloc(size, type, flags)  malloc(size)
+#define free(addr, type)   free(addr)
+
+#endif /* _LIBFREEBSD_RTEMS_FREEBSD_HELPER_H */
\ No newline at end of file
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH RTEMS 3/7] libfreebsd: Added ofw_if.h

2020-07-14 Thread G S Niteesh Babu
This file is the RTEMS implementation of ofw_if.h in FreeBSD. The
ofw_if.h in FreeBSD is an autogenerated header file that maps the
OF_function calls to their respective implementation. But in RTEMS
this file maps the OF_functions directly to their FDT implementation.
---
 cpukit/libfreebsd/freebsd/dev/ofw/ofw_if.h | 62 ++
 1 file changed, 62 insertions(+)
 create mode 100644 cpukit/libfreebsd/freebsd/dev/ofw/ofw_if.h

diff --git a/cpukit/libfreebsd/freebsd/dev/ofw/ofw_if.h 
b/cpukit/libfreebsd/freebsd/dev/ofw/ofw_if.h
new file mode 100644
index 00..f66c02884e
--- /dev/null
+++ b/cpukit/libfreebsd/freebsd/dev/ofw/ofw_if.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: BSD-2-Clause
+
+ *
+ * @file
+ *
+ * @ingroup LIBFREEBSD
+ *
+ * @brief Declaration of OFW functions.
+ */
+
+/*
+ * Copyright (C) <2020> Niteesh Babu 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LIBFREEBSD_OFW_IF_H
+#define _LIBFREEBSD_OFW_IF_H
+
+#include 
+
+typedef void*  ofw_t;
+
+int OFW_INIT(ofw_t ofw_obj, void *cookie);
+phandle_t OFW_PEER(ofw_t ofw_obj, phandle_t node);
+phandle_t OFW_CHILD(ofw_t ofw_obj, phandle_t node);
+phandle_t OFW_PARENT(ofw_t ofw_obj, phandle_t node);
+phandle_t OFW_INSTANCE_TO_PACKAGE(ofw_t ofw_obj, ihandle_t instance);
+ssize_t OFW_GETPROPLEN(ofw_t ofw_obj, phandle_t package, const char *propname);
+ssize_t OFW_GETPROP(ofw_t ofw_obj, phandle_t package, const char *propname,
+   void *buf, size_t buflen);
+int OFW_NEXTPROP(ofw_t ofw_obj, phandle_t package, const char *prev, char *buf,
+   size_t size);
+int OFW_SETPROP(ofw_t ofw_obj, phandle_t package, const char *propname,
+   const void *buf, size_t len);
+ssize_t OFW_CANON(ofw_t ofw_obj, const char *device, char *buf, size_t len);
+phandle_t OFW_FINDDEVICE(ofw_t ofw_obj, const char *device);
+ssize_t OFW_INSTANCE_TO_PATH(ofw_t ofw_obj, ihandle_t instance, char *buf,
+   size_t len);
+ssize_t OFW_PACKAGE_TO_PATH(ofw_t ofw_obj, phandle_t package, char *buf,
+   size_t len);
+
+#endif /* _LIBFREEBSD_OFW_IF_H */
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH RTEMS 7/7] libtests/openfirmware: Added a testsuite for openfirmware

2020-07-14 Thread G S Niteesh Babu
---
 spec/build/testsuites/libtests/grp.yml|   3 +
 .../testsuites/libtests/openfirmware01.yml|  20 +++
 testsuites/libtests/openfirmware01/init.c | 147 ++
 .../openfirmware01/openfirmware01.doc |  29 
 .../openfirmware01/openfirmware01.scn |   2 +
 testsuites/libtests/openfirmware01/some.c |  52 +++
 testsuites/libtests/openfirmware01/some.dts   |  54 +++
 testsuites/libtests/openfirmware01/some.h |  15 ++
 8 files changed, 322 insertions(+)
 create mode 100644 spec/build/testsuites/libtests/openfirmware01.yml
 create mode 100644 testsuites/libtests/openfirmware01/init.c
 create mode 100644 testsuites/libtests/openfirmware01/openfirmware01.doc
 create mode 100644 testsuites/libtests/openfirmware01/openfirmware01.scn
 create mode 100644 testsuites/libtests/openfirmware01/some.c
 create mode 100644 testsuites/libtests/openfirmware01/some.dts
 create mode 100644 testsuites/libtests/openfirmware01/some.h

diff --git a/spec/build/testsuites/libtests/grp.yml 
b/spec/build/testsuites/libtests/grp.yml
index f1de6cd75f..56e84d2c89 100644
--- a/spec/build/testsuites/libtests/grp.yml
+++ b/spec/build/testsuites/libtests/grp.yml
@@ -11,6 +11,7 @@ install: []
 ldflags:
 - -Wl,--wrap=printf
 - -Wl,--wrap=puts
+- -Wl,--wrap=bsp_fdt_get
 links:
 - role: build-dependency
   uid: optbin2c
@@ -312,6 +313,8 @@ links:
   uid: write
 - role: build-dependency
   uid: writev
+- role: build-dependency
+  uid: openfirmware01
 type: build
 use-after:
 - rtemstest
diff --git a/spec/build/testsuites/libtests/openfirmware01.yml 
b/spec/build/testsuites/libtests/openfirmware01.yml
new file mode 100644
index 00..8feb69eb1e
--- /dev/null
+++ b/spec/build/testsuites/libtests/openfirmware01.yml
@@ -0,0 +1,20 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+build-type: test-program
+cflags: []
+copyrights:
+- Copyright (C) 2020 Niteesh G S
+cppflags: []
+cxxflags: []
+enabled-by: true
+features: c cprogram
+includes: []
+ldflags: []
+links: []
+source:
+- testsuites/libtests/openfirmware01/init.c
+- testsuites/libtests/openfirmware01/some.c
+stlib: []
+target: testsuites/libtests/openfirmware01.exe
+type: build
+use-after: []
+use-before: []
diff --git a/testsuites/libtests/openfirmware01/init.c 
b/testsuites/libtests/openfirmware01/init.c
new file mode 100644
index 00..fc38e6c513
--- /dev/null
+++ b/testsuites/libtests/openfirmware01/init.c
@@ -0,0 +1,147 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) <2020> Niteesh G S 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "some.h"
+
+#define BUF_SIZE 100
+
+const char rtems_test_name[] = "OpenFirmWare 01";
+
+const void *__wrap_bsp_fdt_get(void);
+const void *__real_bsp_fdt_get(void);
+
+const void *__wrap_bsp_fdt_get(void)
+{
+if (some_bin != NULL) {
+return &some_bin[0];
+}
+return __real_bsp_fdt_get();
+}
+
+static void Init(rtems_task_argument arg)
+{
+int rv;
+phandle_t d;
+phandle_t l;
+phandle_t t;
+phandle_t root;
+phandle_t temp;
+uint32_t *arr;
+char buf[BUF_SIZE];
+char *bufp;
+ssize_t buf_len;
+
+TEST_BEGIN();
+buf_len = sizeof(buf);
+
+/*
+ * Cannot use fdt_path_offset to compare because
+ * the OF interface uses the offset from the ftdp
+ * to the node as phandle.
+ */
+root = OF_finddevice("/");
+rtems_test_assert(root == 56);
+
+root = OF_peer(0);
+rtems_test_assert(root == 56);
+
+d = OF_child(root);
+temp = OF_finddevice("/d");
+rtems_test_assert(d == temp);

[PATCH RTEMS 5/7] libfreebsd: Port OFW to RTEMS

2020-07-14 Thread G S Niteesh Babu
The following files have been ported to RTEMS
1) openfirm.h
2) openfirm.c
3) ofw_fdt.c
---
 cpukit/include/dev/ofw/openfirm.h|  16 ++
 cpukit/libfreebsd/freebsd/dev/ofw/ofw_fdt.c  | 149 ++-
 cpukit/libfreebsd/freebsd/dev/ofw/openfirm.c |  58 +++-
 3 files changed, 221 insertions(+), 2 deletions(-)

diff --git a/cpukit/include/dev/ofw/openfirm.h 
b/cpukit/include/dev/ofw/openfirm.h
index 74a7075367..b9a1394fe6 100644
--- a/cpukit/include/dev/ofw/openfirm.h
+++ b/cpukit/include/dev/ofw/openfirm.h
@@ -63,7 +63,9 @@
 #define _DEV_OPENFIRM_H_
 
 #include 
+#ifndef __rtems__
 #include 
+#endif /* __rtems__ */
 
 /*
  * Prototypes for Open Firmware Interface Routines
@@ -73,7 +75,14 @@ typedef uint32_t ihandle_t;
 typedef uint32_t   phandle_t;
 typedef uint32_t   pcell_t;
 
+#ifdef __rtems__
+#define _KERNEL1
+typedef struct device  *device_t;
+typedef uint32_t   cell_t;
+#endif /* __rtems__ */
+
 #ifdef _KERNEL
+#ifndef __rtems__
 #include 
 
 #include 
@@ -86,8 +95,10 @@ MALLOC_DECLARE(M_OFWPROP);
  */
 
 boolean_t  OF_install(char *name, int prio);
+#endif /* __rtems__*/
 intOF_init(void *cookie);
 
+#ifndef __rtems__
 /*
  * Known Open Firmware interface names
  */
@@ -100,6 +111,7 @@ int OF_init(void *cookie);
 /* Generic functions */
 intOF_test(const char *name);
 void   OF_printf(const char *fmt, ...);
+#endif /* __rtems__ */
 
 /* Device tree functions */
 phandle_t  OF_peer(phandle_t node);
@@ -152,15 +164,18 @@ device_t  OF_device_from_xref(phandle_t xref);
 phandle_t  OF_xref_from_device(device_t dev);
 intOF_device_register_xref(phandle_t xref, device_t dev);
 
+#ifndef __rtems__
 /* Device I/O functions */
 ihandle_t  OF_open(const char *path);
 void   OF_close(ihandle_t instance);
 ssize_tOF_read(ihandle_t instance, void *buf, size_t len);
 ssize_tOF_write(ihandle_t instance, const void *buf, size_t 
len);
 intOF_seek(ihandle_t instance, uint64_t where);
+#endif /* __rtems__ */
 
 phandle_t  OF_instance_to_package(ihandle_t instance);
 ssize_tOF_instance_to_path(ihandle_t instance, char *buf, 
size_t len);
+#ifndef __rtems__
 intOF_call_method(const char *method, ihandle_t instance,
int nargs, int nreturns, ...);
 
@@ -183,5 +198,6 @@ int OF_interpret(const char *cmd, int nreturns, 
...);
 intOF_decode_addr(phandle_t dev, int regno, bus_space_tag_t *ptag,
bus_space_handle_t *phandle, bus_size_t *sz);
 
+#endif /* __rtems__ */
 #endif /* _KERNEL */
 #endif /* _DEV_OPENFIRM_H_ */
\ No newline at end of file
diff --git a/cpukit/libfreebsd/freebsd/dev/ofw/ofw_fdt.c 
b/cpukit/libfreebsd/freebsd/dev/ofw/ofw_fdt.c
index e4f72e8142..30d0d111c6 100644
--- a/cpukit/libfreebsd/freebsd/dev/ofw/ofw_fdt.c
+++ b/cpukit/libfreebsd/freebsd/dev/ofw/ofw_fdt.c
@@ -30,9 +30,12 @@
  */
 
 #include 
+#ifndef __rtems__
 __FBSDID("$FreeBSD$");
+#endif /* __rtems__ */
 
 #include 
+#ifndef __rtems__
 #include 
 #include 
 #include 
@@ -43,11 +46,24 @@ __FBSDID("$FreeBSD$");
 
 #include 
 #include 
+#endif /* __rtems__ */
 #include 
+#ifndef __rtems__
 #include 
+#endif /* __rtems__ */
 
 #include "ofw_if.h"
 
+#ifdef __rtems__
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#endif /* __rtems__ */
+
+#ifndef __rtems__
 #ifdef DEBUG
 #define debugf(fmt, args...) do { printf("%s(): ", __func__);  \
 printf(fmt,##args); } while (0)
@@ -63,6 +79,7 @@ __FBSDID("$FreeBSD$");
 #define FDT_MARVELL
 #endif
 #endif
+#endif /* __rtems__ */
 
 static int ofw_fdt_init(ofw_t, void *);
 static phandle_t ofw_fdt_peer(ofw_t, phandle_t);
@@ -78,6 +95,7 @@ static ssize_t ofw_fdt_canon(ofw_t, const char *, char *, 
size_t);
 static phandle_t ofw_fdt_finddevice(ofw_t, const char *);
 static ssize_t ofw_fdt_instance_to_path(ofw_t, ihandle_t, char *, size_t);
 static ssize_t ofw_fdt_package_to_path(ofw_t, phandle_t, char *, size_t);
+#ifndef __rtems__
 static int ofw_fdt_interpret(ofw_t, const char *, int, cell_t *);
 
 static ofw_method_t ofw_fdt_methods[] = {
@@ -104,9 +122,11 @@ static ofw_def_t ofw_fdt = {
0
 };
 OFW_DEF(ofw_fdt);
+#endif /* __rtems__ */
 
 static void *fdtp = NULL;
 
+#ifndef __rtems__
 static int
 sysctl_handle_dtb(SYSCTL_HANDLER_ARGS)
 {
@@ -127,6 +147,28 @@ sysctl_register_fdt_oid(void *arg)
sysctl_handle_dtb, "", "Device Tree Blob");
 }
 SYSINIT(dtb_oid, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_register_fdt_oid, NULL);
+#else /* __rtems__ */
+static void
+ofw_init(void)
+{
+   int rv;
+   const void *fdt;
+
+   fdt = bsp_fdt_get();
+   rv = ofw_fdt_init(NULL, (void *)fdt);
+
+   /* Fatal if invalid FDT is provided */
+   if (rv != 0) {
+   printk("Invalid FDT provided");
+   rtems_fatal_error_occurred(RTEMS_NOT_CONFIGURED);
+   }
+}
+RTEMS_SYSINIT_ITEM(
+   ofw

[PATCH RTEMS 2/7] libfreebsd: Import OFW files from FreeBSD.

2020-07-14 Thread G S Niteesh Babu
freebsd head: b8c57b4

The following files have been imported from FreeBSD to implement
OF_* functions into RTEMS.
1) openfirm.h
2) openfirm.c
3) ofw_fdt.c
---
 cpukit/include/dev/ofw/openfirm.h| 187 
 cpukit/libfreebsd/freebsd/dev/ofw/ofw_fdt.c  | 479 +++
 cpukit/libfreebsd/freebsd/dev/ofw/openfirm.c | 848 +++
 3 files changed, 1514 insertions(+)
 create mode 100644 cpukit/include/dev/ofw/openfirm.h
 create mode 100644 cpukit/libfreebsd/freebsd/dev/ofw/ofw_fdt.c
 create mode 100644 cpukit/libfreebsd/freebsd/dev/ofw/openfirm.c

diff --git a/cpukit/include/dev/ofw/openfirm.h 
b/cpukit/include/dev/ofw/openfirm.h
new file mode 100644
index 00..74a7075367
--- /dev/null
+++ b/cpukit/include/dev/ofw/openfirm.h
@@ -0,0 +1,187 @@
+/* $NetBSD: openfirm.h,v 1.1 1998/05/15 10:16:00 tsubai Exp $  */
+
+/*-
+ * SPDX-License-Identifier: (BSD-4-Clause AND BSD-2-Clause-FreeBSD)
+ *
+ * Copyright (C) 1995, 1996 Wolfgang Solfrank.
+ * Copyright (C) 1995, 1996 TooLs GmbH.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *must display the following acknowledgement:
+ * This product includes software developed by TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ *derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+/*
+ * Copyright (C) 2000 Benno Rice.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _DEV_OPENFIRM_H_
+#define _DEV_OPENFIRM_H_
+
+#include 
+#include 
+
+/*
+ * Prototypes for Open Firmware Interface Routines
+ */
+
+typedef uint32_t   ihandle_t;
+typedef uint32_t   phandle_t;
+typedef uint32_t   pcell_t;
+
+#ifdef _KERNEL
+#include 
+
+#include 
+
+MALLOC_DECLARE(M_OFWPROP);
+
+/*
+ * Open Firmware interface initialization.  OF_install installs the named
+ * interface as the Open Firmware access mechanism, OF_init initializes it.
+ */
+
+boolean_t  OF_install(char *name, int prio);
+intOF_init(void *cookie);
+
+/*
+ * Known Open Firmware interface names
+ */
+
+#defineOFW_STD_DIRECT  "ofw_std"   /* Standard OF interface */
+#defineOFW_STD_REAL"ofw_real"  /* Real-mode OF interface */
+#defineOFW_STD_32BIT   "ofw_32bit" /* 32-bit OF interface */
+#defineOFW_FDT "ofw_fdt"   /* Flattened Device Tree */
+
+/* Generic functions */
+intO

[PATCH RTEMS 6/7] spec/build/cpukit: Added spec file for OpenFirmWare

2020-07-14 Thread G S Niteesh Babu
---
 spec/build/cpukit/librtemscpu.yml |  5 +
 spec/build/cpukit/objfreebsd.yml  | 17 +
 2 files changed, 22 insertions(+)
 create mode 100644 spec/build/cpukit/objfreebsd.yml

diff --git a/spec/build/cpukit/librtemscpu.yml 
b/spec/build/cpukit/librtemscpu.yml
index 403662b97d..6d0aef654b 100644
--- a/spec/build/cpukit/librtemscpu.yml
+++ b/spec/build/cpukit/librtemscpu.yml
@@ -33,6 +33,9 @@ install:
 - destination: ${BSP_INCLUDEDIR}/arpa
   source:
   - cpukit/include/arpa/ftp.h
+- destination: ${BSP_INCLUDEDIR}/dev/ofw
+  source:
+  - cpukit/include/dev/ofw/openfirm.h
 - destination: ${BSP_INCLUDEDIR}/dev/i2c
   source:
   - cpukit/include/dev/i2c/eeprom.h
@@ -511,6 +514,8 @@ links:
   uid: objutf8
 - role: build-dependency
   uid: vckey
+- role: build-dependency
+  uid: objfreebsd
 source:
 - cpukit/dev/i2c/eeprom.c
 - cpukit/dev/i2c/fpga-i2c-slave.c
diff --git a/spec/build/cpukit/objfreebsd.yml b/spec/build/cpukit/objfreebsd.yml
new file mode 100644
index 00..02fe9b557e
--- /dev/null
+++ b/spec/build/cpukit/objfreebsd.yml
@@ -0,0 +1,17 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+build-type: objects
+cflags: []
+copyrights:
+- Copyright (C) 2020 Niteesh Babu G S 
+cppflags: []
+cxxflags: []
+enabled-by: true
+includes:
+- cpukit/libfreebsd
+- cpukit/libfreebsd/freebsd
+install: []
+links: []
+source:
+- cpukit/libfreebsd/freebsd/dev/ofw/openfirm.c
+- cpukit/libfreebsd/freebsd/dev/ofw/ofw_fdt.c
+type: build
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


GSoC 2020 PATCH: Import OpenFirmWare API to RTEMS

2020-07-14 Thread G S Niteesh Babu
Hello,
This series of patches import OpenFirmWare to RTEMS from FreeBSD. These
patches are based on the new build system, so it will require the person
building this patch to pull Sebastian's 'build' branch from his git
repo.

Sebastian's git repo: https://git.rtems.org/sebh/rtems.git/log/?h=build

And the instructions to build RTEMS with the new build system can be
found here: https://ftp.rtems.org/pub/rtems/people/sebh/user.pdf


 bsps/include/bsp/fdt.h|  86 
 cpukit/include/dev/ofw/openfirm.h | 203 
+++
 cpukit/include/rtems/fdt.h|  69 +
 cpukit/libfreebsd/freebsd/dev/ofw/ofw_fdt.c   | 626 
+
 cpukit/libfreebsd/freebsd/dev/ofw/ofw_if.h|  62 
 cpukit/libfreebsd/freebsd/dev/ofw/openfirm.c  | 904 
+
 cpukit/libfreebsd/rtems-freebsd-helper.h  |  47 +++
 spec/build/cpukit/librtemscpu.yml |   6 +
 spec/build/cpukit/objfreebsd.yml  |  17 +++
 spec/build/testsuites/libtests/grp.yml|   3 +
 spec/build/testsuites/libtests/openfirmware01.yml |  20 +++
 testsuites/libtests/openfirmware01/init.c | 147 +++
 testsuites/libtests/openfirmware01/openfirmware01.doc |  29 
 testsuites/libtests/openfirmware01/openfirmware01.scn |   2 +
 testsuites/libtests/openfirmware01/some.c |  52 +++
 testsuites/libtests/openfirmware01/some.dts   |  54 +++
 testsuites/libtests/openfirmware01/some.h |  15 ++
 17 files changed, 2286 insertions(+), 56 deletions(-)
 create mode 100644 cpukit/include/dev/ofw/openfirm.h
 create mode 100644 cpukit/include/rtems/fdt.h
 create mode 100644 cpukit/libfreebsd/freebsd/dev/ofw/ofw_fdt.c
 create mode 100644 cpukit/libfreebsd/freebsd/dev/ofw/ofw_if.h
 create mode 100644 cpukit/libfreebsd/freebsd/dev/ofw/openfirm.c
 create mode 100644 cpukit/libfreebsd/rtems-freebsd-helper.h
 create mode 100644 spec/build/cpukit/objfreebsd.yml
 create mode 100644 spec/build/testsuites/libtests/openfirmware01.yml
 create mode 100644 testsuites/libtests/openfirmware01/init.c
 create mode 100644
testsuites/libtests/openfirmware01/openfirmware01.doc
 create mode 100644
testsuites/libtests/openfirmware01/openfirmware01.scn
 create mode 100644 testsuites/libtests/openfirmware01/some.c
 create mode 100644 testsuites/libtests/openfirmware01/some.dts
 create mode 100644 testsuites/libtests/openfirmware01/some.h



___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] bsps/shared/ofw: Added and Documented RTEMS OFW interface

2020-08-12 Thread G S Niteesh Babu
---
 bsps/shared/dev/ofw/ofw.c |   0
 bsps/shared/dev/ofw/ofw.h | 437 ++
 2 files changed, 437 insertions(+)
 create mode 100644 bsps/shared/dev/ofw/ofw.c
 create mode 100644 bsps/shared/dev/ofw/ofw.h

diff --git a/bsps/shared/dev/ofw/ofw.c b/bsps/shared/dev/ofw/ofw.c
new file mode 100644
index 00..e69de29bb2
diff --git a/bsps/shared/dev/ofw/ofw.h b/bsps/shared/dev/ofw/ofw.h
new file mode 100644
index 00..5a8526c892
--- /dev/null
+++ b/bsps/shared/dev/ofw/ofw.h
@@ -0,0 +1,437 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup ofw
+ *
+ * RTEMS FDT implementation of OpenFirmWare Interface.
+ */
+
+/*
+ * Copyright (C) <2020> Niteesh Babu G S 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _OFW_H
+#define _OFW_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include 
+#include 
+
+typedef uint32_t  ihandle_t;
+typedef uint32_t  pcell_t;
+typedef uint32_t  phandle_t;
+
+/**
+ * @brief Gets the node that is next to @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval Peer node offset Successful operation.
+ * @retval 0 No peer node or invalid node handle
+ */
+phandle_t rtems_ofw_peer(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the node that is the child of @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval child node offset Successful operation.
+ * @retval 0 No child node or invalid node handle
+ */
+phandle_t rtems_ofw_child(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the node that is the parent of @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval child node offset Successful operation.
+ * @retval 0 No child node or invalid node handle
+ */
+phandle_t rtems_ofw_parent(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the length of the property mentioned in @a propname.
+ *
+ * @param[in] node Node offset
+ * @param[in] prop Property name
+ *
+ * @retval -1 Invalid node or property
+ * @retval  Length of property on successful operation
+ */
+size_t rtems_ofw_getproplen(
+  phandle_t   node,
+  const char *propname
+);
+
+
+/**
+ * @brief Gets the value of property mentioned in @a propname.
+ *
+ * @param[in] node Node offset
+ * @param[in] prop Property name
+ * @param[out] buf The property value gets stored in this buffer 
(Pre-allocated)
+ * @param[in] len Length of the buffer
+ 
+ * @retval -1 Invalid node or property
+ * @retval  Length of property on successful operation
+ */
+size_t rtems_ofw_getprop(
+  phandle_tnode,
+  const char  *propname,
+  void*buf,
+  size_t   len
+);
+
+/**
+ * @brief Gets the value of property mentioned in @a propname.
+ * 
+ * Gets the value of property of @a node and converts the value into the host's
+ * endiannes.
+ *
+ * @param[in] node Node offset
+ * @param[in] prop Property name
+ * @param[out] buf The property value gets stored in this buffer(Pre-allocated)
+ * after converted to the host's endiannes
+ * @param[in] len Length of the buffer
+ *
+ * @retval -1 Invalid node or property
+ * @retval  Length of property on successful operation
+ */
+size_t rtems_ofw_getencprop(
+  phandle_tnode,
+  const char  *prop,
+  pcell_t *buf,
+  size_t   len
+);
+
+/**
+ * @brief Checks if the property @a propname is present in @a node.
+ *
+ * @param[in] node Node offset
+ * @param[in] propname Property name
+ *
+ *  @retval  0 Property not present.
+ *  @retval  1 Property is present.
+ */
+int rtems_ofw_hasprop(
+  phandle_tnode,
+  const char  *propname
+);
+
+/**
+ * @brief Searches for property @a propname in @a node.
+ * 
+ * Searches the node and its parent recursively for the property and fills the
+ * buffer with the first found value.
+ *
+ * @param[i

[PATCH] bsps/shared/ofw: Implement RTEMS OFW interface

2020-08-15 Thread G S Niteesh Babu
---
 bsps/include/ofw/ofw.h  | 534 
 bsps/shared/ofw/ofw.c   | 654 
 spec/build/bsps/obj.yml |   4 +
 3 files changed, 1192 insertions(+)
 create mode 100644 bsps/include/ofw/ofw.h
 create mode 100644 bsps/shared/ofw/ofw.c

diff --git a/bsps/include/ofw/ofw.h b/bsps/include/ofw/ofw.h
new file mode 100644
index 00..2ca5328abc
--- /dev/null
+++ b/bsps/include/ofw/ofw.h
@@ -0,0 +1,534 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup ofw
+ *
+ * RTEMS FDT implementation of OpenFirmWare Interface.
+ *
+ * RTEMS OFW is a FDT only implementation of the OpenFirmWare interface.
+ * This API is created to be compatible with FreeBSD OpenFirmWare interface.
+ * The main intention is to make porting of FreeBSD drivers to RTEMS easier.
+ */
+
+/*
+ * Copyright (C) 2020 Niteesh Babu G S 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _OFW_H
+#define _OFW_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include 
+#include 
+
+/**
+ * Represents a node in the device tree. The offset from fdtp to node is used
+ * instead of fdt offset to make sure this is compatible with OF interface in
+ * FreeBSD.
+ */
+typedef uint32_t  phandle_t;
+/**
+ * Represents the effective phandle of the node.
+ */
+typedef uint32_t  ihandle_t;
+/**
+ * Represents the data type of the buffer.
+ */
+typedef uint32_t  pcell_t;
+
+/**
+ * @struct rtems_ofw_memory_area
+ *
+ * This is used to represent elements(FDT properties) that define
+ * region of memory address.
+ */
+typedef struct {
+  /** The start address of the memory region. */
+  uint32_t start;
+  /** The size of the memory region. */
+  uint32_t size;
+} rtems_ofw_memory_area;
+
+/**
+ * @struct rtems_ofw_ranges
+ *
+ * This is used to represent the ranges property in the device tree.
+ */
+typedef struct {
+  /** The physical address within the child bus address space */
+  uint32_t child_bus;
+  /** The physical address within the parent bus address space */
+  uint32_t parent_bus;
+  /** The size of the range in the child’s address space */
+  uint32_t size;
+} rtems_ofw_ranges;
+
+/**
+ * @brief Gets the node that is next to @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval Peer node offset Successful operation.
+ * @retval 0 No peer node or invalid node handle
+ */
+phandle_t rtems_ofw_peer(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the node that is the child of @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval child node offset Successful operation.
+ * @retval 0 No child node or invalid node handle
+ */
+phandle_t rtems_ofw_child(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the node that is the parent of @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval child node offset Successful operation.
+ * @retval 0 No child node or invalid node handle
+ */
+phandle_t rtems_ofw_parent(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the length of the property mentioned in @a propname.
+ *
+ * @param[in] node Node offset
+ * @param[in] prop Property name
+ *
+ * @retval -1 Invalid node or property
+ * @retval  Length of property on successful operation
+ */
+size_t rtems_ofw_get_prop_len(
+  phandle_t   node,
+  const char *propname
+);
+
+/**
+ * @brief Gets the value of property mentioned in @a propname.
+ *
+ * @param[in] node Node offset
+ * @param[in] prop Property name
+ * @param[out] buf The property value gets stored in this buffer 
(Pre-allocated)
+ * @param[in] len Length of the buffer
+ 
+ * @retval -1 Invalid node or property
+ * @retval  Length of property on successful operation
+ */
+size_t rtems_ofw_get_prop(
+  phandle_tnode,
+  const char  *propnam

[PATCH v2] bsps/shared/ofw: Implement RTEMS OFW interface

2020-08-20 Thread G S Niteesh Babu
RTEMS OFW is a FDT only implementation of the OpenFirmWare
interface. This API is created to be compatible with FreeBSD
OpenFirmWare interface. The main intention is to make
porting of FreeBSD drivers to RTEMS easier.

Most functions implemented have an direct one-one mapping
with the original OFW API and some extra auxiliary functions
were implemented to make working with device trees easier in
RTEMS.

Update #3784
---
 bsps/include/ofw/ofw.h| 548 +++
 bsps/include/ofw/ofw_compat.h |  74 
 bsps/shared/ofw/ofw.c | 670 ++
 spec/build/bsps/obj.yml   |   4 +
 4 files changed, 1296 insertions(+)
 create mode 100644 bsps/include/ofw/ofw.h
 create mode 100644 bsps/include/ofw/ofw_compat.h
 create mode 100644 bsps/shared/ofw/ofw.c

diff --git a/bsps/include/ofw/ofw.h b/bsps/include/ofw/ofw.h
new file mode 100644
index 00..50f64ff695
--- /dev/null
+++ b/bsps/include/ofw/ofw.h
@@ -0,0 +1,548 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup ofw
+ *
+ * RTEMS FDT implementation of OpenFirmWare Interface.
+ *
+ * RTEMS OFW is a FDT only implementation of the OpenFirmWare interface.
+ * This API is created to be compatible with FreeBSD OpenFirmWare interface.
+ * The main intention is to make porting of FreeBSD drivers to RTEMS easier.
+ */
+
+/*
+ * Copyright (C) 2020 Niteesh Babu G S 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _OFW_H
+#define _OFW_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include 
+#include 
+#include 
+
+/**
+ * Represents a node in the device tree. The offset from fdtp to node is used
+ * instead of fdt offset to make sure this is compatible with OF interface in
+ * FreeBSD.
+ */
+typedef uint32_t  phandle_t;
+/**
+ * Represents the effective phandle of the node.
+ */
+typedef uint32_t  ihandle_t;
+/**
+ * Represents the data type of the buffer.
+ */
+typedef uint32_t  pcell_t;
+
+/**
+ * @struct rtems_ofw_memory_area
+ *
+ * This is used to represent elements(FDT properties) that define
+ * region of memory address.
+ */
+typedef struct {
+  /** The start address of the memory region. */
+  uint32_t start;
+  /** The size of the memory region. */
+  uint32_t size;
+} rtems_ofw_memory_area;
+
+/**
+ * @struct rtems_ofw_ranges
+ *
+ * This is used to represent the ranges property in the device tree.
+ */
+typedef struct {
+  /** The physical address within the child bus address space */
+  uint32_t child_bus;
+  /** The physical address within the parent bus address space */
+  uint32_t parent_bus;
+  /** The size of the range in the child’s address space */
+  uint32_t size;
+} rtems_ofw_ranges;
+
+/**
+ * @brief Gets the node that is next to @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval Peer node offset Successful operation.
+ * @retval 0 No peer node or invalid node handle
+ */
+phandle_t rtems_ofw_peer(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the node that is the child of @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval child node offset Successful operation.
+ * @retval 0 No child node or invalid node handle
+ */
+phandle_t rtems_ofw_child(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the node that is the parent of @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval child node offset Successful operation.
+ * @retval 0 No child node or invalid node handle
+ */
+phandle_t rtems_ofw_parent(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the length of the property mentioned in @a propname.
+ *
+ * @param[in] node Node offset
+ * @param[in] prop Property name
+ *
+ * @retval -1 Invalid node or property
+ * @retval  Length of property on successful operati

[PATCH v1 1/2] bsps/shared/ofw: Implement RTEMS OFW interface

2020-09-16 Thread G S Niteesh Babu
RTEMS OFW is a FDT only implementation of the OpenFirmWare
interface. This API is created to be compatible with FreeBSD
OpenFirmWare interface. The main intention is to make
porting of FreeBSD drivers to RTEMS easier.

Most functions implemented have an direct one-one mapping
with the original OFW API and some extra auxiliary functions
were implemented to make working with device trees easier in
RTEMS.

Update #3784
---
 bsps/include/ofw/ofw.h| 548 +++
 bsps/include/ofw/ofw_compat.h |  74 
 bsps/shared/ofw/ofw.c | 682 ++
 spec/build/bsps/obj.yml   |   5 +
 4 files changed, 1309 insertions(+)
 create mode 100644 bsps/include/ofw/ofw.h
 create mode 100644 bsps/include/ofw/ofw_compat.h
 create mode 100644 bsps/shared/ofw/ofw.c

diff --git a/bsps/include/ofw/ofw.h b/bsps/include/ofw/ofw.h
new file mode 100644
index 00..411010be89
--- /dev/null
+++ b/bsps/include/ofw/ofw.h
@@ -0,0 +1,548 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup ofw
+ *
+ * RTEMS FDT implementation of OpenFirmWare Interface.
+ *
+ * RTEMS OFW is a FDT only implementation of the OpenFirmWare interface.
+ * This API is created to be compatible with FreeBSD OpenFirmWare interface.
+ * The main intention is to make porting of FreeBSD drivers to RTEMS easier.
+ */
+
+/*
+ * Copyright (C) 2020 Niteesh Babu G S 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _OFW_H
+#define _OFW_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include 
+#include 
+#include 
+
+/**
+ * Represents a node in the device tree. The offset from fdtp to node is used
+ * instead of fdt offset to make sure this is compatible with OF interface in
+ * FreeBSD.
+ */
+typedef uint32_t  phandle_t;
+/**
+ * Represents the effective phandle of the node.
+ */
+typedef uint32_t  ihandle_t;
+/**
+ * Represents the data type of the buffer.
+ */
+typedef uint32_t  pcell_t;
+
+/**
+ * @struct rtems_ofw_memory_area
+ *
+ * This is used to represent elements(FDT properties) that define
+ * region of memory address.
+ */
+typedef struct {
+  /** The start address of the memory region. */
+  uint32_t start;
+  /** The size of the memory region. */
+  uint32_t size;
+} rtems_ofw_memory_area;
+
+/**
+ * @struct rtems_ofw_ranges
+ *
+ * This is used to represent the ranges property in the device tree.
+ */
+typedef struct {
+  /** The physical address within the child bus address space */
+  uint32_t child_bus;
+  /** The physical address within the parent bus address space */
+  uint32_t parent_bus;
+  /** The size of the range in the child’s address space */
+  uint32_t size;
+} rtems_ofw_ranges;
+
+/**
+ * @brief Gets the node that is next to @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval Peer node offset Successful operation.
+ * @retval 0 No peer node or invalid node handle
+ */
+phandle_t rtems_ofw_peer(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the node that is the child of @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval child node offset Successful operation.
+ * @retval 0 No child node or invalid node handle
+ */
+phandle_t rtems_ofw_child(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the node that is the parent of @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval child node offset Successful operation.
+ * @retval 0 No child node or invalid node handle
+ */
+phandle_t rtems_ofw_parent(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the length of the property mentioned in @a propname.
+ *
+ * @param[in] node Node offset
+ * @param[in] prop Property name
+ *
+ * @retval -1 Invalid node or property
+ * @retval  Length of property on successful operati

[PATCH v1 2/2] libtests/ofw01: Added a test for RTEMS OFW

2020-09-16 Thread G S Niteesh Babu
This commit adds a basic test that tests all the implemented
RTEMS OFW functions.
---
 spec/build/testsuites/libtests/grp.yml   |   2 +
 spec/build/testsuites/libtests/ofw01.yml |  21 +++
 testsuites/libtests/ofw01/init.c | 187 +++
 testsuites/libtests/ofw01/ofw01.doc  |  29 
 testsuites/libtests/ofw01/ofw01.scn  |   2 +
 testsuites/libtests/ofw01/some.c |  72 +
 testsuites/libtests/ofw01/some.dts   |  76 +
 testsuites/libtests/ofw01/some.h |  15 ++
 8 files changed, 404 insertions(+)
 create mode 100644 spec/build/testsuites/libtests/ofw01.yml
 create mode 100644 testsuites/libtests/ofw01/init.c
 create mode 100644 testsuites/libtests/ofw01/ofw01.doc
 create mode 100644 testsuites/libtests/ofw01/ofw01.scn
 create mode 100644 testsuites/libtests/ofw01/some.c
 create mode 100644 testsuites/libtests/ofw01/some.dts
 create mode 100644 testsuites/libtests/ofw01/some.h

diff --git a/spec/build/testsuites/libtests/grp.yml 
b/spec/build/testsuites/libtests/grp.yml
index aff46c9f8f..82c2288e2f 100644
--- a/spec/build/testsuites/libtests/grp.yml
+++ b/spec/build/testsuites/libtests/grp.yml
@@ -316,6 +316,8 @@ links:
   uid: write
 - role: build-dependency
   uid: writev
+- role: build-dependency
+  uid: ofw01
 type: build
 use-after:
 - rtemstest
diff --git a/spec/build/testsuites/libtests/ofw01.yml 
b/spec/build/testsuites/libtests/ofw01.yml
new file mode 100644
index 00..8517c58bad
--- /dev/null
+++ b/spec/build/testsuites/libtests/ofw01.yml
@@ -0,0 +1,21 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+build-type: test-program
+cflags: []
+copyrights:
+- Copyright (C) 2020 Niteesh G S
+cppflags: []
+cxxflags: []
+enabled-by: true
+features: c cprogram
+includes: []
+ldflags:
+- -Wl,--wrap=bsp_fdt_get
+links: []
+source:
+- testsuites/libtests/ofw01/init.c
+- testsuites/libtests/ofw01/some.c
+stlib: []
+target: testsuites/libtests/ofw01.exe
+type: build
+use-after: []
+use-before: []
diff --git a/testsuites/libtests/ofw01/init.c b/testsuites/libtests/ofw01/init.c
new file mode 100644
index 00..82ee5eb11f
--- /dev/null
+++ b/testsuites/libtests/ofw01/init.c
@@ -0,0 +1,187 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) <2020> Niteesh G S 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "some.h"
+
+#define BUF_SIZE 100
+
+const char rtems_test_name[] = "OFW 01";
+
+const void *__wrap_bsp_fdt_get(void);
+const void *__real_bsp_fdt_get(void);
+
+const void *__wrap_bsp_fdt_get(void)
+{
+  if (some_bin != NULL) {
+return &some_bin[0];
+  }
+
+  return __real_bsp_fdt_get();
+}
+
+static void Init(rtems_task_argument arg)
+{
+  int rv;
+  phandle_t d;
+  phandle_t l;
+  phandle_t t;
+  phandle_t c;
+  phandle_t a;
+  phandle_t b;
+  phandle_t q;
+  phandle_t root;
+  phandle_t temp;
+  uint32_t *arr;
+  char buf[BUF_SIZE];
+  char *bufp;
+  ssize_t buf_len;
+  rtems_ofw_memory_area reg;
+  rtems_ofw_memory_area regs[2];
+  rtems_vector_number intr;
+  rtems_vector_number intrs[2];
+  TEST_BEGIN();
+  buf_len = sizeof(buf);
+  /*
+   * Cannot use fdt_path_offset to compare because
+   * the OF interface uses the offset from the ftdp
+   * to the node as phandle.
+   */
+  root = rtems_ofw_find_device("/");
+  rtems_test_assert(root == 56);
+
+  root = rtems_ofw_peer(0);
+  rtems_test_assert(root == 56);
+
+  d = rtems_ofw_child(root);
+  temp = rtems_ofw_find_device("/d");
+  rtems_test_assert(d == temp);
+
+  temp = rtems_ofw_parent(d);
+  rtems_test_assert(root == temp);
+
+  rv = rtems_ofw_get

[RTEMS-libBSD OFW v1] dev/ofw: Use RTEMS OFW FDT implementation

2020-09-16 Thread G S Niteesh Babu
This commit modifies the OFW interface to the RTEMS FDT
implementation instead of the default FreeBSD.
---
 freebsd/sys/dev/ofw/openfirm.c|  2 ++
 freebsd/sys/dev/ofw/openfirm.h|  9 
 .../machine/rtems-bsd-kernel-namespace.h  | 22 ---
 3 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/freebsd/sys/dev/ofw/openfirm.c b/freebsd/sys/dev/ofw/openfirm.c
index 9cc7dbdc..30513ab2 100644
--- a/freebsd/sys/dev/ofw/openfirm.c
+++ b/freebsd/sys/dev/ofw/openfirm.c
@@ -333,6 +333,7 @@ OF_interpret(const char *cmd, int nreturns, ...)
  * Device tree functions
  */
 
+#ifndef __rtems__
 /* Return the next sibling of this node or 0. */
 phandle_t
 OF_peer(phandle_t node)
@@ -672,6 +673,7 @@ OF_xref_from_node(phandle_t node)
return (node);
return (xref);
 }
+#endif /* __rtems__ */
 
 device_t
 OF_device_from_xref(phandle_t xref)
diff --git a/freebsd/sys/dev/ofw/openfirm.h b/freebsd/sys/dev/ofw/openfirm.h
index f043197a..5df07258 100644
--- a/freebsd/sys/dev/ofw/openfirm.h
+++ b/freebsd/sys/dev/ofw/openfirm.h
@@ -64,7 +64,11 @@
 
 #include 
 #include 
+#ifdef __rtems__
+#include 
+#endif /* __rtems__ */
 
+#ifndef __rtems__
 /*
  * Prototypes for Open Firmware Interface Routines
  */
@@ -72,6 +76,7 @@
 typedef uint32_t   ihandle_t;
 typedef uint32_t   phandle_t;
 typedef uint32_t   pcell_t;
+#endif /* __rtems__ */
 
 #ifdef _KERNEL
 #include 
@@ -102,6 +107,7 @@ int OF_test(const char *name);
 void   OF_printf(const char *fmt, ...);
 
 /* Device tree functions */
+#ifndef __rtems__
 phandle_t  OF_peer(phandle_t node);
 phandle_t  OF_child(phandle_t node);
 phandle_t  OF_parent(phandle_t node);
@@ -140,6 +146,7 @@ ssize_t OF_package_to_path(phandle_t node, char 
*buf, size_t len);
  */
 phandle_t  OF_node_from_xref(phandle_t xref);
 phandle_t  OF_xref_from_node(phandle_t node);
+#endif /* __rtems__ */
 
 /*
  * When properties contain references to other nodes using xref handles it is
@@ -159,8 +166,10 @@ ssize_tOF_read(ihandle_t instance, void *buf, 
size_t len);
 ssize_tOF_write(ihandle_t instance, const void *buf, size_t 
len);
 intOF_seek(ihandle_t instance, uint64_t where);
 
+#ifndef __rtems__
 phandle_t  OF_instance_to_package(ihandle_t instance);
 ssize_tOF_instance_to_path(ihandle_t instance, char *buf, 
size_t len);
+#endif /* __rtems__ */
 intOF_call_method(const char *method, ihandle_t instance,
int nargs, int nreturns, ...);
 
diff --git a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h 
b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
index 75b744a4..53944393 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
@@ -3044,42 +3044,20 @@
 #definenull_filtops _bsd_null_filtops
 #definenullop _bsd_nullop
 #defineOF_call_method _bsd_OF_call_method
-#defineOF_canon _bsd_OF_canon
-#defineOF_child _bsd_OF_child
 #defineOF_claim _bsd_OF_claim
 #defineOF_close _bsd_OF_close
 #defineOF_device_from_xref _bsd_OF_device_from_xref
 #defineOF_device_register_xref _bsd_OF_device_register_xref
 #defineOF_enter _bsd_OF_enter
 #defineOF_exit _bsd_OF_exit
-#defineOF_finddevice _bsd_OF_finddevice
-#defineOF_getencprop _bsd_OF_getencprop
-#defineOF_getencprop_alloc _bsd_OF_getencprop_alloc
-#defineOF_getencprop_alloc_multi _bsd_OF_getencprop_alloc_multi
-#defineOF_getprop _bsd_OF_getprop
-#defineOF_getprop_alloc _bsd_OF_getprop_alloc
-#defineOF_getprop_alloc_multi _bsd_OF_getprop_alloc_multi
-#defineOF_getproplen _bsd_OF_getproplen
-#defineOF_hasprop _bsd_OF_hasprop
 #defineOF_init _bsd_OF_init
 #defineOF_install _bsd_OF_install
-#defineOF_instance_to_package _bsd_OF_instance_to_package
-#defineOF_instance_to_path _bsd_OF_instance_to_path
 #defineOF_interpret _bsd_OF_interpret
-#defineOF_nextprop _bsd_OF_nextprop
-#defineOF_node_from_xref _bsd_OF_node_from_xref
 #defineOF_open _bsd_OF_open
-#defineOF_package_to_path _bsd_OF_package_to_path
-#defineOF_parent _bsd_OF_parent
-#defineOF_peer _bsd_OF_peer
 #defineOF_printf _bsd_OF_printf
-#defineOF_prop_free _bsd_OF_prop_free
 #defineOF_read _bsd_OF_read
 #defineOF_release _bsd_OF_release
-#defineOF_searchencprop _bsd_OF_searchencprop
-#defineOF_searchprop _bsd_OF_searchprop
 #defineOF_seek _bsd_OF_seek
-#defineOF_setprop _bsd_OF_setprop
 #defineOF_test _bsd_OF_test
 #defineofw_bus_assigned_addresses_to_rl 
_bsd_ofw_bus_assigned_addresses_to_rl
 #defineofwbus_driver _bsd_ofwbus_driver
-- 
2.17.1

_

[PATCH v2 2/2] libtests/ofw01: Added a test for RTEMS OFW

2020-11-03 Thread G S Niteesh Babu
Added a basic test for the implemented RTEMS OFW
API.
---
 spec/build/testsuites/libtests/grp.yml   |   2 +
 spec/build/testsuites/libtests/ofw01.yml |  21 +++
 testsuites/libtests/ofw01/init.c | 187 +++
 testsuites/libtests/ofw01/ofw01.doc  |  29 
 testsuites/libtests/ofw01/ofw01.scn  |   2 +
 testsuites/libtests/ofw01/some.c |  72 +
 testsuites/libtests/ofw01/some.dts   |  76 +
 testsuites/libtests/ofw01/some.h |  15 ++
 8 files changed, 404 insertions(+)
 create mode 100644 spec/build/testsuites/libtests/ofw01.yml
 create mode 100644 testsuites/libtests/ofw01/init.c
 create mode 100644 testsuites/libtests/ofw01/ofw01.doc
 create mode 100644 testsuites/libtests/ofw01/ofw01.scn
 create mode 100644 testsuites/libtests/ofw01/some.c
 create mode 100644 testsuites/libtests/ofw01/some.dts
 create mode 100644 testsuites/libtests/ofw01/some.h

diff --git a/spec/build/testsuites/libtests/grp.yml 
b/spec/build/testsuites/libtests/grp.yml
index b9ca014b0d..1aa136854a 100644
--- a/spec/build/testsuites/libtests/grp.yml
+++ b/spec/build/testsuites/libtests/grp.yml
@@ -316,6 +316,8 @@ links:
   uid: write
 - role: build-dependency
   uid: writev
+- role: build-dependency
+  uid: ofw01
 type: build
 use-after:
 - rtemstest
diff --git a/spec/build/testsuites/libtests/ofw01.yml 
b/spec/build/testsuites/libtests/ofw01.yml
new file mode 100644
index 00..8517c58bad
--- /dev/null
+++ b/spec/build/testsuites/libtests/ofw01.yml
@@ -0,0 +1,21 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+build-type: test-program
+cflags: []
+copyrights:
+- Copyright (C) 2020 Niteesh G S
+cppflags: []
+cxxflags: []
+enabled-by: true
+features: c cprogram
+includes: []
+ldflags:
+- -Wl,--wrap=bsp_fdt_get
+links: []
+source:
+- testsuites/libtests/ofw01/init.c
+- testsuites/libtests/ofw01/some.c
+stlib: []
+target: testsuites/libtests/ofw01.exe
+type: build
+use-after: []
+use-before: []
diff --git a/testsuites/libtests/ofw01/init.c b/testsuites/libtests/ofw01/init.c
new file mode 100644
index 00..82ee5eb11f
--- /dev/null
+++ b/testsuites/libtests/ofw01/init.c
@@ -0,0 +1,187 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) <2020> Niteesh G S 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "some.h"
+
+#define BUF_SIZE 100
+
+const char rtems_test_name[] = "OFW 01";
+
+const void *__wrap_bsp_fdt_get(void);
+const void *__real_bsp_fdt_get(void);
+
+const void *__wrap_bsp_fdt_get(void)
+{
+  if (some_bin != NULL) {
+return &some_bin[0];
+  }
+
+  return __real_bsp_fdt_get();
+}
+
+static void Init(rtems_task_argument arg)
+{
+  int rv;
+  phandle_t d;
+  phandle_t l;
+  phandle_t t;
+  phandle_t c;
+  phandle_t a;
+  phandle_t b;
+  phandle_t q;
+  phandle_t root;
+  phandle_t temp;
+  uint32_t *arr;
+  char buf[BUF_SIZE];
+  char *bufp;
+  ssize_t buf_len;
+  rtems_ofw_memory_area reg;
+  rtems_ofw_memory_area regs[2];
+  rtems_vector_number intr;
+  rtems_vector_number intrs[2];
+  TEST_BEGIN();
+  buf_len = sizeof(buf);
+  /*
+   * Cannot use fdt_path_offset to compare because
+   * the OF interface uses the offset from the ftdp
+   * to the node as phandle.
+   */
+  root = rtems_ofw_find_device("/");
+  rtems_test_assert(root == 56);
+
+  root = rtems_ofw_peer(0);
+  rtems_test_assert(root == 56);
+
+  d = rtems_ofw_child(root);
+  temp = rtems_ofw_find_device("/d");
+  rtems_test_assert(d == temp);
+
+  temp = rtems_ofw_parent(d);
+  rtems_test_assert(root == temp);
+
+  rv = rtems_ofw_get_prop(d, "e", buf, buf_len);

[PATCH v2 1/2] bsps/shared/ofw: Implement RTEMS OFW interface

2020-11-03 Thread G S Niteesh Babu
RTEMS OFW is a FDT only implementation of the OpenFirmWare
interface. This API is created to be compatible with FreeBSD
OpenFirmWare interface. The main intention is to make
porting of FreeBSD drivers to RTEMS easier.

Most functions implemented have an direct one-one mapping
with the original OFW API and some extra auxiliary functions
were implemented to make working with device trees easier in
RTEMS.

Update #3784
---
 bsps/include/ofw/ofw.h| 548 +++
 bsps/include/ofw/ofw_compat.h |  74 
 bsps/shared/ofw/ofw.c | 682 ++
 spec/build/bsps/obj.yml   |   5 +
 4 files changed, 1309 insertions(+)
 create mode 100644 bsps/include/ofw/ofw.h
 create mode 100644 bsps/include/ofw/ofw_compat.h
 create mode 100644 bsps/shared/ofw/ofw.c

diff --git a/bsps/include/ofw/ofw.h b/bsps/include/ofw/ofw.h
new file mode 100644
index 00..4c402671a4
--- /dev/null
+++ b/bsps/include/ofw/ofw.h
@@ -0,0 +1,548 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup ofw
+ *
+ * RTEMS FDT implementation of OpenFirmWare Interface.
+ *
+ * RTEMS OFW is a FDT only implementation of the OpenFirmWare interface.
+ * This API is created to be compatible with FreeBSD OpenFirmWare interface.
+ * The main intention is to make porting of FreeBSD drivers to RTEMS easier.
+ */
+
+/*
+ * Copyright (C) 2020 Niteesh Babu G S 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _OFW_H
+#define _OFW_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include 
+#include 
+#include 
+
+/**
+ * Represents a node in the device tree. The offset from fdtp to node is used
+ * instead of fdt offset to make sure this is compatible with OF interface in
+ * FreeBSD.
+ */
+typedef uint32_t  phandle_t;
+/**
+ * Represents the effective phandle of the node.
+ */
+typedef uint32_t  ihandle_t;
+/**
+ * Represents the data type of the buffer.
+ */
+typedef uint32_t  pcell_t;
+
+/**
+ * @struct rtems_ofw_memory_area
+ *
+ * This is used to represent elements(FDT properties) that define
+ * region of memory address.
+ */
+typedef struct {
+  /** The start address of the memory region. */
+  uint32_t start;
+  /** The size of the memory region. */
+  uint32_t size;
+} rtems_ofw_memory_area;
+
+/**
+ * @struct rtems_ofw_ranges
+ *
+ * This is used to represent the ranges property in the device tree.
+ */
+typedef struct {
+  /** The physical address within the child bus address space */
+  uint32_t child_bus;
+  /** The physical address within the parent bus address space */
+  uint32_t parent_bus;
+  /** The size of the range in the child’s address space */
+  uint32_t size;
+} rtems_ofw_ranges;
+
+/**
+ * @brief Gets the node that is next to @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval Peer node offset Successful operation.
+ * @retval 0 No peer node or invalid node handle
+ */
+phandle_t rtems_ofw_peer(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the node that is the child of @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval child node offset Successful operation.
+ * @retval 0 No child node or invalid node handle
+ */
+phandle_t rtems_ofw_child(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the node that is the parent of @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval child node offset Successful operation.
+ * @retval 0 No child node or invalid node handle
+ */
+phandle_t rtems_ofw_parent(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the length of the property mentioned in @a propname.
+ *
+ * @param[in] node Node offset
+ * @param[in] prop Property name
+ *
+ * @retval -1 Invalid node or property
+ * @retval  Length of property on successful operati

[PATCH v3 1/2] bsps/shared/ofw: Implement RTEMS OFW interface

2020-12-04 Thread G S Niteesh Babu
RTEMS OFW is a FDT only implementation of the OpenFirmWare
interface. This API is created to be compatible with FreeBSD
OpenFirmWare interface. The main intention is to make
porting of FreeBSD drivers to RTEMS easier.

Most functions implemented have an direct one-one mapping
with the original OFW API and some extra auxiliary functions
were implemented to make working with device trees easier in
RTEMS.

Update #3784
---
 bsps/include/ofw/ofw.h| 548 +++
 bsps/include/ofw/ofw_compat.h |  74 
 bsps/include/ofw/ofw_test.h   |  43 +++
 bsps/shared/ofw/ofw.c | 683 ++
 spec/build/bsps/obj.yml   |   5 +
 5 files changed, 1353 insertions(+)
 create mode 100644 bsps/include/ofw/ofw.h
 create mode 100644 bsps/include/ofw/ofw_compat.h
 create mode 100644 bsps/include/ofw/ofw_test.h
 create mode 100644 bsps/shared/ofw/ofw.c

diff --git a/bsps/include/ofw/ofw.h b/bsps/include/ofw/ofw.h
new file mode 100644
index 00..411010be89
--- /dev/null
+++ b/bsps/include/ofw/ofw.h
@@ -0,0 +1,548 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup ofw
+ *
+ * RTEMS FDT implementation of OpenFirmWare Interface.
+ *
+ * RTEMS OFW is a FDT only implementation of the OpenFirmWare interface.
+ * This API is created to be compatible with FreeBSD OpenFirmWare interface.
+ * The main intention is to make porting of FreeBSD drivers to RTEMS easier.
+ */
+
+/*
+ * Copyright (C) 2020 Niteesh Babu G S 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _OFW_H
+#define _OFW_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include 
+#include 
+#include 
+
+/**
+ * Represents a node in the device tree. The offset from fdtp to node is used
+ * instead of fdt offset to make sure this is compatible with OF interface in
+ * FreeBSD.
+ */
+typedef uint32_t  phandle_t;
+/**
+ * Represents the effective phandle of the node.
+ */
+typedef uint32_t  ihandle_t;
+/**
+ * Represents the data type of the buffer.
+ */
+typedef uint32_t  pcell_t;
+
+/**
+ * @struct rtems_ofw_memory_area
+ *
+ * This is used to represent elements(FDT properties) that define
+ * region of memory address.
+ */
+typedef struct {
+  /** The start address of the memory region. */
+  uint32_t start;
+  /** The size of the memory region. */
+  uint32_t size;
+} rtems_ofw_memory_area;
+
+/**
+ * @struct rtems_ofw_ranges
+ *
+ * This is used to represent the ranges property in the device tree.
+ */
+typedef struct {
+  /** The physical address within the child bus address space */
+  uint32_t child_bus;
+  /** The physical address within the parent bus address space */
+  uint32_t parent_bus;
+  /** The size of the range in the child’s address space */
+  uint32_t size;
+} rtems_ofw_ranges;
+
+/**
+ * @brief Gets the node that is next to @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval Peer node offset Successful operation.
+ * @retval 0 No peer node or invalid node handle
+ */
+phandle_t rtems_ofw_peer(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the node that is the child of @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval child node offset Successful operation.
+ * @retval 0 No child node or invalid node handle
+ */
+phandle_t rtems_ofw_child(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the node that is the parent of @a node.
+ *
+ * @param[in] node Node offset
+ *
+ * @retval child node offset Successful operation.
+ * @retval 0 No child node or invalid node handle
+ */
+phandle_t rtems_ofw_parent(
+  phandle_t   node
+);
+
+/**
+ * @brief Gets the length of the property mentioned in @a propname.
+ *
+ * @param[in] node Node offset
+ * @param[in] prop Property name
+ *
+ * 

[PATCH v3 2/2] libtests/ofw01: Added a test for RTEMS OFW

2020-12-04 Thread G S Niteesh Babu
This commit adds a basic test that tests all the implemented
RTEMS OFW functions.
---
 spec/build/testsuites/libtests/grp.yml   |   2 +
 spec/build/testsuites/libtests/ofw01.yml |  21 +++
 testsuites/libtests/ofw01/init.c | 197 +++
 testsuites/libtests/ofw01/ofw01.doc  |  29 
 testsuites/libtests/ofw01/ofw01.scn  |   2 +
 testsuites/libtests/ofw01/some.c |  72 +
 testsuites/libtests/ofw01/some.dts   |  76 +
 testsuites/libtests/ofw01/some.h |  15 ++
 8 files changed, 414 insertions(+)
 create mode 100644 spec/build/testsuites/libtests/ofw01.yml
 create mode 100644 testsuites/libtests/ofw01/init.c
 create mode 100644 testsuites/libtests/ofw01/ofw01.doc
 create mode 100644 testsuites/libtests/ofw01/ofw01.scn
 create mode 100644 testsuites/libtests/ofw01/some.c
 create mode 100644 testsuites/libtests/ofw01/some.dts
 create mode 100644 testsuites/libtests/ofw01/some.h

diff --git a/spec/build/testsuites/libtests/grp.yml 
b/spec/build/testsuites/libtests/grp.yml
index aff46c9f8f..82c2288e2f 100644
--- a/spec/build/testsuites/libtests/grp.yml
+++ b/spec/build/testsuites/libtests/grp.yml
@@ -316,6 +316,8 @@ links:
   uid: write
 - role: build-dependency
   uid: writev
+- role: build-dependency
+  uid: ofw01
 type: build
 use-after:
 - rtemstest
diff --git a/spec/build/testsuites/libtests/ofw01.yml 
b/spec/build/testsuites/libtests/ofw01.yml
new file mode 100644
index 00..8517c58bad
--- /dev/null
+++ b/spec/build/testsuites/libtests/ofw01.yml
@@ -0,0 +1,21 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+build-type: test-program
+cflags: []
+copyrights:
+- Copyright (C) 2020 Niteesh G S
+cppflags: []
+cxxflags: []
+enabled-by: true
+features: c cprogram
+includes: []
+ldflags:
+- -Wl,--wrap=bsp_fdt_get
+links: []
+source:
+- testsuites/libtests/ofw01/init.c
+- testsuites/libtests/ofw01/some.c
+stlib: []
+target: testsuites/libtests/ofw01.exe
+type: build
+use-after: []
+use-before: []
diff --git a/testsuites/libtests/ofw01/init.c b/testsuites/libtests/ofw01/init.c
new file mode 100644
index 00..105c52c50e
--- /dev/null
+++ b/testsuites/libtests/ofw01/init.c
@@ -0,0 +1,197 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) <2020> Niteesh G S 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "some.h"
+
+#define BUF_SIZE 100
+
+const char rtems_test_name[] = "OFW 01";
+static const void *test_bin = NULL;
+
+const void *__wrap_bsp_fdt_get(void);
+const void *__real_bsp_fdt_get(void);
+
+const void *__wrap_bsp_fdt_get(void)
+{
+  if (test_bin != NULL) {
+return test_bin;
+  }
+
+  return __real_bsp_fdt_get();
+}
+
+static void Init(rtems_task_argument arg)
+{
+  int rv;
+  phandle_t d;
+  phandle_t l;
+  phandle_t t;
+  phandle_t c;
+  phandle_t a;
+  phandle_t b;
+  phandle_t q;
+  phandle_t root;
+  phandle_t temp;
+  uint32_t *arr;
+  char buf[BUF_SIZE];
+  char *bufp;
+  ssize_t buf_len;
+  rtems_ofw_memory_area reg;
+  rtems_ofw_memory_area regs[2];
+  rtems_vector_number intr;
+  rtems_vector_number intrs[2];
+  TEST_BEGIN();
+  buf_len = sizeof(buf);
+
+  /*
+   * Reinitializing the OFW API to use the test
+   * FDT instead of the original FDT.
+   */
+  test_bin = some_bin;
+  rtems_ofw_init();
+
+  /*
+   * Cannot use fdt_path_offset to compare because
+   * the OF interface uses the offset from the ftdp
+   * to the node as phandle.
+   */
+  root = rtems_ofw_find_device("/");
+  rtems_test_assert(root == 56);
+
+  root = rtems_ofw_peer(0);
+  rtems_test_assert(root == 56);
+

[PATCH] Implement FreeBSD helper structures

2021-01-19 Thread G S Niteesh Babu
The following structures and functions have been implemented to
make porting of driver from FreeBSD easier.

 1) struct resource_spec
 2) struct device
 3) struct resource
 4) device_get_softc
 5) bus_alloc_resources
 6) bus_alloc_resource
 7) bus_alloc_resource_any
 8) bus_space_read_1
 9) bus_space_read_2
10) bus_space_read_4
11) bus_space_write_1
12) bus_space_write_2
13) bus_space_write_4
---
 bsps/include/rtems/freebsd-compat/bus.h  | 122 +++
 bsps/include/rtems/freebsd-compat/device.h   |  46 +++
 bsps/include/rtems/freebsd-compat/resource.h |  46 +++
 bsps/include/rtems/freebsd-compat/rman.h |  65 ++
 bsps/shared/rtems/freebsd-compat/bus.c   | 119 ++
 spec/build/bsps/obj.yml  |   1 +
 6 files changed, 399 insertions(+)
 create mode 100644 bsps/include/rtems/freebsd-compat/bus.h
 create mode 100644 bsps/include/rtems/freebsd-compat/device.h
 create mode 100644 bsps/include/rtems/freebsd-compat/resource.h
 create mode 100644 bsps/include/rtems/freebsd-compat/rman.h
 create mode 100644 bsps/shared/rtems/freebsd-compat/bus.c

diff --git a/bsps/include/rtems/freebsd-compat/bus.h 
b/bsps/include/rtems/freebsd-compat/bus.h
new file mode 100644
index 00..4bd3ab311a
--- /dev/null
+++ b/bsps/include/rtems/freebsd-compat/bus.h
@@ -0,0 +1,122 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup FreeBSDCompat
+ *
+ * @brief
+ */
+
+/*
+ * Copyright (C) <2020> Niteesh Babu 
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _FREEBSD_COMPAT_BUS_H
+#define _FREEBSD_COMPAT_BUS_H
+
+#include 
+#include "device.h"
+#include "rman.h"
+
+struct resource_spec {
+  int type;
+  int rid;
+  int flags;
+};
+#define RESOURCE_SPEC_END {-1, 0, 0}
+
+/*
+ * Write a 1, 2, 4, or 8 byte quantity to bus space
+ * described by tag/handle/offset.
+ */
+static inline void
+bus_space_write_1(bus_space_tag_t bst, bus_space_handle_t bsh, bus_size_t ofs,
+uint8_t val)
+{
+  uint8_t volatile *bsp = (uint8_t volatile *)(bsh + ofs);
+  *bsp = val;
+}
+
+static inline void
+bus_space_write_2(bus_space_tag_t bst, bus_space_handle_t bsh, bus_size_t ofs,
+uint16_t val)
+{
+  uint16_t volatile *bsp = (uint16_t volatile *)(bsh + ofs);
+  *bsp = val;
+}
+
+static inline void
+bus_space_write_4(bus_space_tag_t bst, bus_space_handle_t bsh, bus_size_t ofs,
+uint32_t val)
+{
+  uint32_t volatile *bsp = (uint32_t volatile *)(bsh + ofs);
+  *bsp = val;
+}
+
+/*
+ * Read a 1, 2, 4, or 8 byte quantity from bus space
+ * described by tag/handle/offset.
+ */
+static inline uint8_t
+bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle,
+ bus_size_t offset)
+{
+
+  return (*(volatile uint8_t *)(handle + offset));
+}
+
+static inline uint16_t
+bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle,
+ bus_size_t offset)
+{
+  return (*(volatile uint16_t *)(handle + offset));
+}
+
+static inline uint32_t
+bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle,
+bus_size_t offset)
+{
+  return (*(volatile uint32_t *)(handle + offset));
+}
+
+bus_space_handle_t rman_get_bushandle(struct resource *);
+bus_space_tag_t rman_get_bustag(struct resource *);
+
+void   *device_get_softc(device_t dev);
+
+intbus_alloc_resources(device_t dev, struct resource_spec *rs,
+  struct resource **res);
+
+struct resource *bus_alloc_resource(device_t dev, int type, int *rid,
+ rman_res_t start, rman_res_t end,
+ rman_res_t count, u_int flags);
+
+static __inline struct resource *
+bus_alloc_resource_any(device_t dev, int type, int *rid, uint32_t flags)
+{
+  return (bus_alloc_resource(dev, type, rid, 0, ~0, 1, fl

[patch libBSD] dev/ofw: Use RTEMS OFW FDT implementation

2021-01-20 Thread G S Niteesh Babu
This commit modifies the OFW interface to the RTEMS FDT
implementation instead of the default FreeBSD.
---
 freebsd/sys/dev/ofw/openfirm.c|  2 ++
 freebsd/sys/dev/ofw/openfirm.h|  9 
 .../machine/rtems-bsd-kernel-namespace.h  | 22 ---
 3 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/freebsd/sys/dev/ofw/openfirm.c b/freebsd/sys/dev/ofw/openfirm.c
index 9cc7dbdc..30513ab2 100644
--- a/freebsd/sys/dev/ofw/openfirm.c
+++ b/freebsd/sys/dev/ofw/openfirm.c
@@ -333,6 +333,7 @@ OF_interpret(const char *cmd, int nreturns, ...)
  * Device tree functions
  */
 
+#ifndef __rtems__
 /* Return the next sibling of this node or 0. */
 phandle_t
 OF_peer(phandle_t node)
@@ -672,6 +673,7 @@ OF_xref_from_node(phandle_t node)
return (node);
return (xref);
 }
+#endif /* __rtems__ */
 
 device_t
 OF_device_from_xref(phandle_t xref)
diff --git a/freebsd/sys/dev/ofw/openfirm.h b/freebsd/sys/dev/ofw/openfirm.h
index f043197a..5df07258 100644
--- a/freebsd/sys/dev/ofw/openfirm.h
+++ b/freebsd/sys/dev/ofw/openfirm.h
@@ -64,7 +64,11 @@
 
 #include 
 #include 
+#ifdef __rtems__
+#include 
+#endif /* __rtems__ */
 
+#ifndef __rtems__
 /*
  * Prototypes for Open Firmware Interface Routines
  */
@@ -72,6 +76,7 @@
 typedef uint32_t   ihandle_t;
 typedef uint32_t   phandle_t;
 typedef uint32_t   pcell_t;
+#endif /* __rtems__ */
 
 #ifdef _KERNEL
 #include 
@@ -102,6 +107,7 @@ int OF_test(const char *name);
 void   OF_printf(const char *fmt, ...);
 
 /* Device tree functions */
+#ifndef __rtems__
 phandle_t  OF_peer(phandle_t node);
 phandle_t  OF_child(phandle_t node);
 phandle_t  OF_parent(phandle_t node);
@@ -140,6 +146,7 @@ ssize_t OF_package_to_path(phandle_t node, char 
*buf, size_t len);
  */
 phandle_t  OF_node_from_xref(phandle_t xref);
 phandle_t  OF_xref_from_node(phandle_t node);
+#endif /* __rtems__ */
 
 /*
  * When properties contain references to other nodes using xref handles it is
@@ -159,8 +166,10 @@ ssize_tOF_read(ihandle_t instance, void *buf, 
size_t len);
 ssize_tOF_write(ihandle_t instance, const void *buf, size_t 
len);
 intOF_seek(ihandle_t instance, uint64_t where);
 
+#ifndef __rtems__
 phandle_t  OF_instance_to_package(ihandle_t instance);
 ssize_tOF_instance_to_path(ihandle_t instance, char *buf, 
size_t len);
+#endif /* __rtems__ */
 intOF_call_method(const char *method, ihandle_t instance,
int nargs, int nreturns, ...);
 
diff --git a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h 
b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
index 75b744a4..53944393 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
@@ -3044,42 +3044,20 @@
 #definenull_filtops _bsd_null_filtops
 #definenullop _bsd_nullop
 #defineOF_call_method _bsd_OF_call_method
-#defineOF_canon _bsd_OF_canon
-#defineOF_child _bsd_OF_child
 #defineOF_claim _bsd_OF_claim
 #defineOF_close _bsd_OF_close
 #defineOF_device_from_xref _bsd_OF_device_from_xref
 #defineOF_device_register_xref _bsd_OF_device_register_xref
 #defineOF_enter _bsd_OF_enter
 #defineOF_exit _bsd_OF_exit
-#defineOF_finddevice _bsd_OF_finddevice
-#defineOF_getencprop _bsd_OF_getencprop
-#defineOF_getencprop_alloc _bsd_OF_getencprop_alloc
-#defineOF_getencprop_alloc_multi _bsd_OF_getencprop_alloc_multi
-#defineOF_getprop _bsd_OF_getprop
-#defineOF_getprop_alloc _bsd_OF_getprop_alloc
-#defineOF_getprop_alloc_multi _bsd_OF_getprop_alloc_multi
-#defineOF_getproplen _bsd_OF_getproplen
-#defineOF_hasprop _bsd_OF_hasprop
 #defineOF_init _bsd_OF_init
 #defineOF_install _bsd_OF_install
-#defineOF_instance_to_package _bsd_OF_instance_to_package
-#defineOF_instance_to_path _bsd_OF_instance_to_path
 #defineOF_interpret _bsd_OF_interpret
-#defineOF_nextprop _bsd_OF_nextprop
-#defineOF_node_from_xref _bsd_OF_node_from_xref
 #defineOF_open _bsd_OF_open
-#defineOF_package_to_path _bsd_OF_package_to_path
-#defineOF_parent _bsd_OF_parent
-#defineOF_peer _bsd_OF_peer
 #defineOF_printf _bsd_OF_printf
-#defineOF_prop_free _bsd_OF_prop_free
 #defineOF_read _bsd_OF_read
 #defineOF_release _bsd_OF_release
-#defineOF_searchencprop _bsd_OF_searchencprop
-#defineOF_searchprop _bsd_OF_searchprop
 #defineOF_seek _bsd_OF_seek
-#defineOF_setprop _bsd_OF_setprop
 #defineOF_test _bsd_OF_test
 #defineofw_bus_assigned_addresses_to_rl 
_bsd_ofw_bus_assigned_addresses_to_rl
 #defineofwbus_driver _bsd_ofwbus_driver
-- 
2.17.1

_

[PATCH] bsps/shared/ofw: Fix coverity reported defects

2021-01-28 Thread G S Niteesh Babu
Fixed use after free and null pointer dereference defects

FIXES:
1) CID 1472601 (NULL_RETURNS)
2) CID 1472600 (USE_AFTER_FREE)
3) CID 1472599 (USE_AFTER_FREE)
4) CID 1472598 (USE_AFTER_FREE)
5) CID 1472596 (USE_AFTER_FREE)
---
 bsps/shared/ofw/ofw.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index 82924b2600..fa94bfbf05 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -313,7 +313,7 @@ ssize_t rtems_ofw_get_prop_alloc(
 }
 
 if (rtems_ofw_get_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -344,7 +344,7 @@ ssize_t rtems_ofw_get_prop_alloc_multi(
 }
 
 if (rtems_ofw_get_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -373,7 +373,7 @@ ssize_t rtems_ofw_get_enc_prop_alloc(
 }
 
 if (rtems_ofw_get_enc_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -404,7 +404,7 @@ ssize_t rtems_ofw_get_enc_prop_alloc_multi(
 }
 
 if (rtems_ofw_get_enc_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -614,7 +614,7 @@ int rtems_ofw_get_reg(
 offset = rtems_fdt_phandle_to_offset(parent);
 ptr = fdt_getprop(fdtp, offset, "ranges", &len);
 
-if (len < 0) {
+if (ptr == NULL) {
   break;
 }
 
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v2] bsps/shared/ofw: Fix coverity reported defects

2021-02-03 Thread G S Niteesh Babu
Fixed use after free and null pointer dereference defects

FIXES:
1) CID 1472601 (NULL_RETURNS)
2) CID 1472600 (USE_AFTER_FREE)
3) CID 1472599 (USE_AFTER_FREE)
4) CID 1472598 (USE_AFTER_FREE)
5) CID 1472596 (USE_AFTER_FREE)
6) CID 1472597 (ARRAY_VS_SINGLETON)
7) CID 1472595 (ARRAY_VS_SINGLETON)
---
 bsps/shared/ofw/ofw.c | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index 82924b2600..126a86cc55 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -313,7 +313,7 @@ ssize_t rtems_ofw_get_prop_alloc(
 }
 
 if (rtems_ofw_get_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -344,7 +344,7 @@ ssize_t rtems_ofw_get_prop_alloc_multi(
 }
 
 if (rtems_ofw_get_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -373,7 +373,7 @@ ssize_t rtems_ofw_get_enc_prop_alloc(
 }
 
 if (rtems_ofw_get_enc_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -404,7 +404,7 @@ ssize_t rtems_ofw_get_enc_prop_alloc_multi(
 }
 
 if (rtems_ofw_get_enc_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -500,7 +500,7 @@ static phandle_t rtems_ofw_get_effective_phandle(
 )
 {
   phandle_t child;
-  phandle_t ref;
+  phandle_t ref[1];
 
   for (child = rtems_ofw_child(node); child != 0; child = 
rtems_ofw_peer(child)) {
 ref = rtems_ofw_get_effective_phandle(child, xref);
@@ -533,7 +533,7 @@ phandle_t rtems_ofw_node_from_xref( phandle_t xref )
 
 phandle_t rtems_ofw_xref_from_node( phandle_t node )
 {
-  phandle_t ref;
+  phandle_t ref[1];
 
 if (rtems_ofw_get_enc_prop(node, "phandle", &ref, sizeof(ref)) == -1 &&
 rtems_ofw_get_enc_prop(node, "ibm,phandle", &ref, sizeof(ref)) == -1 &&
@@ -614,7 +614,7 @@ int rtems_ofw_get_reg(
 offset = rtems_fdt_phandle_to_offset(parent);
 ptr = fdt_getprop(fdtp, offset, "ranges", &len);
 
-if (len < 0) {
+if (ptr == NULL) {
   break;
 }
 
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v3] bsps/shared/ofw: Fix coverity reported defects

2021-02-03 Thread G S Niteesh Babu
Fixed use after free and null pointer dereference defects

FIXES:
1) CID 1472601 (NULL_RETURNS)
2) CID 1472600 (USE_AFTER_FREE)
3) CID 1472599 (USE_AFTER_FREE)
4) CID 1472598 (USE_AFTER_FREE)
5) CID 1472596 (USE_AFTER_FREE)
6) CID 1472597 (ARRAY_VS_SINGLETON)
7) CID 1472595 (ARRAY_VS_SINGLETON)
---
 bsps/shared/ofw/ofw.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index 82924b2600..ccd57e36af 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -313,7 +313,7 @@ ssize_t rtems_ofw_get_prop_alloc(
 }
 
 if (rtems_ofw_get_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -344,7 +344,7 @@ ssize_t rtems_ofw_get_prop_alloc_multi(
 }
 
 if (rtems_ofw_get_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -373,7 +373,7 @@ ssize_t rtems_ofw_get_enc_prop_alloc(
 }
 
 if (rtems_ofw_get_enc_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -404,7 +404,7 @@ ssize_t rtems_ofw_get_enc_prop_alloc_multi(
 }
 
 if (rtems_ofw_get_enc_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -500,21 +500,21 @@ static phandle_t rtems_ofw_get_effective_phandle(
 )
 {
   phandle_t child;
-  phandle_t ref;
+  phandle_t ref[1];
 
   for (child = rtems_ofw_child(node); child != 0; child = 
rtems_ofw_peer(child)) {
-ref = rtems_ofw_get_effective_phandle(child, xref);
-if (ref != -1)
-  return ref;
+ref[0] = rtems_ofw_get_effective_phandle(child, xref);
+if (ref[0] != -1)
+  return ref[0];
 
-if (rtems_ofw_get_enc_prop(child, "phandle", &ref, sizeof(ref)) == -1 &&
-rtems_ofw_get_enc_prop(child, "ibm,phandle", &ref, sizeof(ref)) == -1 
&&
-rtems_ofw_get_enc_prop(child, "linux,phandle", &ref, sizeof(ref)) == -1
+if (rtems_ofw_get_enc_prop(child, "phandle", ref, sizeof(ref)) == -1 &&
+rtems_ofw_get_enc_prop(child, "ibm,phandle", ref, sizeof(ref)) == -1 &&
+rtems_ofw_get_enc_prop(child, "linux,phandle", ref, sizeof(ref)) == -1
 ) {
   continue;
 }
 
-if (ref == xref)
+if (ref[0] == xref)
   return child;
   }
 
@@ -533,16 +533,16 @@ phandle_t rtems_ofw_node_from_xref( phandle_t xref )
 
 phandle_t rtems_ofw_xref_from_node( phandle_t node )
 {
-  phandle_t ref;
+  phandle_t ref[1];
 
-if (rtems_ofw_get_enc_prop(node, "phandle", &ref, sizeof(ref)) == -1 &&
-rtems_ofw_get_enc_prop(node, "ibm,phandle", &ref, sizeof(ref)) == -1 &&
-rtems_ofw_get_enc_prop(node, "linux,phandle", &ref, sizeof(ref)) == -1)
+if (rtems_ofw_get_enc_prop(node, "phandle", ref, sizeof(ref)) == -1 &&
+rtems_ofw_get_enc_prop(node, "ibm,phandle", ref, sizeof(ref)) == -1 &&
+rtems_ofw_get_enc_prop(node, "linux,phandle", ref, sizeof(ref)) == -1)
 {
   return node;
 }
 
-return ref;
+return ref[0];
 }
 
 phandle_t rtems_ofw_instance_to_package( ihandle_t instance )
@@ -614,7 +614,7 @@ int rtems_ofw_get_reg(
 offset = rtems_fdt_phandle_to_offset(parent);
 ptr = fdt_getprop(fdtp, offset, "ranges", &len);
 
-if (len < 0) {
+if (ptr == NULL) {
   break;
 }
 
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH docs] user: remove old build system cmd

2021-02-03 Thread G S Niteesh Babu
---
 user/start/gsoc.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/user/start/gsoc.rst b/user/start/gsoc.rst
index f8167b9..2c7df7c 100644
--- a/user/start/gsoc.rst
+++ b/user/start/gsoc.rst
@@ -114,8 +114,8 @@ running `make` in the BSP build directory.
 
 .. code-block:: none
 
-  cd $HOME/quick-start/build/b-erc32
-  make
+  cd $HOME/quick-start/src/rtems
+  ./waf
 
 If you are happy with your changes you can commit the changes and send the 
patch
 to :r:list:`devel`.
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 0/4] bsps/shared/ofw: Bug and Coverity defect fixes

2021-02-05 Thread G S Niteesh Babu
The following series of patches fix bugs and coverity reported
defect in bsps/shared/ofw.c.

G S Niteesh Babu (4):
  bsps/shared/ofw: Fix coverity reported defects
  bsps/shared/ofw: Use memcpy instead of strncpy
  bsps/shared/ofw: Make rtems_ofw_get_effective_phandle iterative
  bsps/shared/ofw: Bug fixes

 bsps/shared/ofw/ofw.c | 35 ++-
 1 file changed, 22 insertions(+), 13 deletions(-)

-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 1/4] bsps/shared/ofw: Fix coverity reported defects

2021-02-05 Thread G S Niteesh Babu
Fixed use after free and null pointer dereference defects

FIXES:
1) CID 1472601 (NULL_RETURNS)
2) CID 1472600 (USE_AFTER_FREE)
3) CID 1472599 (USE_AFTER_FREE)
4) CID 1472598 (USE_AFTER_FREE)
5) CID 1472596 (USE_AFTER_FREE)

The below two defects have to marked false positive
1) CID 1472597 (ARRAY_VS_SINGLETON)
2) CID 1472595 (ARRAY_VS_SINGLETON)
---
 bsps/shared/ofw/ofw.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index 82924b2600..fa94bfbf05 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -313,7 +313,7 @@ ssize_t rtems_ofw_get_prop_alloc(
 }
 
 if (rtems_ofw_get_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -344,7 +344,7 @@ ssize_t rtems_ofw_get_prop_alloc_multi(
 }
 
 if (rtems_ofw_get_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -373,7 +373,7 @@ ssize_t rtems_ofw_get_enc_prop_alloc(
 }
 
 if (rtems_ofw_get_enc_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -404,7 +404,7 @@ ssize_t rtems_ofw_get_enc_prop_alloc_multi(
 }
 
 if (rtems_ofw_get_enc_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -614,7 +614,7 @@ int rtems_ofw_get_reg(
 offset = rtems_fdt_phandle_to_offset(parent);
 ptr = fdt_getprop(fdtp, offset, "ranges", &len);
 
-if (len < 0) {
+if (ptr == NULL) {
   break;
 }
 
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 2/4] bsps/shared/ofw: Use memcpy instead of strncpy

2021-02-05 Thread G S Niteesh Babu
Changed rtems_ofw_get_prop to use memcpy instead of strncpy
---
 bsps/shared/ofw/ofw.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index fa94bfbf05..9dec310247 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -198,7 +198,15 @@ ssize_t rtems_ofw_get_prop(
 
   if (prop == NULL && strcmp(propname, "name") == 0) {
 prop = fdt_get_name(fdtp, offset, &len);
-strncpy(buf, prop, bufsize);
+
+bufsize = MIN(len, bufsize - 1);
+memcpy(buf, prop, bufsize);
+
+/* Null terminate the buffer */
+*((char *)buf + bufsize) = 0;
+
+/* Return the length of the name including the null byte */
+/* This is the behaviour in libBSD ofw_fdt_getprop */
 return len + 1;
   }
 
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 3/4] bsps/shared/ofw: Make rtems_ofw_get_effective_phandle iterative

2021-02-05 Thread G S Niteesh Babu
Refactored recursive rtems_ofw_get_effective_phandle into a
iterative function.
---
 bsps/shared/ofw/ofw.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index 9dec310247..e3626747fa 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -509,11 +509,12 @@ static phandle_t rtems_ofw_get_effective_phandle(
 {
   phandle_t child;
   phandle_t ref;
+  int node_offset;
 
-  for (child = rtems_ofw_child(node); child != 0; child = 
rtems_ofw_peer(child)) {
-ref = rtems_ofw_get_effective_phandle(child, xref);
-if (ref != -1)
-  return ref;
+  node_offset = fdt_path_offset(fdtp, "/");
+
+  while ((node_offset = fdt_next_node(fdtp, node_offset, NULL)) > 0) {
+child = rtems_fdt_offset_to_phandle(node_offset);
 
 if (rtems_ofw_get_enc_prop(child, "phandle", &ref, sizeof(ref)) == -1 &&
 rtems_ofw_get_enc_prop(child, "ibm,phandle", &ref, sizeof(ref)) == -1 
&&
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 4/4] bsps/shared/ofw: Bug fixes

2021-02-05 Thread G S Niteesh Babu
Fixed bugs in rtems_ofw_get_prop, rtems_ofw_get_prop_len
and removed hardcoded value.
---
 bsps/shared/ofw/ofw.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index e3626747fa..8b7f77311d 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -162,7 +162,7 @@ ssize_t rtems_ofw_get_prop_len(
 return len + 1;
   }
 
-  if (prop == NULL && strcmp(propname, "/chosen") == 0) {
+  if (prop == NULL && offset == fdt_path_offset(fdtp, "/chosen")) {
 if (strcmp(propname, "fdtbootcpu") == 0)
   return sizeof(pcell_t);
 if (strcmp(propname, "fdtmemreserv") == 0)
@@ -210,7 +210,7 @@ ssize_t rtems_ofw_get_prop(
 return len + 1;
   }
 
-  if (prop == NULL && strcmp(propname, "/chosen") == 0) {
+  if (prop == NULL && offset == fdt_path_offset(fdtp, "/chosen")) {
 if (strcmp(propname, "fdtbootcpu") == 0) {
   cpuid = cpu_to_fdt32(fdt_boot_cpuid_phys(fdtp));
   len = sizeof(cpuid);
@@ -240,7 +240,7 @@ ssize_t rtems_ofw_get_enc_prop(
 {
   ssize_t rv;
 
-  assert(len % 4 == 0);
+  assert(len % sizeof(pcell_t) == 0);
   rv = rtems_ofw_get_prop(node, prop, buf, len);
 
   if (rv < 0) {
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v2 2/4] bsps/shared/ofw: Use strlcpy instead of strncpy

2021-02-06 Thread G S Niteesh Babu
Changed rtems_ofw_get_prop to use strlcpy instead of strncpy
to ensure the buffer is null terminated incase of overflow.
---
 bsps/shared/ofw/ofw.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index fa94bfbf05..886ad0252b 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -198,7 +198,15 @@ ssize_t rtems_ofw_get_prop(
 
   if (prop == NULL && strcmp(propname, "name") == 0) {
 prop = fdt_get_name(fdtp, offset, &len);
-strncpy(buf, prop, bufsize);
+
+/* Node name's are 1-31 chars in length consisting of only
+ * ascii chars and are null terminated */
+strlcpy(buf, prop, bufsize);
+
+/* Return the length of the name including the null byte
+ * rather than the amount copied.
+ * This is the behaviour in libBSD ofw_fdt_getprop
+ */
 return len + 1;
   }
 
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v2 1/4] bsps/shared/ofw: Fix coverity reported defects

2021-02-06 Thread G S Niteesh Babu
Fixed use after free and null pointer dereference defects

FIXES:
1) CID 1472601 (NULL_RETURNS)
2) CID 1472600 (USE_AFTER_FREE)
3) CID 1472599 (USE_AFTER_FREE)
4) CID 1472598 (USE_AFTER_FREE)
5) CID 1472596 (USE_AFTER_FREE)

The below two defects have to marked false positive
1) CID 1472597 (ARRAY_VS_SINGLETON)
2) CID 1472595 (ARRAY_VS_SINGLETON)
---
 bsps/shared/ofw/ofw.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index 82924b2600..fa94bfbf05 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -313,7 +313,7 @@ ssize_t rtems_ofw_get_prop_alloc(
 }
 
 if (rtems_ofw_get_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -344,7 +344,7 @@ ssize_t rtems_ofw_get_prop_alloc_multi(
 }
 
 if (rtems_ofw_get_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -373,7 +373,7 @@ ssize_t rtems_ofw_get_enc_prop_alloc(
 }
 
 if (rtems_ofw_get_enc_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -404,7 +404,7 @@ ssize_t rtems_ofw_get_enc_prop_alloc_multi(
 }
 
 if (rtems_ofw_get_enc_prop(node, propname, *buf, len) == -1) {
-  rtems_ofw_free(buf);
+  rtems_ofw_free(*buf);
   *buf = NULL;
   return -1;
 }
@@ -614,7 +614,7 @@ int rtems_ofw_get_reg(
 offset = rtems_fdt_phandle_to_offset(parent);
 ptr = fdt_getprop(fdtp, offset, "ranges", &len);
 
-if (len < 0) {
+if (ptr == NULL) {
   break;
 }
 
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v2 0/4] bsps/shared/ofw: Bug and Coverity defect fixes

2021-02-06 Thread G S Niteesh Babu
Update since v1: Using strlcpy instead of memcpy

The following series of patches fix bugs and coverity reported
defect in bsps/shared/ofw.c.

G S Niteesh Babu (4):
  bsps/shared/ofw: Fix coverity reported defects
  bsps/shared/ofw: Use strlcpy instead of strncpy
  bsps/shared/ofw: Make rtems_ofw_get_effective_phandle iterative
  bsps/shared/ofw: Bug fixes

 bsps/shared/ofw/ofw.c | 35 ++-
 1 file changed, 22 insertions(+), 13 deletions(-)

-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v2 4/4] bsps/shared/ofw: Bug fixes

2021-02-06 Thread G S Niteesh Babu
Fixed bugs in rtems_ofw_get_prop, rtems_ofw_get_prop_len
and removed hardcoded value.
---
 bsps/shared/ofw/ofw.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index 78576ecf45..1c3a81785d 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -162,7 +162,7 @@ ssize_t rtems_ofw_get_prop_len(
 return len + 1;
   }
 
-  if (prop == NULL && strcmp(propname, "/chosen") == 0) {
+  if (prop == NULL && offset == fdt_path_offset(fdtp, "/chosen")) {
 if (strcmp(propname, "fdtbootcpu") == 0)
   return sizeof(pcell_t);
 if (strcmp(propname, "fdtmemreserv") == 0)
@@ -210,7 +210,7 @@ ssize_t rtems_ofw_get_prop(
 return len + 1;
   }
 
-  if (prop == NULL && strcmp(propname, "/chosen") == 0) {
+  if (prop == NULL && offset == fdt_path_offset(fdtp, "/chosen")) {
 if (strcmp(propname, "fdtbootcpu") == 0) {
   cpuid = cpu_to_fdt32(fdt_boot_cpuid_phys(fdtp));
   len = sizeof(cpuid);
@@ -240,7 +240,7 @@ ssize_t rtems_ofw_get_enc_prop(
 {
   ssize_t rv;
 
-  assert(len % 4 == 0);
+  assert(len % sizeof(pcell_t) == 0);
   rv = rtems_ofw_get_prop(node, prop, buf, len);
 
   if (rv < 0) {
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH v2 3/4] bsps/shared/ofw: Make rtems_ofw_get_effective_phandle iterative

2021-02-06 Thread G S Niteesh Babu
Refactored recursive rtems_ofw_get_effective_phandle into a
iterative function.
---
 bsps/shared/ofw/ofw.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/bsps/shared/ofw/ofw.c b/bsps/shared/ofw/ofw.c
index 886ad0252b..78576ecf45 100644
--- a/bsps/shared/ofw/ofw.c
+++ b/bsps/shared/ofw/ofw.c
@@ -509,11 +509,12 @@ static phandle_t rtems_ofw_get_effective_phandle(
 {
   phandle_t child;
   phandle_t ref;
+  int node_offset;
 
-  for (child = rtems_ofw_child(node); child != 0; child = 
rtems_ofw_peer(child)) {
-ref = rtems_ofw_get_effective_phandle(child, xref);
-if (ref != -1)
-  return ref;
+  node_offset = fdt_path_offset(fdtp, "/");
+
+  while ((node_offset = fdt_next_node(fdtp, node_offset, NULL)) > 0) {
+child = rtems_fdt_offset_to_phandle(node_offset);
 
 if (rtems_ofw_get_enc_prop(child, "phandle", &ref, sizeof(ref)) == -1 &&
 rtems_ofw_get_enc_prop(child, "ibm,phandle", &ref, sizeof(ref)) == -1 
&&
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] RTEMS Docs: Fix search field

2020-02-22 Thread G S Niteesh Babu
This patch fixes the search field which previously was not working
due to this commit 71dd8bfbf94417ad55b2444e1dbd219db266f335 in
sphinx.
---
 common/sphinx_rtd_theme_rtems/layout.html | 3 ++-
 common/sphinx_rtd_theme_rtems/layout_old.html | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/common/sphinx_rtd_theme_rtems/layout.html 
b/common/sphinx_rtd_theme_rtems/layout.html
index 44978c9..ca63b80 100644
--- a/common/sphinx_rtd_theme_rtems/layout.html
+++ b/common/sphinx_rtd_theme_rtems/layout.html
@@ -167,7 +167,8 @@
 VERSION:'{{ release|e }}',
 COLLAPSE_INDEX:false,
 FILE_SUFFIX:'{{ '' if no_search_suffix else file_suffix }}',
-HAS_SOURCE:  {{ has_source|lower }}
+HAS_SOURCE:  {{ has_source|lower }},
+SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}'
 };
 
 {%- for scriptfile in script_files %}
diff --git a/common/sphinx_rtd_theme_rtems/layout_old.html 
b/common/sphinx_rtd_theme_rtems/layout_old.html
index deb8df2..f0dc2af 100644
--- a/common/sphinx_rtd_theme_rtems/layout_old.html
+++ b/common/sphinx_rtd_theme_rtems/layout_old.html
@@ -91,7 +91,8 @@
 VERSION: '{{ release|e }}',
 COLLAPSE_INDEX: false,
 FILE_SUFFIX: '{{ '' if no_search_suffix else file_suffix }}',
-HAS_SOURCE:  {{ has_source|lower }}
+HAS_SOURCE:  {{ has_source|lower }},
+SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}'
   };
 
 {%- for scriptfile in script_files %}
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel