[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", , sizeof(ref)) == -1 &&
 rtems_ofw_get_enc_prop(node, "ibm,phandle", , 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", );
 
-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", , sizeof(ref)) == -1 &&
-rtems_ofw_get_enc_prop(child, "ibm,phandle", , sizeof(ref)) == -1 
&&
-rtems_ofw_get_enc_prop(child, "linux,phandle", , 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", , sizeof(ref)) == -1 &&
-rtems_ofw_get_enc_prop(node, "ibm,phandle", , sizeof(ref)) == -1 &&
-rtems_ofw_get_enc_prop(node, "linux,phandle", , 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", );
 
-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 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([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 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([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/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 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", , sizeof(ref)) == -1 &&
 rtems_ofw_get_enc_prop(child, "ibm,phandle", , 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 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", );
 
-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, );
-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 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
+  

[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", 

[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( >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, , sizeof(irq));

[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 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( >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 )( >base );
 rtems_set_errno_and_return_minus_one( err );
   }
-  am335x_i2c_module_clk_enable(bus);
-  am335x_i2c_pinmux( bus );
+

[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 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", >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", >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 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", >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", >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 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", );
 
-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", , sizeof(ref)) == -1 &&
 rtems_ofw_get_enc_prop(child, "ibm,phandle", , sizeof(ref)) == -1 
&&
-- 
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, );
-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


<    1   2