[PATCH rtems-libbsd 04/14] pci: Back port changes

2024-01-23 Thread Christian Mauderer
From: Sebastian Huber 

---
 freebsd/sys/dev/pci/pci.c | 3 ++-
 freebsd/sys/dev/pci/pci_pci.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/freebsd/sys/dev/pci/pci.c b/freebsd/sys/dev/pci/pci.c
index 0cc72dba..3789a73e 100644
--- a/freebsd/sys/dev/pci/pci.c
+++ b/freebsd/sys/dev/pci/pci.c
@@ -233,7 +233,8 @@ static device_method_t pci_methods[] = {
 DEFINE_CLASS_0(pci, pci_driver, pci_methods, sizeof(struct pci_softc));
 
 static devclass_t pci_devclass;
-DRIVER_MODULE(pci, pcib, pci_driver, pci_devclass, pci_modevent, NULL);
+EARLY_DRIVER_MODULE(pci, pcib, pci_driver, pci_devclass, pci_modevent, NULL,
+BUS_PASS_BUS);
 MODULE_VERSION(pci, 1);
 
 static char*pci_vendordata;
diff --git a/freebsd/sys/dev/pci/pci_pci.c b/freebsd/sys/dev/pci/pci_pci.c
index 5ba3e9a0..c1e73a3c 100644
--- a/freebsd/sys/dev/pci/pci_pci.c
+++ b/freebsd/sys/dev/pci/pci_pci.c
@@ -136,7 +136,8 @@ static device_method_t pcib_methods[] = {
 static devclass_t pcib_devclass;
 
 DEFINE_CLASS_0(pcib, pcib_driver, pcib_methods, sizeof(struct pcib_softc));
-DRIVER_MODULE(pcib, pci, pcib_driver, pcib_devclass, NULL, NULL);
+EARLY_DRIVER_MODULE(pcib, pci, pcib_driver, pcib_devclass, NULL, NULL,
+BUS_PASS_BUS);
 
 #if defined(NEW_PCIB) || defined(PCI_HP)
 SYSCTL_DECL(_hw_pci);
-- 
2.35.3

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


[PATCH 1/3] bsps/qoriq: Add MMU regions for PCIe based on fdt

2024-01-23 Thread Christian Mauderer
Get the memory ranges for the PCIe from the FDT and add them to the MMU.
This is necessary so that the PCIe driver in libbsd can work.
---
 bsps/powerpc/qoriq/start/mmu-config.c | 88 +++
 1 file changed, 88 insertions(+)

diff --git a/bsps/powerpc/qoriq/start/mmu-config.c 
b/bsps/powerpc/qoriq/start/mmu-config.c
index 58b08c8349..15e4a83fc4 100644
--- a/bsps/powerpc/qoriq/start/mmu-config.c
+++ b/bsps/powerpc/qoriq/start/mmu-config.c
@@ -305,6 +305,92 @@ static void TEXT config_fdt_adjust(const void *fdt)
}
 }
 
+/*
+ * Each PCIe controller has a ranges attribute in the fdt like the following:
+ *
+ *   ranges = <0x200 0x00 0xc000 0x00 0xc000 0x00 0x2000
+ * 0x100 0x00 0x 0x00 0xffc2 0x00 0x0001>;
+ * |--PCI address--| |-CPU address-| |-size|
+ *
+ * In theory, some fdt-attributes should be used to find out how long the PCI
+ * address (#address-cells of the PCIe node), the CPU address (#address-cells 
of
+ * the parent node) and the size (#size-cells of the PCIe node) are. In our 
case
+ * the structure is fixed because the pcie root controllers are a part of the
+ * chip. Therefore the sizes will never change and we can assume fixed lengths.
+ *
+ * The first cell of the PCI address holds a number of flags. A detailed
+ * explanation can be found for example here:
+ *
+ * 
https://web.archive.org/web/20240109080338/https://michael2012z.medium.com/understanding-pci-node-in-fdt-769a894a13cc
+ *
+ * We are only interested in the entry with the flags 0x0200 which 
basically
+ * means that it is a non-relocatable, non-prefetchable, not-aliased 32 bit
+ * memory space on the first bus.
+ *
+ * The other two cells of the PCI address are a 64 Bit address viewed from PCI
+ * address space. The two CPU address cells are the same 64 Bit address viewed
+ * from CPU address space. For our controller these two should always be the
+ * same (no address translation). The last two cells give a size of the memory
+ * region (in theory in PCI address space but it has to be the same for CPU and
+ * PCI).
+ */
+static void TEXT add_pcie_regions(qoriq_mmu_context *context, const void *fdt)
+{
+   int node;
+
+   node = -1;
+
+   while (true) {
+   static const size_t range_length = 7 * 4;
+   const void *val;
+   int len;
+
+   node = fdt_node_offset_by_compatible(
+   fdt,
+   node,
+   "fsl,mpc8548-pcie"
+   );
+   if (node < 0) {
+   break;
+   }
+
+   val = fdt_getprop(fdt, node, "ranges", &len);
+   if (len % range_length != 0) {
+   continue;
+   }
+
+   while (len >= range_length) {
+   uint32_t pci_addr_flags;
+   uintptr_t pci_addr;
+   uintptr_t cpu_addr;
+   uintptr_t size;
+   const uint32_t *cells;
+
+   cells = val;
+   pci_addr_flags = fdt32_to_cpu(cells[0]);
+   pci_addr = fdt64_to_cpu(*(fdt64_t *)(&cells[1]));
+   cpu_addr = fdt64_to_cpu(*(fdt64_t *)(&cells[3]));
+   size = fdt64_to_cpu(*(fdt64_t *)(&cells[5]));
+
+   if (pci_addr_flags == 0x0200 &&
+   pci_addr == cpu_addr) {
+   /* Add as I/O memory */
+   qoriq_mmu_add(
+   context,
+   cpu_addr,
+   cpu_addr + size - 1,
+   0,
+   FSL_EIS_MAS2_I | FSL_EIS_MAS2_G,
+   FSL_EIS_MAS3_SR | FSL_EIS_MAS3_SW,
+   0
+   );
+   }
+   len -= range_length;
+   val += range_length;
+   }
+   }
+}
+
 void TEXT qoriq_mmu_config(bool boot_processor, int first_tlb, int scratch_tlb)
 {
qoriq_mmu_context context;
@@ -349,6 +435,8 @@ void TEXT qoriq_mmu_config(bool boot_processor, int 
first_tlb, int scratch_tlb)
}
}
 
+   add_pcie_regions(&context, fdt);
+
qoriq_mmu_partition(&context, max_count);
qoriq_mmu_write_to_tlb1(&context, first_tlb);
 }
-- 
2.35.3

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


[PATCH 2/3] bsps/qoriq: Allow setting EIRQ polarity and sense

2024-01-23 Thread Christian Mauderer
Add a function that allows to set the polarity (active-low / negative
edge triggered or active-high / positive edge triggered) and sense
(level or edge sensitive) of the external interrupts.
---
 bsps/powerpc/qoriq/include/bsp/irq.h | 27 ++
 bsps/powerpc/qoriq/irq/irq.c | 56 
 2 files changed, 83 insertions(+)

diff --git a/bsps/powerpc/qoriq/include/bsp/irq.h 
b/bsps/powerpc/qoriq/include/bsp/irq.h
index 5719701d02..f197f7ab6e 100644
--- a/bsps/powerpc/qoriq/include/bsp/irq.h
+++ b/bsps/powerpc/qoriq/include/bsp/irq.h
@@ -279,6 +279,8 @@ extern "C" {
 #define QORIQ_IRQ_EXT_10 (QORIQ_IRQ_EXT_BASE + 10)
 #define QORIQ_IRQ_EXT_11 (QORIQ_IRQ_EXT_BASE + 11)
 
+#define QORIQ_IRQ_IS_EXT(vector) \
+  ((vector) >= QORIQ_IRQ_EXT_0 && (vector) <= QORIQ_IRQ_EXT_11)
 /** @} */
 
 /**
@@ -429,6 +431,31 @@ rtems_status_code qoriq_pic_msi_map(
   uint32_t *data
 );
 
+typedef enum {
+  QORIQ_EIRQ_TRIGGER_EDGE_FALLING,
+  QORIQ_EIRQ_TRIGGER_EDGE_RISING,
+  QORIQ_EIRQ_TRIGGER_LEVEL_LOW,
+  QORIQ_EIRQ_TRIGGER_LEVEL_HIGH,
+} qoriq_eirq_sense_and_polarity;
+
+/**
+ * @brief Change polarity and sense settings of external interrupts.
+ *
+ * NOTE: There are only very rare edge cases where you need this function.
+ *
+ * @a vector must be the vector number of an external interrupt.
+ *
+ * Use @a new_sense_and_polarity to select the new setting. If @a
+ * old_sense_and_polarity is not NULL, the old value is returned.
+ *
+ * @returns RTEMS_SUCCSSSFUL on sucess or other values for invalid settings.
+ */
+rtems_status_code qoriq_pic_set_sense_and_polarity(
+  rtems_vector_number vector,
+  qoriq_eirq_sense_and_polarity new_sense_and_polarity,
+  qoriq_eirq_sense_and_polarity *old_sense_and_polarity
+);
+
 /** @} */
 
 #ifdef __cplusplus
diff --git a/bsps/powerpc/qoriq/irq/irq.c b/bsps/powerpc/qoriq/irq/irq.c
index 1a650ddc83..8d6afa6c12 100644
--- a/bsps/powerpc/qoriq/irq/irq.c
+++ b/bsps/powerpc/qoriq/irq/irq.c
@@ -338,6 +338,62 @@ rtems_status_code qoriq_pic_set_priority(
return sc;
 }
 
+rtems_status_code qoriq_pic_set_sense_and_polarity(
+  rtems_vector_number vector,
+  qoriq_eirq_sense_and_polarity new_sense_and_polarity,
+  qoriq_eirq_sense_and_polarity *old_sense_and_polarity
+)
+{
+   rtems_status_code sc = RTEMS_SUCCESSFUL;
+   uint32_t old_vpr = 0;
+   volatile qoriq_pic_src_cfg *src_cfg;
+   rtems_interrupt_lock_context lock_context;
+   uint32_t new_p_s = 0;
+
+   if (!QORIQ_IRQ_IS_EXT(vector)) {
+   return RTEMS_UNSATISFIED;
+   }
+
+   if (new_sense_and_polarity == QORIQ_EIRQ_TRIGGER_EDGE_RISING ||
+   new_sense_and_polarity == QORIQ_EIRQ_TRIGGER_LEVEL_HIGH) {
+   new_p_s |= VPR_P;
+   }
+
+   if (new_sense_and_polarity == QORIQ_EIRQ_TRIGGER_LEVEL_HIGH ||
+   new_sense_and_polarity == QORIQ_EIRQ_TRIGGER_LEVEL_LOW) {
+   new_p_s |= VPR_S;
+   }
+
+   src_cfg = get_src_cfg(vector);
+
+   rtems_interrupt_lock_acquire(&lock, &lock_context);
+   old_vpr = src_cfg->vpr;
+   src_cfg->vpr = (old_vpr & ~(VPR_P | VPR_S)) | new_p_s;
+   rtems_interrupt_lock_release(&lock, &lock_context);
+
+   if (old_sense_and_polarity != NULL) {
+   if ((old_vpr & VPR_P) == 0) {
+   if ((old_vpr & VPR_S) == 0) {
+   *old_sense_and_polarity =
+   QORIQ_EIRQ_TRIGGER_EDGE_FALLING;
+   } else {
+   *old_sense_and_polarity =
+   QORIQ_EIRQ_TRIGGER_LEVEL_LOW;
+   }
+   } else {
+   if ((old_vpr & VPR_S) == 0) {
+   *old_sense_and_polarity =
+   QORIQ_EIRQ_TRIGGER_EDGE_RISING;
+   } else {
+   *old_sense_and_polarity =
+   QORIQ_EIRQ_TRIGGER_LEVEL_HIGH;
+   }
+   }
+   }
+
+   return sc;
+}
+
 rtems_status_code bsp_interrupt_set_affinity(
rtems_vector_number vector,
const Processor_mask *affinity
-- 
2.35.3

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


[PATCH rtems-libbsd 01/14] sys/bus.h: Fix for small-data area targets

2024-01-23 Thread Christian Mauderer
From: Sebastian Huber 

---
 freebsd/sys/sys/buf.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/freebsd/sys/sys/buf.h b/freebsd/sys/sys/buf.h
index 209174b4..dfe3eaa6 100644
--- a/freebsd/sys/sys/buf.h
+++ b/freebsd/sys/sys/buf.h
@@ -497,7 +497,11 @@ extern int cluster_pbuf_freecnt;   /* Number of pbufs for 
clusters */
 extern int vnode_pbuf_freecnt; /* Number of pbufs for vnode pager */
 extern int vnode_async_pbuf_freecnt; /* Number of pbufs for vnode pager,
 asynchronous reads */
+#ifndef __rtems__
 extern caddr_t unmapped_buf;   /* Data address for unmapped buffers. */
+#else /* __rtems__ */
+extern caddr_t __read_mostly unmapped_buf;
+#endif /* __rtems__ */
 
 static inline int
 buf_mapped(struct buf *bp)
-- 
2.35.3

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


[PATCHES rtems, libbsd] Add PCIe and VME support for qoriq

2024-01-23 Thread Christian Mauderer
Hello,

the attached patch set for RTEMS and libbsd adds initial support of the
Tsi148 VME bridge on the MVME2500 board using the qoriq BSP. Basically
it consists of the following parts:

- Add PCIe ranges to the qoriq MMU configuration (based on FDT).
- Add the existing VME support files to the qoriq BSP.
- Allow to set up the necessary interrupt level and polarity in the BSP.
- Add a matching VMEConfig.h to the BSP.
- Add PCIe support for the qoriq to libbsd.
- Add a glue layer to libbsd that allows the Tsi148 driver to use the
  BSP Tsi148 driver.

The VME parts are only active, if `tsi148` is set to on in the buildset
in libbsd. Otherwise, no VME parts will be linked into the application.

Please note that the libbsd patches currently can only be applied to
6-freebsd-12. The master branch is a few months behind the 6-freebsd-12
in the FreeBSD development. Unluckily, the PCIe driver has been adapted
to this controller in these months. Backporting the driver would pull in
a other system changes which would make a later update of the master
branch in libbsd harder. So I currently plan to only apply the patches
to 6-freebsd-12 for now.

With kind regards

Christian Mauderer


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


[PATCH 3/3] bsps/qoriq: Add VME support for MVME2500

2024-01-23 Thread Christian Mauderer
This enables the VME support for the MVME2500. Note that the PCIe
support from libbsd is used. So you need the related libbsd patches for
this to work.

If the drivers in libbsd are not enabled, the linker should not pick up
anything from this patch.
---
 bsps/powerpc/qoriq/include/bsp/VMEConfig.h | 50 ++
 spec/build/bsps/powerpc/qoriq/grp.yml  |  2 +
 spec/build/bsps/powerpc/qoriq/obj.yml  |  3 +-
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/bsps/powerpc/qoriq/include/bsp/VMEConfig.h 
b/bsps/powerpc/qoriq/include/bsp/VMEConfig.h
index 79c22d137a..4bb7c0d62f 100644
--- a/bsps/powerpc/qoriq/include/bsp/VMEConfig.h
+++ b/bsps/powerpc/qoriq/include/bsp/VMEConfig.h
@@ -7,6 +7,9 @@
  *
  * @brief This header file provides the interfaces used by VME bus device
  *   drivers.
+ *
+ * Note that for the MVME2500, you need the PCIe support from libbsd for this 
to
+ * work.
  */
 
 /*
@@ -43,6 +46,53 @@ extern "C" {
 
 #define _VME_DRIVER_TSI148
 
+/*
+ * Base address of the PCI that is used for the VME bridge. Value is set in
+ * libbsd during device discovery.
+ */
+extern uintptr_t bsp_vme_pcie_base_address;
+
+#define PCI_MEM_BASE 0
+#define PCI_DRAM_OFFSET 0
+
+/*
+ * NOTE: shared vmeconfig.c uses hardcoded window lengths that match this 
layout
+ *
+ * The memory length of the PCIe controllers on the P2020 processor is
+ * 0x2000. The Tsi148 registers are mapped at the bsp_vme_pcie_base_address
+ * with a size of 0x1000. Therefore the VME windows are arranged a bit 
different
+ * then on other BSPs.
+ */
+#define _VME_A32_WIN0_ON_PCI   (bsp_vme_pcie_base_address + 0x1000)
+#define _VME_A24_ON_PCI(bsp_vme_pcie_base_address + 0x0300)
+#define _VME_A16_ON_PCI(bsp_vme_pcie_base_address + 0x0200)
+#define _VME_CSR_ON_PCI(bsp_vme_pcie_base_address + 0x0100)
+
+/* FIXME: Make this a BSP config option */
+#define _VME_A32_WIN0_ON_VME 0x2000
+
+/*
+ * FIXME: The fixed QORIQ_IRQ_EXT_0 is valid for the MVME2500 board. In theory
+ * there should be some possibility to get that information from the device 
tree
+ * or from PCI config space. But I didn't find it anywhere.
+ */
+#define BSP_VME_INSTALL_IRQ_MGR(err) \
+  do { \
+err = qoriq_pic_set_sense_and_polarity(\
+  QORIQ_IRQ_EXT_0, \
+  QORIQ_EIRQ_TRIGGER_LEVEL_LOW, \
+  NULL \
+); \
+if (err == 0) { \
+  err = vmeTsi148InstallIrqMgrAlt(0, 0, QORIQ_IRQ_EXT_0, -1); \
+} \
+  } while (0)
+
+/* Add prototypes that are in all VMEConfig.h files */
+extern int BSP_VMEInit(void);
+extern int BSP_VMEIrqMgrInstall(void);
+extern unsigned short (*_BSP_clear_vmebridge_errors)(int);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/spec/build/bsps/powerpc/qoriq/grp.yml 
b/spec/build/bsps/powerpc/qoriq/grp.yml
index 2acb506c89..65e623fdbd 100644
--- a/spec/build/bsps/powerpc/qoriq/grp.yml
+++ b/spec/build/bsps/powerpc/qoriq/grp.yml
@@ -28,6 +28,8 @@ links:
   uid: ../obj
 - role: build-dependency
   uid: ../objexc
+- role: build-dependency
+  uid: ../objvme
 - role: build-dependency
   uid: abi
 - role: build-dependency
diff --git a/spec/build/bsps/powerpc/qoriq/obj.yml 
b/spec/build/bsps/powerpc/qoriq/obj.yml
index 8926cc2135..b0ab1e6ca2 100644
--- a/spec/build/bsps/powerpc/qoriq/obj.yml
+++ b/spec/build/bsps/powerpc/qoriq/obj.yml
@@ -17,6 +17,7 @@ install:
   - bsps/powerpc/qoriq/include/asm/fsl_hcalls.h
 - destination: ${BSP_INCLUDEDIR}/bsp
   source:
+  - bsps/powerpc/qoriq/include/bsp/VMEConfig.h
   - bsps/powerpc/qoriq/include/bsp/intercom.h
   - bsps/powerpc/qoriq/include/bsp/irq.h
   - bsps/powerpc/qoriq/include/bsp/mmu.h
@@ -63,8 +64,6 @@ source:
 - bsps/powerpc/shared/start/bsp-start-zero.S
 - bsps/powerpc/shared/start/bspidle.c
 - bsps/powerpc/shared/start/tictac.c
-- bsps/powerpc/shared/vme/bspVmeDmaList.c
-- bsps/powerpc/shared/vme/vmeTsi148.c
 - bsps/shared/dev/getentropy/getentropy-cpucounter.c
 - bsps/shared/dev/rtc/rtc-support.c
 - bsps/shared/dev/serial/console-termios-init.c
-- 
2.35.3

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


[PATCH rtems-libbsd 14/14] testsuite: Add a VME test

2024-01-23 Thread Christian Mauderer
Note: This test currently only works with a board with a Tsi148 like the
MVME2500. For other boards it will print only a message.
---
 libbsd.py   |  2 +
 testsuite/vme01/test_main.c | 80 +
 2 files changed, 82 insertions(+)
 create mode 100644 testsuite/vme01/test_main.c

diff --git a/libbsd.py b/libbsd.py
index b05ea069..3fa2c8f3 100644
--- a/libbsd.py
+++ b/libbsd.py
@@ -5631,6 +5631,8 @@ class tests(builder.Module):
 self.addTest(mm.generator['test']('openssl01', ['test_main']))
 self.addTest(mm.generator['test']('openssl02', ['test_main']))
 self.addTest(mm.generator['test']('tcpdump01', ['test_main']))
+self.addTest(mm.generator['test']('vme01', ['test_main'],
+  runTest = False))
 
 def load(mm):
 
diff --git a/testsuite/vme01/test_main.c b/testsuite/vme01/test_main.c
new file mode 100644
index ..fe6c1072
--- /dev/null
+++ b/testsuite/vme01/test_main.c
@@ -0,0 +1,80 @@
+/**
+ * @file
+ *
+ * @brief A test for VME interrupts.
+ */
+
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) 2023 embedded brains GmbH & Co. KG
+ *
+ * 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.
+ */
+
+#define TEST_NAME "LIBBSD VME 1"
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#if defined(RTEMS_BSD_MODULE_TSI148) && defined(LIBBSP_POWERPC_QORIQ_BSP_H)
+
+#include 
+
+static void
+test_main(void)
+{
+   int error = 0;
+
+   for (int vec = 42; vec < 43; ++vec) {
+   for (int lvl = 7; lvl > 0; --lvl) {
+   int x = vmeTsi148IntLoopbackTst(lvl, vec);
+   printf("Tsi Interrupt test lvl %d, vec %d: %d\n",
+   lvl, vec, x);
+   if (x != 0) {
+   error = x;
+   }
+   }
+   }
+
+   exit(error);
+}
+
+#else /* RTEMS_BSD_MODULE_TSI148 */
+
+static void
+test_main(void)
+{
+   puts("VME not enabled in the current build set or not available on this 
BSP.");
+   exit(0);
+}
+
+#endif /* RTEMS_BSD_MODULE_TSI148 */
+
+#define RTEMS_BSD_CONFIG_BSP_CONFIG
+
+#include 
+
-- 
2.35.3

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


[PATCH rtems-libbsd 13/14] tsi148: Add an RTEMS VME glue layer

2024-01-23 Thread Christian Mauderer
The glue layer provides the necessary function so that the Tsi148 driver
in the BSP can use the PCI functionality from libbsd.
---
 libbsd.py   |   1 +
 rtemsbsd/sys/dev/vme/tsi148.c   |  24 +++-
 rtemsbsd/sys/dev/vme/vme-rtems-compat.c | 143 
 3 files changed, 167 insertions(+), 1 deletion(-)
 create mode 100644 rtemsbsd/sys/dev/vme/vme-rtems-compat.c

diff --git a/libbsd.py b/libbsd.py
index ed40106c..b05ea069 100644
--- a/libbsd.py
+++ b/libbsd.py
@@ -3152,6 +3152,7 @@ class tsi148(builder.Module):
 self.addRTEMSKernelSourceFiles(
 [
 'sys/dev/vme/tsi148.c',
+'sys/dev/vme/vme-rtems-compat.c',
 ],
 mm.generator['source']()
 )
diff --git a/rtemsbsd/sys/dev/vme/tsi148.c b/rtemsbsd/sys/dev/vme/tsi148.c
index 56c746bc..99c3cfcd 100644
--- a/rtemsbsd/sys/dev/vme/tsi148.c
+++ b/rtemsbsd/sys/dev/vme/tsi148.c
@@ -27,6 +27,10 @@
 
 #include 
 
+#include 
+#ifdef LIBBSP_POWERPC_QORIQ_BSP_H
+#include 
+
 #include 
 #include 
 #include 
@@ -37,6 +41,8 @@
 #include 
 #include 
 
+#include 
+
 struct tsi148 {
device_tdev;
int mem_rid;
@@ -52,6 +58,13 @@ tsi148_intr(void *arg)
struct tsi148 *sc;
 
sc = arg;
+
+   /*
+* Note: This interrupt is never used. It would be used in case of MSIs.
+* But the Tsi148 can't generate them. So this interrupt must never
+* happen.
+*/
+   puts("tsi148_intr: Unexpected interrupt. Should never happen.\n");
 }
 
 static int
@@ -71,6 +84,11 @@ tsi148_attach(device_t dev)
 {
struct tsi148 *sc;
 
+   if (bsp_vme_pcie_base_address != 0) {
+   puts("tsi148: Another instance is already attached.\n");
+   return (ENXIO);
+   }
+
sc = device_get_softc(dev);
sc->dev = dev;
 
@@ -94,7 +112,10 @@ tsi148_attach(device_t dev)
return (ENOMEM);
}
 
-   return (ENXIO);
+   bsp_vme_pcie_base_address = sc->mem_res->r_bushandle;
+   BSP_vme_config();
+
+   return 0;
 }
 
 static int
@@ -121,3 +142,4 @@ static driver_t tsi148_driver = {
 static devclass_t tsi148_devclass;
 
 DRIVER_MODULE(tsi148, pci, tsi148_driver, tsi148_devclass, NULL, 0);
+#endif /* LIBBSP_POWERPC_QORIQ_BSP_H */
diff --git a/rtemsbsd/sys/dev/vme/vme-rtems-compat.c 
b/rtemsbsd/sys/dev/vme/vme-rtems-compat.c
new file mode 100644
index ..c5ce8d84
--- /dev/null
+++ b/rtemsbsd/sys/dev/vme/vme-rtems-compat.c
@@ -0,0 +1,143 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) 2023 embedded brains GmbH
+ *
+ * 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.
+ */
+
+/*
+ * This file is a glue layer that allows the TSI148 RTEMS VME driver to use the
+ * libbsd PCI support.
+ */
+
+typedef void FILE;
+
+#define __INSIDE_RTEMS_BSP__
+
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#undef pci_find_device
+
+static device_t dev;
+
+static int
+read_config_byte(unsigned char bus, unsigned char slot, unsigned char func,
+unsigned char reg, uint8_t *val)
+{
+   *val = (uint8_t)pci_read_config(dev, reg, 1);
+   return 0;
+}
+
+static int
+read_config_word(unsigned char bus, unsigned char slot, unsigned char func,
+unsigned char reg, uint16_t *val)
+{
+   *val = (uint16_t)pci_read_config(dev, reg, 2);
+   return 0;
+}
+
+static int
+read_config_dword(unsigned char bus, unsigned char slot, unsigned char func,
+unsigned char reg, uint32_t *val)
+{
+   *val = pci_read_config(dev, reg, 4);
+   return 0;
+}
+
+static int
+write_config_byte(unsigned char bus, unsigned char slot, unsigned 

[PATCH rtems-libbsd 12/14] Add Tsi148 driver template

2024-01-23 Thread Christian Mauderer
From: Sebastian Huber 

---
 buildset/default.ini |   1 +
 buildset/everything.ini  |   3 +
 libbsd.py|  17 
 rtemsbsd/include/bsp/nexus-devices.h |   4 +
 rtemsbsd/sys/dev/vme/tsi148.c| 123 +++
 5 files changed, 148 insertions(+)
 create mode 100644 rtemsbsd/sys/dev/vme/tsi148.c

diff --git a/buildset/default.ini b/buildset/default.ini
index fca70f9c..acb1226d 100644
--- a/buildset/default.ini
+++ b/buildset/default.ini
@@ -65,6 +65,7 @@ rpc = on
 rpc_user = on
 rtems = on
 tests = on
+tsi148 = off
 tty = on
 user_space = on
 user_space_wlanstats = off
diff --git a/buildset/everything.ini b/buildset/everything.ini
index 0eee99e7..b4e57246 100644
--- a/buildset/everything.ini
+++ b/buildset/everything.ini
@@ -17,3 +17,6 @@ usr_sbin_wpa_supplicant = on
 
 # IPSec
 netipsec = on
+
+# VME
+tsi148 = on
diff --git a/libbsd.py b/libbsd.py
index 73df656b..ed40106c 100644
--- a/libbsd.py
+++ b/libbsd.py
@@ -3139,6 +3139,22 @@ class pci(builder.Module):
 mm.generator['source']()
 )
 
+#
+# TSI148
+#
+class tsi148(builder.Module):
+
+def __init__(self, manager):
+super(tsi148, self).__init__(manager, type(self).__name__)
+
+def generate(self):
+mm = self.manager
+self.addRTEMSKernelSourceFiles(
+[
+'sys/dev/vme/tsi148.c',
+],
+mm.generator['source']()
+)
 
 #
 # User space
@@ -5666,6 +5682,7 @@ def load(mm):
 
 # Add PCI
 mm.addModule(pci(mm))
+mm.addModule(tsi148(mm))
 
 # Add NIC devices
 mm.addModule(dev_nic(mm))
diff --git a/rtemsbsd/include/bsp/nexus-devices.h 
b/rtemsbsd/include/bsp/nexus-devices.h
index e764306e..ac4a52a1 100644
--- a/rtemsbsd/include/bsp/nexus-devices.h
+++ b/rtemsbsd/include/bsp/nexus-devices.h
@@ -267,6 +267,10 @@ SYSINIT_DRIVER_REFERENCE(pcib, pci);
 SYSINIT_DRIVER_REFERENCE(rcpcib, pci);
 #endif
 
+#ifdef RTEMS_BSD_MODULE_TSI148
+SYSINIT_DRIVER_REFERENCE(tsi148, pci);
+#endif
+
 #endif /* QORIQ_CHIP_IS_T_VARIANT(QORIQ_CHIP_VARIANT) */
 
 #elif defined(LIBBSP_POWERPC_TQM8XX_BSP_H)
diff --git a/rtemsbsd/sys/dev/vme/tsi148.c b/rtemsbsd/sys/dev/vme/tsi148.c
new file mode 100644
index ..56c746bc
--- /dev/null
+++ b/rtemsbsd/sys/dev/vme/tsi148.c
@@ -0,0 +1,123 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) 2022 embedded brains GmbH (http://www.embedded-brains.de)
+ *
+ * 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 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+struct tsi148 {
+   device_tdev;
+   int mem_rid;
+   struct resource *mem_res;
+   int irq_rid;
+   struct resource *irq_res;
+   void*irq_cookie;
+};
+
+static void
+tsi148_intr(void *arg)
+{
+   struct tsi148 *sc;
+
+   sc = arg;
+}
+
+static int
+tsi148_probe(device_t dev)
+{
+
+   if (pci_get_devid(dev) == 0x014810e3) {
+   device_set_desc(dev, "Tundra Tsi148 PCI-VME bridge");
+   return (BUS_PROBE_GENERIC);
+   }
+
+   return (ENXIO);
+}
+
+static int
+tsi148_attach(device_t dev)
+{
+   struct tsi148 *sc;
+
+   sc = device_get_softc(dev);
+   sc->dev = dev;
+
+   sc->mem_rid = PCIR_BAR(0);
+   sc->mem_res = bus_alloc_resource_any(sc->dev, SYS_RES_MEMORY,
+   &sc->mem_rid, RF_ACTIVE);
+   if (sc->mem_res == NULL) {
+   return (ENOMEM);
+   }
+
+   sc->irq_rid = 0;
+   sc->irq_res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ,
+   &sc->irq_rid, RF_S

[PATCH rtems-libbsd 02/14] mpc85xx: Import from FreeBSD

2024-01-23 Thread Christian Mauderer
From: Sebastian Huber 

---
 freebsd/sys/dev/ofw/ofwpci.c  | 677 +
 freebsd/sys/dev/ofw/ofwpci.h  |  87 ++
 freebsd/sys/dev/pci/pci_subr.c| 388 +++
 freebsd/sys/powerpc/include/machine/hid.h | 224 
 freebsd/sys/powerpc/include/machine/pio.h | 306 ++
 .../sys/powerpc/include/machine/platformvar.h |  91 ++
 freebsd/sys/powerpc/mpc85xx/mpc85xx.c | 361 +++
 freebsd/sys/powerpc/mpc85xx/mpc85xx.h | 177 
 freebsd/sys/powerpc/mpc85xx/pci_mpc85xx.c | 959 ++
 .../sys/powerpc/mpc85xx/pci_mpc85xx_pcib.c| 111 ++
 .../sys/powerpc/mpc85xx/platform_mpc85xx.c| 710 +
 freebsd/sys/powerpc/ofw/ofw_pcib_pci.c| 178 
 12 files changed, 4269 insertions(+)
 create mode 100644 freebsd/sys/dev/ofw/ofwpci.c
 create mode 100644 freebsd/sys/dev/ofw/ofwpci.h
 create mode 100644 freebsd/sys/dev/pci/pci_subr.c
 create mode 100644 freebsd/sys/powerpc/include/machine/hid.h
 create mode 100644 freebsd/sys/powerpc/include/machine/pio.h
 create mode 100644 freebsd/sys/powerpc/include/machine/platformvar.h
 create mode 100644 freebsd/sys/powerpc/mpc85xx/mpc85xx.c
 create mode 100644 freebsd/sys/powerpc/mpc85xx/mpc85xx.h
 create mode 100644 freebsd/sys/powerpc/mpc85xx/pci_mpc85xx.c
 create mode 100644 freebsd/sys/powerpc/mpc85xx/pci_mpc85xx_pcib.c
 create mode 100644 freebsd/sys/powerpc/mpc85xx/platform_mpc85xx.c
 create mode 100644 freebsd/sys/powerpc/ofw/ofw_pcib_pci.c

diff --git a/freebsd/sys/dev/ofw/ofwpci.c b/freebsd/sys/dev/ofw/ofwpci.c
new file mode 100644
index ..d576cb67
--- /dev/null
+++ b/freebsd/sys/dev/ofw/ofwpci.c
@@ -0,0 +1,677 @@
+#include 
+
+/*-
+ * Copyright (c) 2011 Nathan Whitehorn
+ * 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 
+#include 
+#include 
+
+#include 
+#include 
+
+#include 
+
+/*
+ * If it is necessary to set another value of this for
+ * some platforms it should be set at fdt.h file
+ */
+#ifndef PCI_MAP_INTR
+#definePCI_MAP_INTR4
+#endif
+
+#definePCI_INTR_PINS   4
+
+/*
+ * bus interface.
+ */
+static struct resource * ofw_pci_alloc_resource(device_t, device_t,
+int, int *, rman_res_t, rman_res_t, rman_res_t, u_int);
+static int ofw_pci_release_resource(device_t, device_t, int, int,
+struct resource *);
+static int ofw_pci_activate_resource(device_t, device_t, int, int,
+struct resource *);
+static int ofw_pci_deactivate_resource(device_t, device_t, int, int,
+struct resource *);
+static int ofw_pci_adjust_resource(device_t, device_t, int,
+struct resource *, rman_res_t, rman_res_t);
+
+#ifdef __powerpc__
+static bus_space_tag_t ofw_pci_bus_get_bus_tag(device_t, device_t);
+#endif
+
+/*
+ * pcib interface
+ */
+static int ofw_pci_maxslots(device_t);
+
+/*
+ * ofw_bus interface
+ */
+static phandle_t ofw_pci_get_node(device_t, device_t);
+
+/*
+ * local methods
+ */
+static int ofw_pci_fill_ranges(phandle_t, struct ofw_pci_range *);
+static struct rman *ofw_pci_get_rman(struct ofw_pci_softc *, int, u_int);
+
+/*
+ * Driver methods.
+ */
+static device_method_t ofw_pci_methods[] = {
+
+   /* Device interface */
+   DEVMETHOD(device_attach,ofw_pci_attach),
+
+   /* Bus interface */
+   DEVMETHOD(bus_print_child,  bus_generic_print_child),
+   DEVMETHOD(bus_read_ivar,ofw_pci_read_ivar),
+   DEVMETHOD(bus_write_ivar,   ofw_pci_write_ivar),
+   DEVMETHOD(bus_setup_intr,   bus_gen

[PATCH rtems-libbsd 11/14] pci_mpc85xx: Ensure access order for config-regs

2024-01-23 Thread Christian Mauderer
The CFG_ADDR has to be written before reading or writing the CFG_DATA.
---
 freebsd/sys/powerpc/mpc85xx/pci_mpc85xx.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/freebsd/sys/powerpc/mpc85xx/pci_mpc85xx.c 
b/freebsd/sys/powerpc/mpc85xx/pci_mpc85xx.c
index 47879e68..b479eb33 100644
--- a/freebsd/sys/powerpc/mpc85xx/pci_mpc85xx.c
+++ b/freebsd/sys/powerpc/mpc85xx/pci_mpc85xx.c
@@ -80,6 +80,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #ifdef __rtems__
 #include 
+#include 
 #endif /* __rtems__ */
 
 #defineREG_CFG_ADDR0x
@@ -460,6 +461,9 @@ fsl_pcib_cfgread(struct fsl_pcib_softc *sc, u_int bus, 
u_int slot, u_int func,
 
mtx_lock_spin(&sc->sc_cfg_mtx);
bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_CFG_ADDR, addr);
+#ifdef __rtems__
+   ppc_enforce_in_order_execution_of_io();
+#endif
 
switch (bytes) {
case 1:
@@ -498,6 +502,9 @@ fsl_pcib_cfgwrite(struct fsl_pcib_softc *sc, u_int bus, 
u_int slot, u_int func,
 
mtx_lock_spin(&sc->sc_cfg_mtx);
bus_space_write_4(sc->sc_bst, sc->sc_bsh, REG_CFG_ADDR, addr);
+#ifdef __rtems__
+   ppc_enforce_in_order_execution_of_io();
+#endif
 
switch (bytes) {
case 1:
-- 
2.35.3

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


[PATCH rtems-libbsd 10/14] Enable kernel space pci_find_device()

2024-01-23 Thread Christian Mauderer
From: Sebastian Huber 

---
 freebsd/sys/dev/pci/pci.c | 2 --
 rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h | 1 +
 rtemsbsd/rtems/rtems-kernel-pci_bus.c | 1 +
 3 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/freebsd/sys/dev/pci/pci.c b/freebsd/sys/dev/pci/pci.c
index 3789a73e..5c76f1d5 100644
--- a/freebsd/sys/dev/pci/pci.c
+++ b/freebsd/sys/dev/pci/pci.c
@@ -471,7 +471,6 @@ pci_find_dbsf(uint32_t domain, uint8_t bus, uint8_t slot, 
uint8_t func)
return (NULL);
 }
 
-#ifndef __rtems__
 /* Find a device_t by vendor/device ID */
 
 device_t
@@ -488,7 +487,6 @@ pci_find_device(uint16_t vendor, uint16_t device)
 
return (NULL);
 }
-#endif /* __rtems__ */
 
 device_t
 pci_find_class(uint8_t class, uint8_t subclass)
diff --git a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h 
b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
index 94e0d56f..c74eadbc 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-namespace.h
@@ -3847,6 +3847,7 @@
 #definepci_find_cap_method _bsd_pci_find_cap_method
 #definepci_find_class _bsd_pci_find_class
 #definepci_find_dbsf _bsd_pci_find_dbsf
+#definepci_find_device _bsd_pci_find_device
 #definepci_find_extcap_method _bsd_pci_find_extcap_method
 #definepci_find_htcap_method _bsd_pci_find_htcap_method
 #definepci_find_next_cap_method _bsd_pci_find_next_cap_method
diff --git a/rtemsbsd/rtems/rtems-kernel-pci_bus.c 
b/rtemsbsd/rtems/rtems-kernel-pci_bus.c
index 67324dd8..6cbae125 100644
--- a/rtemsbsd/rtems/rtems-kernel-pci_bus.c
+++ b/rtemsbsd/rtems/rtems-kernel-pci_bus.c
@@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
 #include 
 
 #include 
+#undef pci_find_device
 #define pci_find_device rtems_pci_find_device
 #if HAVE_RTEMS_PCI_H
 #include 
-- 
2.35.3

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


[PATCH rtems-libbsd 05/14] Add pic_if.m

2024-01-23 Thread Christian Mauderer
From: Sebastian Huber 

---
 Makefile.todo |  10 ++
 rtemsbsd/include/rtems/bsd/local/pic_if.h | 133 ++
 rtemsbsd/local/pic_if.c   |  69 +++
 3 files changed, 212 insertions(+)
 create mode 100644 rtemsbsd/include/rtems/bsd/local/pic_if.h
 create mode 100644 rtemsbsd/local/pic_if.c

diff --git a/Makefile.todo b/Makefile.todo
index 36951c55..111beb07 100644
--- a/Makefile.todo
+++ b/Makefile.todo
@@ -34,6 +34,8 @@ GENERATED += $(LOCAL_INC)/pci_if.h
 GENERATED += $(LOCAL_SRC)/pci_if.c
 GENERATED += $(LOCAL_INC)/pcib_if.h
 GENERATED += $(LOCAL_SRC)/pcib_if.c
+GENERATED += $(LOCAL_INC)/pic_if.h
+GENERATED += $(LOCAL_SRC)/pic_if.c
 GENERATED += $(LOCAL_INC)/mmcbr_if.h
 GENERATED += $(LOCAL_SRC)/mmcbr_if.c
 GENERATED += $(LOCAL_INC)/mmcbus_if.h
@@ -166,6 +168,14 @@ $(LOCAL_SRC)/pcib_if.c: 
$(FREEBSD_SRC)/sys/dev/pci/pcib_if.m
awk -f $(TOOLS)/makeobjops.awk $< -c
mv pcib_if.c $@
 
+$(LOCAL_INC)/pic_if.h: $(FREEBSD_SRC)/sys/powerpc/powerpc/pic_if.m
+   awk -f $(TOOLS)/makeobjops.awk $< -h
+   mv pic_if.h $@
+
+$(LOCAL_SRC)/pic_if.c: $(FREEBSD_SRC)/sys/powerpc/powerpc/pic_if.m
+   awk -f $(TOOLS)/makeobjops.awk $< -c
+   mv pic_if.c $@
+
 $(LOCAL_INC)/mmcbus_if.h: $(FREEBSD_SRC)/sys/dev/mmc/mmcbus_if.m
awk -f $(TOOLS)/makeobjops.awk $< -h
mv mmcbus_if.h $@
diff --git a/rtemsbsd/include/rtems/bsd/local/pic_if.h 
b/rtemsbsd/include/rtems/bsd/local/pic_if.h
new file mode 100644
index ..a903a25d
--- /dev/null
+++ b/rtemsbsd/include/rtems/bsd/local/pic_if.h
@@ -0,0 +1,133 @@
+/*
+ * This file is produced automatically.
+ * Do not modify anything in here by hand.
+ *
+ * Created from source file
+ *   freebsd-org/sys/powerpc/powerpc/pic_if.m
+ * with
+ *   makeobjops.awk
+ *
+ * See the source file for legal information
+ */
+
+
+#ifndef _pic_if_h_
+#define _pic_if_h_
+
+/** @brief Unique descriptor for the PIC_BIND() method */
+extern struct kobjop_desc pic_bind_desc;
+/** @brief A function implementing the PIC_BIND() method */
+typedef void pic_bind_t(device_t dev, u_int irq, cpuset_t cpumask, void 
**priv);
+
+static __inline void PIC_BIND(device_t dev, u_int irq, cpuset_t cpumask,
+  void **priv)
+{
+   kobjop_t _m;
+   KOBJOPLOOKUP(((kobj_t)dev)->ops,pic_bind);
+   ((pic_bind_t *) _m)(dev, irq, cpumask, priv);
+}
+
+/** @brief Unique descriptor for the PIC_TRANSLATE_CODE() method */
+extern struct kobjop_desc pic_translate_code_desc;
+/** @brief A function implementing the PIC_TRANSLATE_CODE() method */
+typedef void pic_translate_code_t(device_t dev, u_int irq, int code,
+  enum intr_trigger *trig,
+  enum intr_polarity *pol);
+
+static __inline void PIC_TRANSLATE_CODE(device_t dev, u_int irq, int code,
+enum intr_trigger *trig,
+enum intr_polarity *pol)
+{
+   kobjop_t _m;
+   KOBJOPLOOKUP(((kobj_t)dev)->ops,pic_translate_code);
+   ((pic_translate_code_t *) _m)(dev, irq, code, trig, pol);
+}
+
+/** @brief Unique descriptor for the PIC_CONFIG() method */
+extern struct kobjop_desc pic_config_desc;
+/** @brief A function implementing the PIC_CONFIG() method */
+typedef void pic_config_t(device_t dev, u_int irq, enum intr_trigger trig,
+  enum intr_polarity pol);
+
+static __inline void PIC_CONFIG(device_t dev, u_int irq, enum intr_trigger 
trig,
+enum intr_polarity pol)
+{
+   kobjop_t _m;
+   KOBJOPLOOKUP(((kobj_t)dev)->ops,pic_config);
+   ((pic_config_t *) _m)(dev, irq, trig, pol);
+}
+
+/** @brief Unique descriptor for the PIC_DISPATCH() method */
+extern struct kobjop_desc pic_dispatch_desc;
+/** @brief A function implementing the PIC_DISPATCH() method */
+typedef void pic_dispatch_t(device_t dev, struct trapframe *tf);
+
+static __inline void PIC_DISPATCH(device_t dev, struct trapframe *tf)
+{
+   kobjop_t _m;
+   KOBJOPLOOKUP(((kobj_t)dev)->ops,pic_dispatch);
+   ((pic_dispatch_t *) _m)(dev, tf);
+}
+
+/** @brief Unique descriptor for the PIC_ENABLE() method */
+extern struct kobjop_desc pic_enable_desc;
+/** @brief A function implementing the PIC_ENABLE() method */
+typedef void pic_enable_t(device_t dev, u_int irq, u_int vector, void **priv);
+
+static __inline void PIC_ENABLE(device_t dev, u_int irq, u_int vector,
+void **priv)
+{
+   kobjop_t _m;
+   KOBJOPLOOKUP(((kobj_t)dev)->ops,pic_enable);
+   ((pic_enable_t *) _m)(dev, irq, vector, priv);
+}
+
+/** @brief Unique descriptor for the PIC_EOI() method */
+extern struct kobjop_desc pic_eoi_desc;
+/** @brief A function implementing the PIC_EOI() method */
+typedef void pic_eoi_t(device_t dev, u_int irq, void *priv);
+
+static __inline void PIC_EOI(device_t dev, u_int irq, void *priv)
+{
+   kobjop_t _m;
+  

[PATCH rtems-libbsd 06/14] Include missing header file

2024-01-23 Thread Christian Mauderer
From: Sebastian Huber 

---
 rtemsbsd/rtems/rtems-kernel-pci_bus.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/rtemsbsd/rtems/rtems-kernel-pci_bus.c 
b/rtemsbsd/rtems/rtems-kernel-pci_bus.c
index d344e7a3..67324dd8 100644
--- a/rtemsbsd/rtems/rtems-kernel-pci_bus.c
+++ b/rtemsbsd/rtems/rtems-kernel-pci_bus.c
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
-- 
2.35.3

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


[PATCH rtems-libbsd 09/14] pci_mpc85xx.c: Disable reset during initialization

2024-01-23 Thread Christian Mauderer
From: Sebastian Huber 

---
 freebsd/sys/powerpc/mpc85xx/pci_mpc85xx.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/freebsd/sys/powerpc/mpc85xx/pci_mpc85xx.c 
b/freebsd/sys/powerpc/mpc85xx/pci_mpc85xx.c
index beaf96e8..47879e68 100644
--- a/freebsd/sys/powerpc/mpc85xx/pci_mpc85xx.c
+++ b/freebsd/sys/powerpc/mpc85xx/pci_mpc85xx.c
@@ -383,6 +383,7 @@ fsl_pcib_attach(device_t dev)
PCIM_CMD_PORTEN;
fsl_pcib_cfgwrite(sc, 0, 0, 0, PCIR_COMMAND, cfgreg, 2);
 
+#ifndef __rtems__
/* Reset the bus.  Needed for Radeon video cards. */
brctl = fsl_pcib_read_config(sc->sc_dev, 0, 0, 0,
PCIR_BRIDGECTL_1, 1);
@@ -394,6 +395,7 @@ fsl_pcib_attach(device_t dev)
fsl_pcib_write_config(sc->sc_dev, 0, 0, 0,
PCIR_BRIDGECTL_1, brctl, 1);
DELAY(10);
+#endif /* __rtems__ */
 
if (sc->sc_pcie) {
ltssm = fsl_pcib_cfgread(sc, 0, 0, 0, PCIR_LTSSM, 1);
-- 
2.35.3

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


[PATCH rtems-libbsd 07/14] Enable NEW_PCIB

2024-01-23 Thread Christian Mauderer
From: Sebastian Huber 

---
 rtemsbsd/include/machine/resource.h   |  1 +
 .../include/machine/rtems-bsd-kernel-space.h  |  8 +++
 rtemsbsd/rtems/rtems-kernel-nexus.c   | 21 +++
 3 files changed, 30 insertions(+)

diff --git a/rtemsbsd/include/machine/resource.h 
b/rtemsbsd/include/machine/resource.h
index ad4f0f29..babc1ae6 100644
--- a/rtemsbsd/include/machine/resource.h
+++ b/rtemsbsd/include/machine/resource.h
@@ -45,5 +45,6 @@
 #define SYS_RES_MEMORY 3
 #define SYS_RES_IOPORT 4
 #define SYS_RES_GPIO 5
+#define PCI_RES_BUS 6
 
 #endif /* _RTEMS_BSD_MACHINE_RESOURCE_H_ */
diff --git a/rtemsbsd/include/machine/rtems-bsd-kernel-space.h 
b/rtemsbsd/include/machine/rtems-bsd-kernel-space.h
index 09f3c64d..2b45c2db 100644
--- a/rtemsbsd/include/machine/rtems-bsd-kernel-space.h
+++ b/rtemsbsd/include/machine/rtems-bsd-kernel-space.h
@@ -247,6 +247,14 @@ dev_t rtems_bsd__makedev(int _M, int _m);
 struct dirent;
 void dirent_terminate(struct dirent *dp);
 
+/*
+ * Enable the "new" PCI-PCI bridge driver, since this is going to be the future
+ * FreeBSD driver:
+ *
+ * https://reviews.freebsd.org/D32954
+ */
+#defineNEW_PCIB 1
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
diff --git a/rtemsbsd/rtems/rtems-kernel-nexus.c 
b/rtemsbsd/rtems/rtems-kernel-nexus.c
index 8fc879fe..c5ee33d8 100644
--- a/rtemsbsd/rtems/rtems-kernel-nexus.c
+++ b/rtemsbsd/rtems/rtems-kernel-nexus.c
@@ -57,6 +57,7 @@
 #endif
 
 #include 
+#include 
 #include 
 
 #include 
@@ -103,6 +104,10 @@ static struct rman mem_rman;
 
 static struct rman irq_rman;
 
+#ifdef RTEMS_BSD_MODULE_PCI
+static struct rman pci_rman;
+#endif
+
 #if defined(RTEMS_BSP_PCI_IO_REGION_BASE)
 static struct rman port_rman;
 #endif
@@ -137,6 +142,17 @@ nexus_probe(device_t dev)
err = rman_manage_region(&irq_rman, irq_rman.rm_start, irq_rman.rm_end);
BSD_ASSERT(err == 0);
 
+#ifdef RTEMS_BSD_MODULE_PCI
+   pci_rman.rm_start = 0;
+   pci_rman.rm_end = ~0UL;
+   pci_rman.rm_type = RMAN_ARRAY;
+   pci_rman.rm_descr = "PCI bus";
+   err = rman_init(&pci_rman) != 0;
+   BSD_ASSERT(err == 0);
+   err = rman_manage_region(&pci_rman, pci_rman.rm_start, pci_rman.rm_end);
+   BSD_ASSERT(err == 0);
+#endif
+
 #if defined(RTEMS_BSP_PCI_IO_REGION_BASE)
port_rman.rm_start = 0;
port_rman.rm_end = ~0UL;
@@ -191,6 +207,11 @@ nexus_alloc_resource(device_t bus, device_t child, int 
type, int *rid,
case SYS_RES_IRQ:
rm = &irq_rman;
break;
+#ifdef RTEMS_BSD_MODULE_PCI
+   case PCI_RES_BUS:
+   rm = &pci_rman;
+   break;
+#endif
 #if defined(RTEMS_BSP_PCI_IO_REGION_BASE)
case SYS_RES_IOPORT:
rm = &port_rman;
-- 
2.35.3

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


[PATCH rtems-libbsd 03/14] mpc85xx: Port to RTEMS

2024-01-23 Thread Christian Mauderer
From: Sebastian Huber 

---
 freebsd/sys/dev/ofw/ofwpci.c  | 16 
 freebsd/sys/dev/pci/pci.c |  2 +
 freebsd/sys/kern/subr_bus.c   |  2 +-
 freebsd/sys/powerpc/include/machine/spr.h |  3 ++
 freebsd/sys/powerpc/mpc85xx/mpc85xx.c |  4 ++
 freebsd/sys/powerpc/mpc85xx/pci_mpc85xx.c | 32 ++-
 libbsd.py | 25 
 rtemsbsd/include/bsp/nexus-devices.h  |  8 
 rtemsbsd/sys/powerpc/platform_mpc85xx.c   | 48 +++
 9 files changed, 137 insertions(+), 3 deletions(-)
 create mode 100644 rtemsbsd/sys/powerpc/platform_mpc85xx.c

diff --git a/freebsd/sys/dev/ofw/ofwpci.c b/freebsd/sys/dev/ofw/ofwpci.c
index d576cb67..c18de9d2 100644
--- a/freebsd/sys/dev/ofw/ofwpci.c
+++ b/freebsd/sys/dev/ofw/ofwpci.c
@@ -47,7 +47,9 @@ __FBSDID("$FreeBSD$");
 #include 
 
 #include 
+#ifndef __rtems__
 #include 
+#endif /* __rtems__ */
 #include 
 
 #include 
@@ -79,9 +81,11 @@ static int ofw_pci_deactivate_resource(device_t, device_t, 
int, int,
 static int ofw_pci_adjust_resource(device_t, device_t, int,
 struct resource *, rman_res_t, rman_res_t);
 
+#ifndef __rtems__
 #ifdef __powerpc__
 static bus_space_tag_t ofw_pci_bus_get_bus_tag(device_t, device_t);
 #endif
+#endif /* __rtems__ */
 
 /*
  * pcib interface
@@ -118,9 +122,11 @@ static device_method_t ofw_pci_methods[] = {
DEVMETHOD(bus_activate_resource,ofw_pci_activate_resource),
DEVMETHOD(bus_deactivate_resource,  ofw_pci_deactivate_resource),
DEVMETHOD(bus_adjust_resource,  ofw_pci_adjust_resource),
+#ifndef __rtems__
 #ifdef __powerpc__
DEVMETHOD(bus_get_bus_tag,  ofw_pci_bus_get_bus_tag),
 #endif
+#endif /* __rtems__ */
 
/* pcib interface */
DEVMETHOD(pcib_maxslots,ofw_pci_maxslots),
@@ -531,9 +537,13 @@ ofw_pci_activate_resource(device_t bus, device_t child, 
int type, int rid,
printf("ofw_pci mapdev: start %jx, len %jd\n",
(rman_res_t)start, rman_get_size(res));
 
+#ifndef __rtems__
tag = BUS_GET_BUS_TAG(child, child);
if (tag == NULL)
return (ENOMEM);
+#else /* __rtems__ */
+   tag = 0;
+#endif /* __rtems__ */
 
rman_set_bustag(res, tag);
rv = bus_space_map(tag, start,
@@ -547,6 +557,7 @@ ofw_pci_activate_resource(device_t bus, device_t child, int 
type, int rid,
return (rman_activate_resource(res));
 }
 
+#ifndef __rtems__
 #ifdef __powerpc__
 static bus_space_tag_t
 ofw_pci_bus_get_bus_tag(device_t bus, device_t child)
@@ -555,20 +566,25 @@ ofw_pci_bus_get_bus_tag(device_t bus, device_t child)
return (&bs_le_tag);
 }
 #endif
+#endif /* __rtems__ */
 
 static int
 ofw_pci_deactivate_resource(device_t bus, device_t child, int type, int rid,
 struct resource *res)
 {
+#ifndef __rtems__
vm_size_t psize;
+#endif /* __rtems__ */
 
if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY) {
return (bus_generic_deactivate_resource(bus, child, type, rid,
res));
}
 
+#ifndef __rtems__
psize = rman_get_size(res);
pmap_unmapdev((vm_offset_t)rman_get_virtual(res), psize);
+#endif /* __rtems__ */
 
return (rman_deactivate_resource(res));
 }
diff --git a/freebsd/sys/dev/pci/pci.c b/freebsd/sys/dev/pci/pci.c
index f1501208..0cc72dba 100644
--- a/freebsd/sys/dev/pci/pci.c
+++ b/freebsd/sys/dev/pci/pci.c
@@ -3694,6 +3694,7 @@ pci_reserve_secbus(device_t bus, device_t dev, pcicfgregs 
*cfg,
}
break;
 
+#ifndef __rtems__
case 0x00dd10de:
/* Compaq R3000 BIOS sets wrong subordinate bus number. */
if ((cp = kern_getenv("smbios.planar.maker")) == NULL)
@@ -3715,6 +3716,7 @@ pci_reserve_secbus(device_t bus, device_t dev, pcicfgregs 
*cfg,
PCI_WRITE_CONFIG(bus, dev, sub_reg, sub_bus, 1);
}
break;
+#endif /* __rtems__ */
}
 
if (bootverbose)
diff --git a/freebsd/sys/kern/subr_bus.c b/freebsd/sys/kern/subr_bus.c
index e43d0030..c4b8c04d 100644
--- a/freebsd/sys/kern/subr_bus.c
+++ b/freebsd/sys/kern/subr_bus.c
@@ -5588,7 +5588,6 @@ bus_data_generation_update(void)
bus_data_generation++;
 }
 
-#ifndef __rtems__
 int
 bus_free_resource(device_t dev, int type, struct resource *r)
 {
@@ -5597,6 +5596,7 @@ bus_free_resource(device_t dev, int type, struct resource 
*r)
return (bus_release_resource(dev, type, rman_get_rid(r), r));
 }
 
+#ifndef __rtems__
 device_t
 device_lookup_by_name(const char *name)
 {
diff --git a/freebsd/sys/powerpc/include/machine/spr.h 
b/freebsd/sys/powerpc/include/machine/spr.h
index 228e3955..4d108593 100644
--- a/freebsd/sys/powerpc/include/machine/spr.h
+++ b/freebsd/sys/powerpc/include/machine/spr.h
@@ -31,6 +31,9 @@
 #ifndef _POWERPC_SPR_H_
 #define_POWERPC_SPR_H_
 
+#ifdef __rtems__
+#define BOOKE
+#endif /* __rtems

[PATCH rtems-libbsd 08/14] mpc85xx: Support P20XX Local Access Window regs

2024-01-23 Thread Christian Mauderer
From: Sebastian Huber 

---
 freebsd/sys/powerpc/mpc85xx/mpc85xx.c | 38 +++
 freebsd/sys/powerpc/mpc85xx/mpc85xx.h |  2 ++
 2 files changed, 40 insertions(+)

diff --git a/freebsd/sys/powerpc/mpc85xx/mpc85xx.c 
b/freebsd/sys/powerpc/mpc85xx/mpc85xx.c
index ec7eaa3f..7f3df540 100644
--- a/freebsd/sys/powerpc/mpc85xx/mpc85xx.c
+++ b/freebsd/sys/powerpc/mpc85xx/mpc85xx.c
@@ -82,6 +82,29 @@ ccsr_write4(uintptr_t addr, uint32_t val)
powerpc_iomb();
 }
 
+static int
+mpc85xx_is_p20xx(void)
+{
+   uint32_t ver;
+   int is_p20xx;
+
+   ver = SVR_VER(mfspr(SPR_SVR));
+   switch (ver) {
+   case SVR_P2010:
+   case SVR_P2010E:
+   case SVR_P2020:
+   case SVR_P2020E:
+   case SVR_P2041:
+   case SVR_P2041E:
+   is_p20xx = 1;
+   break;
+   default:
+   is_p20xx = 0;
+   }
+
+   return (is_p20xx);
+}
+
 int
 law_getmax(void)
 {
@@ -100,6 +123,14 @@ law_getmax(void)
case SVR_MPC8548E:
law_max = 10;
break;
+   case SVR_P2010:
+   case SVR_P2010E:
+   case SVR_P2020:
+   case SVR_P2020E:
+   case SVR_P2041:
+   case SVR_P2041E:
+   law_max = 12;
+   break;
case SVR_P5020:
case SVR_P5020E:
case SVR_P5021:
@@ -124,6 +155,10 @@ law_write(uint32_t n, uint64_t bar, uint32_t sr)
ccsr_write4(OCP85XX_LAWBARL(n), bar);
ccsr_write4(OCP85XX_LAWSR_QORIQ(n), sr);
ccsr_read4(OCP85XX_LAWSR_QORIQ(n));
+   } else if (mpc85xx_is_p20xx()) {
+   ccsr_write4(OCP85XX_LAWBAR_P20XX(n), bar >> 12);
+   ccsr_write4(OCP85XX_LAWAR(n), sr);
+   ccsr_read4(OCP85XX_LAWAR(n));
} else {
ccsr_write4(OCP85XX_LAWBAR(n), bar >> 12);
ccsr_write4(OCP85XX_LAWSR_85XX(n), sr);
@@ -148,6 +183,9 @@ law_read(uint32_t n, uint64_t *bar, uint32_t *sr)
*bar = (uint64_t)ccsr_read4(OCP85XX_LAWBARH(n)) << 32 |
ccsr_read4(OCP85XX_LAWBARL(n));
*sr = ccsr_read4(OCP85XX_LAWSR_QORIQ(n));
+   } else if (mpc85xx_is_p20xx()) {
+   *bar = (uint64_t)ccsr_read4(OCP85XX_LAWBAR_P20XX(n)) << 12;
+   *sr = ccsr_read4(OCP85XX_LAWAR(n));
} else {
*bar = (uint64_t)ccsr_read4(OCP85XX_LAWBAR(n)) << 12;
*sr = ccsr_read4(OCP85XX_LAWSR_85XX(n));
diff --git a/freebsd/sys/powerpc/mpc85xx/mpc85xx.h 
b/freebsd/sys/powerpc/mpc85xx/mpc85xx.h
index 1a0be6cb..0f1ee5cc 100644
--- a/freebsd/sys/powerpc/mpc85xx/mpc85xx.h
+++ b/freebsd/sys/powerpc/mpc85xx/mpc85xx.h
@@ -79,6 +79,8 @@ extern vm_size_t  ccsrbar_size;
 #defineOCP85XX_LAWSR_85XX(n)   (CCSRBAR_VA + 0xc10 + 0x10 * (n))
 #defineOCP85XX_LAWSR(n)(mpc85xx_is_qoriq() ? 
OCP85XX_LAWSR_QORIQ(n) : \
 OCP85XX_LAWSR_85XX(n))
+#defineOCP85XX_LAWBAR_P20XX(n) (CCSRBAR_VA + 0xc08 + 0x20 * (n))
+#defineOCP85XX_LAWAR(n)(CCSRBAR_VA + 0xc10 + 0x20 * (n))
 
 /* Attribute register */
 #defineOCP85XX_ENA_MASK0x8000
-- 
2.35.3

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


Re: [PATCH rtems6 1/1] libmisc/shell: Fix timeout in getting terminal size

2024-01-23 Thread Peter Dufault


> On Jan 22, 2024, at 1:51 PM, Peter Dufault  wrote:
> 
> 
> 
>> On Jan 22, 2024, at 12:16 PM, Gedare Bloom  wrote:
>> 
>> I have a couple minor notes below. More important, does this change
>> require updating documentation?
> 
> I'd have to look to see if this window size detection is documented, I wanted 
> to fix the problem it caused me.   
> 
>> 
>> I know we have a somewhat aging shell-specific guide:
>> https://docs.rtems.org/branches/master/shell/index.html
>> 
>> 
>> On Fri, Jan 19, 2024 at 5:19 AM  wrote:
>>> 
>>> From: Peter Dufault 
>>> 
>>> - Fix detection of timeout in rtems_shell_term_wait_for().
>>> 
>>> - Switch to using "termios" VTIME inter-character timeout.
>>> The previous implementation is dependent on the BSP clock tick value.
>>> 
>>> Updates #4763
>>> ---
>>> cpukit/libmisc/shell/shell.c | 101 
>>> ++-
>>> 1 file changed, 62 insertions(+), 39 deletions(-)
>>> 
>>> diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
>>> index 9cefc80..60cdb4f 100644
>>> --- a/cpukit/libmisc/shell/shell.c
>>> +++ b/cpukit/libmisc/shell/shell.c
>>> @@ -805,28 +805,52 @@ void rtems_shell_print_env(
>>> }
>>> #endif
>>> 
>>> +/* Debugging output for the terminal I/O associated with window size 
>>> detection
>>> + * can be sent with rtems_shell_winsize_db().
>>> + */
>>> +
>>> +/* Window size detection knobs.
>>> + */
>>> +static bool rtems_shell_winsize_dbf;/* Debug.  "true" to debug. */
>> Is this necessary? How does the application set/test this?
> 
> I don't know.  Same with the "vtime" setting, no way to change that either. 
> Rationale:
> 
> - It puts what you may want to change in one place.
> - I'm not a fan of "#define".
> - I didn't want to add a public interface to tweak things (then I *would* 
> need to document).
> - It was useful. I left it in to make it clear how to compile-time turn it on 
> if you need it.
> 
> I can make the "dbf" behavior pre-processor enabled at compile-time.  Or take 
> it out.

I'm embarrassed to say I didn't see that SHELL_WINSIZE_DEBUG is already in the 
code.  I will switch to use that.
I don't like losing the format checking when a flag is undefined.  I can avoid 
that by unconditionally adding .  There is already SHELL_DEBUG 
conditional code using "printk()" without including .

#define SHELL_STD_DEBUG 1  /* Or 0. */
#define SHELL_WINSIZE_DEBUG 1  /* Or 0. */

#if SHELL_STD_DEBUG | SHELL_WINSIZE_DEBUG
#include 
#define shell_std_debug_(...) \
  do { printk("shell[%08x]: ", rtems_task_self()); printk(__VA_ARGS__); } while 
(0)
#endif

#if SHELL_STD_DEBUG
#define shell_std_debug(...) do { shell_std_debug_(__VA_ARGS__); } while (0)
#else
#define shell_std_debug(...)
#endif

#if SHELL_WINSIZE_DEBUG
#define shell_winsize_debug(...) do { shell_std_debug_(__VA_ARGS__); } while (0)
#else
#define shell_winsize_debug(...)
#endif

- OR: Polluted (with rtems/bspIo.h) implementation:

#define SHELL_STD_DEBUG 1  /* Or 0. */
#define SHELL_WINSIZE_DEBUG 1  /* Or 0. */

#include 
#define shell_std_debug_(ENABLE, ...) \
  do { if (ENABLE) printk("shell[%08x]: ", rtems_task_self()); 
printk(__VA_ARGS__); } while (0)

#define shell_std_debug(...) shell_std_debug_(SHELL_STD_DEBUG, __VA_ARGS__)
#define shell_winsize_debug(...) shell_std_debug_(SHELL_WINSIZE_DEBUG, 
__VA_ARGS__)

> 
> I would leave the "vtime" static, there was no way to change the previous 
> timeout either.
> 
>> 
>>> +static int rtems_shell_winsize_vtime = 1;  /* VTIME timeout in .1 seconds 
>>> */
>>> +
>>> +static void rtems_shell_winsize_vdb(const char *format, va_list ap) {
>>> +  if (rtems_shell_winsize_dbf == false)
>>> +return;
>>> +  printf("shell_winsize: ");
>>> +  vprintf(format, ap);
>>> +  fflush(stdout);
>>> +}
>>> +
>>> +static void rtems_shell_winsize_db(const char *format, ...) {
>>> +  va_list ap;
>>> +  va_start(ap, format);
>>> +  rtems_shell_winsize_vdb(format, ap);
>>> +  va_end(ap);
>>> +}
>>> +
>>> /*
>>> * Wait for the string to return or timeout.
>>> */
>>> -static bool rtems_shell_term_wait_for(const int fd, const char* str, const 
>>> int timeout)
>>> +static bool rtems_shell_term_wait_for(const int fd, const char* str)
>>> {
>>> -  int msec = timeout;
>>>  int i = 0;
>>> -  while (msec-- > 0 && str[i] != '\0') {
>>> +  while (str[i] != '\0') {
>>>char ch[2];
>>> -if (read(fd, &ch[0], 1) == 1) {
>>> -  fflush(stdout);
>>> +ssize_t n;
>>> +if ((n = read(fd, &ch[0], 1)) == 1) {
>>>  if (ch[0] != str[i++]) {
>>> +rtems_shell_winsize_db("Wrong char at char %d.\n", i);
>>>return false;
>>>  }
>>> -  msec = timeout;
>>>} else {
>>> -  usleep(1000);
>>> +  rtems_shell_winsize_db("%s reading char %d.\n",
>>> +   (n == 0) ? "Timeout" : "Error", i);
>> I'd suggest putting the 'i' on it's own line here.  I don't know that
>> there's a specific style guide for this file, but having trailing
>> statements after the ternary is a bit harder to read. imo

[PATCH rtems-libbsd master 0/3] Cleanup patch series

2024-01-23 Thread Kinsey Moore
This patch set cleans up several issues found by Coverity on the master
branch.


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


[PATCH rtems-libbsd master 1/3] rtemsbsd/rc-conf: Avoid use after free

2024-01-23 Thread Kinsey Moore
---
 rtemsbsd/rtems/rtems-bsd-rc-conf.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/rtemsbsd/rtems/rtems-bsd-rc-conf.c 
b/rtemsbsd/rtems/rtems-bsd-rc-conf.c
index f4cc987b..d34aafd9 100644
--- a/rtemsbsd/rtems/rtems-bsd-rc-conf.c
+++ b/rtemsbsd/rtems/rtems-bsd-rc-conf.c
@@ -714,6 +714,7 @@ rc_conf_worker(rtems_task_argument task_argument)
   rtems_chain_node*  node = rtems_chain_first(&services);
   intr = 0;
   interror;
+  bool   rc_conf_verbose;
 
   /*
* Check for a syslog priority before any services are run.
@@ -748,6 +749,8 @@ rc_conf_worker(rtems_task_argument task_argument)
   if (r < 0)
 rc_conf->error_code = error;
 
+  rc_conf_verbose = rc_conf->verbose;
+
   /*
* If there is a waiter signal else clean up because the waiter has gone.
*/
@@ -760,7 +763,7 @@ rc_conf_worker(rtems_task_argument task_argument)
 rc_conf_destroy(rc_conf);
   }
 
-  if (rc_conf->verbose)
+  if (rc_conf_verbose)
 printf("rc.conf: finished\n");
 
   rtems_task_exit();
-- 
2.39.2

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


[PATCH rtems-libbsd master 2/3] rtemsbsd/rtems: Check function return values

2024-01-23 Thread Kinsey Moore
---
 rtemsbsd/rtems/rtems-bsd-rc-conf-net.c | 10 ++
 rtemsbsd/rtems/rtems-kernel-init.c |  4 +++-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c 
b/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c
index 23ee15db..8ffaa914 100644
--- a/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c
+++ b/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c
@@ -103,7 +103,9 @@ cloned_interfaces(rtems_bsd_rc_conf* rc_conf, 
rtems_bsd_rc_conf_argc_argv* aa)
   "ifconfig", aa->argv[arg], "create", NULL
 };
 rtems_bsd_rc_conf_print_cmd(rc_conf, "cloning_interfaces", 3, 
ifconfg_args);
-rtems_bsd_command_ifconfig(3, (char**) ifconfg_args);
+if (rtems_bsd_command_ifconfig(3, (char**) ifconfg_args)) {
+  return -1;
+}
   }
 
   return 0;
@@ -377,7 +379,7 @@ defaultrouter(rtems_bsd_rc_conf* rc_conf, 
rtems_bsd_rc_conf_argc_argv* aa, bool
   memset(&sin, 0, sizeof(sin));
   memset(&rti_info[0], 0, sizeof(rti_info));
   sin.sin_family = AF_INET;
-  inet_pton(AF_INET, "0.0.0.0", &sin.sin_addr);
+  (void) inet_pton(AF_INET, "0.0.0.0", &sin.sin_addr);
 
   r = rtems_get_route(&sin, rti_info);
   if (r == 0 && rti_info[RTAX_GATEWAY] != NULL) {
@@ -710,9 +712,9 @@ run_dhcp(rtems_bsd_rc_conf* rc_conf, 
rtems_bsd_rc_conf_argc_argv* aa)
   }
   dd->config.priority = priority;
 
-  rtems_bsd_rc_conf_find(rc_conf, "dhcpcd_options", dd->argc_argv);
+  r = rtems_bsd_rc_conf_find(rc_conf, "dhcpcd_options", dd->argc_argv);
 
-  if (dd->argc_argv->argc > 0) {
+  if (r == 0 && dd->argc_argv->argc > 0) {
 dd->config.argc = dd->argc_argv->argc;
 dd->config.argv = dd->argc_argv->argv;
   }
diff --git a/rtemsbsd/rtems/rtems-kernel-init.c 
b/rtemsbsd/rtems/rtems-kernel-init.c
index 7112914e..b0779277 100644
--- a/rtemsbsd/rtems/rtems-kernel-init.c
+++ b/rtemsbsd/rtems/rtems-kernel-init.c
@@ -135,7 +135,9 @@ rtems_bsd_initialize(void)
sbt_tickthreshold = bttosbt(bt_tickthreshold);
maxid_maxcpus = (int) rtems_scheduler_get_processor_maximum();
 
-   mkdir("/etc", S_IRWXU | S_IRWXG | S_IRWXO);
+   if (mkdir("/etc", S_IRWXU | S_IRWXG | S_IRWXO) != 0) {
+   return RTEMS_UNSATISFIED;
+   }
 
sc =  rtems_timer_initiate_server(
rtems_bsd_get_task_priority(name),
-- 
2.39.2

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


[PATCH rtems-libbsd master 3/3] rtemsbsd/rtems: Don't leak memory on error

2024-01-23 Thread Kinsey Moore
---
 rtemsbsd/rtems/rtems-bsd-rc-conf.c | 14 ++
 rtemsbsd/rtems/rtems-routes.c  |  4 +++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/rtemsbsd/rtems/rtems-bsd-rc-conf.c 
b/rtemsbsd/rtems/rtems-bsd-rc-conf.c
index d34aafd9..88d98c3e 100644
--- a/rtemsbsd/rtems/rtems-bsd-rc-conf.c
+++ b/rtemsbsd/rtems/rtems-bsd-rc-conf.c
@@ -260,12 +260,14 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
*/
   length = strnlen(text, RTEMS_BSD_RC_CONF_MAX_SIZE);
   if (length == RTEMS_BSD_RC_CONF_MAX_SIZE) {
+free(_rc_conf);
 errno = E2BIG;
 return -1;
   }
 
   copy = strdup(text);
   if (copy == NULL) {
+free(_rc_conf);
 errno = ENOMEM;
 return -1;
   }
@@ -286,6 +288,7 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
   lines = malloc(sizeof(char*) * line_count);
   if (lines == NULL) {
 free(copy);
+free(_rc_conf);
 errno = ENOMEM;
 return -1;
   }
@@ -335,6 +338,13 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
   if (timeout >= 0)
 _rc_conf->waiter = rtems_task_self();
 
+  if (_rc_conf->name == NULL) {
+free((void*) _rc_conf->lines);
+free((void*) _rc_conf->data);
+free(_rc_conf);
+return -1;
+  }
+
   /*
* Create the lock.
*/
@@ -343,6 +353,7 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
 free((void*) _rc_conf->name);
 free((void*) _rc_conf->lines);
 free((void*) _rc_conf->data);
+free(_rc_conf);
 return -1;
   }
 
@@ -796,6 +807,7 @@ rtems_bsd_run_rc_conf_script(const char* name,
   if (sc != RTEMS_SUCCESSFUL) {
 fprintf(stderr, "error: %s: get priority: %s\n",
 name, rtems_status_text(sc));
+rc_conf_destroy(rc_conf);
 errno = EIO;
 return -1;
   }
@@ -808,6 +820,7 @@ rtems_bsd_run_rc_conf_script(const char* name,
  &worker);
   if (sc != RTEMS_SUCCESSFUL) {
 fprintf (stderr, "error: worker create: %s", rtems_status_text(sc));
+rc_conf_destroy(rc_conf);
 errno = EIO;
 return -1;
   }
@@ -817,6 +830,7 @@ rtems_bsd_run_rc_conf_script(const char* name,
 (rtems_task_argument) rc_conf);
   if (sc != RTEMS_SUCCESSFUL) {
 fprintf (stderr, "error: worker start: %s", rtems_status_text(sc));
+rc_conf_destroy(rc_conf);
 errno = EIO;
 return - 1;
   }
diff --git a/rtemsbsd/rtems/rtems-routes.c b/rtemsbsd/rtems/rtems-routes.c
index 6663e8d4..0b5250f0 100644
--- a/rtemsbsd/rtems/rtems-routes.c
+++ b/rtemsbsd/rtems/rtems-routes.c
@@ -85,8 +85,10 @@ int rtems_get_route(const struct sockaddr_in* sin, struct 
sockaddr** rti_info)
   }
 
   s = socket(AF_ROUTE, SOCK_RAW, AF_UNSPEC);
-  if (s < 0)
+  if (s < 0) {
+free(buf);
 return -1;
+  }
 
   rtm = (struct rt_msghdr *) buf;
   rtm->rtm_msglen = sizeof(struct rt_msghdr) + sizeof(struct sockaddr_in);
-- 
2.39.2

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


[PATCH rtems-libbsd 6-freebsd-12 5/5] rtemsbsd: Remove unused variable

2024-01-23 Thread Kinsey Moore
---
 rtemsbsd/rtems/rtems-kernel-lockmgr.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/rtemsbsd/rtems/rtems-kernel-lockmgr.c 
b/rtemsbsd/rtems/rtems-kernel-lockmgr.c
index 518f6831..de5d9d8a 100644
--- a/rtemsbsd/rtems/rtems-kernel-lockmgr.c
+++ b/rtemsbsd/rtems/rtems-kernel-lockmgr.c
@@ -207,13 +207,11 @@ lockmgr_lock_fast_path(struct lock *lk, u_int flags, 
struct lock_object *ilk,
 {
uintptr_t x, tid;
u_int op;
-   bool locked;
 
if (__predict_false(panicstr != NULL))
return (0);
 
op = flags & LK_TYPE_MASK;
-   locked = false;
switch (op) {
case LK_SHARED:
if (!__predict_false(lk->lock_object.lo_flags & LK_NOSHARE))
-- 
2.39.2

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


[PATCH rtems-libbsd 6-freebsd-12 0/5] Cleanup patch set

2024-01-23 Thread Kinsey Moore
This is the 6-freebsd-12 version of the cleanup patch set. Coverity was
actually run against 6-freebsd-12, so this patch set is slightly larger
than the master patch set.


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


[PATCH rtems-libbsd 6-freebsd-12 4/5] rtemsbsd/arasan_sdhci: Move variable init to start

2024-01-23 Thread Kinsey Moore
This moves the ZynqMP-specific variable initialization to the start of
the function to avoid Coverity warnings.
---
 rtemsbsd/sys/dev/sdhci/arasan_sdhci.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/rtemsbsd/sys/dev/sdhci/arasan_sdhci.c 
b/rtemsbsd/sys/dev/sdhci/arasan_sdhci.c
index 722e609d..017f4acb 100644
--- a/rtemsbsd/sys/dev/sdhci/arasan_sdhci.c
+++ b/rtemsbsd/sys/dev/sdhci/arasan_sdhci.c
@@ -247,6 +247,12 @@ arasan_sdhci_attach(device_t dev)
 {
struct arasan_sdhci_softc *sc = device_get_softc(dev);
int rid, err;
+#if defined(LIBBSP_AARCH64_XILINX_ZYNQMP_BSP_H)
+   volatile uint32_t *RST_LPD_IOU2_ptr = (uint32_t*)0xFF5E0238;
+   uint32_t RST_LPD_IOU2 = *RST_LPD_IOU2_ptr;
+   uint32_t SDIO0_disabled = RST_LPD_IOU2 & (1 << 5);
+   uint32_t SDIO1_disabled = RST_LPD_IOU2 & (1 << 6);
+#endif
 
sc->dev = dev;
 
@@ -265,10 +271,6 @@ arasan_sdhci_attach(device_t dev)
 * Detect this situation and avoid probing the device in this situation.
 */
 #if defined(LIBBSP_AARCH64_XILINX_ZYNQMP_BSP_H)
-   volatile uint32_t *RST_LPD_IOU2_ptr = (uint32_t*)0xFF5E0238;
-   uint32_t RST_LPD_IOU2 = *RST_LPD_IOU2_ptr;
-   uint32_t SDIO0_disabled = RST_LPD_IOU2 & (1 << 5);
-   uint32_t SDIO1_disabled = RST_LPD_IOU2 & (1 << 6);
if ( sc->mem_res == 0xFF16 ) {
if ( SDIO0_disabled != 0 ) {
device_printf(dev, "SDIO0 disabled\n");
-- 
2.39.2

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


[PATCH rtems-libbsd 6-freebsd-12 2/5] rtemsbsd/rtems: Check function return values

2024-01-23 Thread Kinsey Moore
---
 rtemsbsd/rtems/rtems-bsd-rc-conf-net.c | 10 ++
 rtemsbsd/rtems/rtems-bsd-syscall-api.c |  9 ++---
 rtemsbsd/rtems/rtems-kernel-init.c |  4 +++-
 rtemsbsd/rtems/rtems-kernel-pager.c|  4 +++-
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c 
b/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c
index 23ee15db..8ffaa914 100644
--- a/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c
+++ b/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c
@@ -103,7 +103,9 @@ cloned_interfaces(rtems_bsd_rc_conf* rc_conf, 
rtems_bsd_rc_conf_argc_argv* aa)
   "ifconfig", aa->argv[arg], "create", NULL
 };
 rtems_bsd_rc_conf_print_cmd(rc_conf, "cloning_interfaces", 3, 
ifconfg_args);
-rtems_bsd_command_ifconfig(3, (char**) ifconfg_args);
+if (rtems_bsd_command_ifconfig(3, (char**) ifconfg_args)) {
+  return -1;
+}
   }
 
   return 0;
@@ -377,7 +379,7 @@ defaultrouter(rtems_bsd_rc_conf* rc_conf, 
rtems_bsd_rc_conf_argc_argv* aa, bool
   memset(&sin, 0, sizeof(sin));
   memset(&rti_info[0], 0, sizeof(rti_info));
   sin.sin_family = AF_INET;
-  inet_pton(AF_INET, "0.0.0.0", &sin.sin_addr);
+  (void) inet_pton(AF_INET, "0.0.0.0", &sin.sin_addr);
 
   r = rtems_get_route(&sin, rti_info);
   if (r == 0 && rti_info[RTAX_GATEWAY] != NULL) {
@@ -710,9 +712,9 @@ run_dhcp(rtems_bsd_rc_conf* rc_conf, 
rtems_bsd_rc_conf_argc_argv* aa)
   }
   dd->config.priority = priority;
 
-  rtems_bsd_rc_conf_find(rc_conf, "dhcpcd_options", dd->argc_argv);
+  r = rtems_bsd_rc_conf_find(rc_conf, "dhcpcd_options", dd->argc_argv);
 
-  if (dd->argc_argv->argc > 0) {
+  if (r == 0 && dd->argc_argv->argc > 0) {
 dd->config.argc = dd->argc_argv->argc;
 dd->config.argv = dd->argc_argv->argv;
   }
diff --git a/rtemsbsd/rtems/rtems-bsd-syscall-api.c 
b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
index 800aa323..bec03c57 100644
--- a/rtemsbsd/rtems/rtems-bsd-syscall-api.c
+++ b/rtemsbsd/rtems/rtems-bsd-syscall-api.c
@@ -1322,9 +1322,12 @@ rtems_bsd_sysgen_vnstat(
if (vp == NULL)
error = EFAULT;
else {
-   VOP_LOCK(vp, LK_SHARED);
-   error = vn_stat(vp, buf, td->td_ucred, NOCRED, td);
-   VOP_UNLOCK(vp, 0);
+   if (VOP_LOCK(vp, LK_SHARED) == 0) {
+   error = vn_stat(vp, buf, td->td_ucred, NOCRED, td);
+   VOP_UNLOCK(vp, 0);
+   } else {
+   error = ENOLCK;
+   }
}
if (RTEMS_BSD_SYSCALL_TRACE) {
printf("bsd: sys: vnstat: exit %p\n", vp);
diff --git a/rtemsbsd/rtems/rtems-kernel-init.c 
b/rtemsbsd/rtems/rtems-kernel-init.c
index 90a9c809..8ac2f59e 100644
--- a/rtemsbsd/rtems/rtems-kernel-init.c
+++ b/rtemsbsd/rtems/rtems-kernel-init.c
@@ -223,7 +223,9 @@ rtems_bsd_initialize(void)
return RTEMS_UNSATISFIED;
}
 
-   mkdir("/etc", S_IRWXU | S_IRWXG | S_IRWXO);
+   if (mkdir("/etc", S_IRWXU | S_IRWXG | S_IRWXO) != 0) {
+   return RTEMS_UNSATISFIED;
+   }
 
sc = rtems_timer_initiate_server(rtems_bsd_get_task_priority(name),
rtems_bsd_get_task_stack_size(name), RTEMS_DEFAULT_ATTRIBUTES);
diff --git a/rtemsbsd/rtems/rtems-kernel-pager.c 
b/rtemsbsd/rtems/rtems-kernel-pager.c
index 5a48c2e8..d8febb03 100644
--- a/rtemsbsd/rtems/rtems-kernel-pager.c
+++ b/rtemsbsd/rtems/rtems-kernel-pager.c
@@ -85,7 +85,9 @@ pbuf_ctor(void *mem, int size, void *arg, int flags)
bp->b_ioflags = 0;
bp->b_iodone = NULL;
bp->b_error = 0;
-   BUF_LOCK(bp, LK_EXCLUSIVE, NULL);
+   if (BUF_LOCK(bp, LK_EXCLUSIVE, NULL) != 0) {
+   return -1;
+   }
 
return (0);
 }
-- 
2.39.2

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


[PATCH rtems-libbsd 6-freebsd-12 1/5] rtemsbsd/rc-conf: Avoid use after free

2024-01-23 Thread Kinsey Moore
---
 rtemsbsd/rtems/rtems-bsd-rc-conf.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/rtemsbsd/rtems/rtems-bsd-rc-conf.c 
b/rtemsbsd/rtems/rtems-bsd-rc-conf.c
index f4cc987b..d34aafd9 100644
--- a/rtemsbsd/rtems/rtems-bsd-rc-conf.c
+++ b/rtemsbsd/rtems/rtems-bsd-rc-conf.c
@@ -714,6 +714,7 @@ rc_conf_worker(rtems_task_argument task_argument)
   rtems_chain_node*  node = rtems_chain_first(&services);
   intr = 0;
   interror;
+  bool   rc_conf_verbose;
 
   /*
* Check for a syslog priority before any services are run.
@@ -748,6 +749,8 @@ rc_conf_worker(rtems_task_argument task_argument)
   if (r < 0)
 rc_conf->error_code = error;
 
+  rc_conf_verbose = rc_conf->verbose;
+
   /*
* If there is a waiter signal else clean up because the waiter has gone.
*/
@@ -760,7 +763,7 @@ rc_conf_worker(rtems_task_argument task_argument)
 rc_conf_destroy(rc_conf);
   }
 
-  if (rc_conf->verbose)
+  if (rc_conf_verbose)
 printf("rc.conf: finished\n");
 
   rtems_task_exit();
-- 
2.39.2

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


[PATCH rtems-libbsd 6-freebsd-12 3/5] rtemsbsd/rtems: Don't leak memory on error

2024-01-23 Thread Kinsey Moore
---
 rtemsbsd/rtems/rtems-bsd-mountroot.c |  4 ++--
 rtemsbsd/rtems/rtems-bsd-rc-conf.c   | 14 ++
 rtemsbsd/rtems/rtems-routes.c|  4 +++-
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/rtemsbsd/rtems/rtems-bsd-mountroot.c 
b/rtemsbsd/rtems/rtems-bsd-mountroot.c
index 132a08ff..d913e12f 100644
--- a/rtemsbsd/rtems/rtems-bsd-mountroot.c
+++ b/rtemsbsd/rtems/rtems-bsd-mountroot.c
@@ -94,8 +94,6 @@ bsd_mountroot(const char *fstype)
if (vfsp != NULL) {
mp = vfs_mount_alloc(NULLVP, vfsp, "/", cred);
 
-   crfree(cred);
-
error = VFS_MOUNT(mp);
if (error != 0)
panic("Cannot mount root file system: %d", error);
@@ -114,6 +112,8 @@ bsd_mountroot(const char *fstype)
 
set_rootvnode(mp);
}
+
+   crfree(cred);
 }
 
 static void
diff --git a/rtemsbsd/rtems/rtems-bsd-rc-conf.c 
b/rtemsbsd/rtems/rtems-bsd-rc-conf.c
index d34aafd9..88d98c3e 100644
--- a/rtemsbsd/rtems/rtems-bsd-rc-conf.c
+++ b/rtemsbsd/rtems/rtems-bsd-rc-conf.c
@@ -260,12 +260,14 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
*/
   length = strnlen(text, RTEMS_BSD_RC_CONF_MAX_SIZE);
   if (length == RTEMS_BSD_RC_CONF_MAX_SIZE) {
+free(_rc_conf);
 errno = E2BIG;
 return -1;
   }
 
   copy = strdup(text);
   if (copy == NULL) {
+free(_rc_conf);
 errno = ENOMEM;
 return -1;
   }
@@ -286,6 +288,7 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
   lines = malloc(sizeof(char*) * line_count);
   if (lines == NULL) {
 free(copy);
+free(_rc_conf);
 errno = ENOMEM;
 return -1;
   }
@@ -335,6 +338,13 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
   if (timeout >= 0)
 _rc_conf->waiter = rtems_task_self();
 
+  if (_rc_conf->name == NULL) {
+free((void*) _rc_conf->lines);
+free((void*) _rc_conf->data);
+free(_rc_conf);
+return -1;
+  }
+
   /*
* Create the lock.
*/
@@ -343,6 +353,7 @@ rc_conf_create(rtems_bsd_rc_conf** rc_conf,
 free((void*) _rc_conf->name);
 free((void*) _rc_conf->lines);
 free((void*) _rc_conf->data);
+free(_rc_conf);
 return -1;
   }
 
@@ -796,6 +807,7 @@ rtems_bsd_run_rc_conf_script(const char* name,
   if (sc != RTEMS_SUCCESSFUL) {
 fprintf(stderr, "error: %s: get priority: %s\n",
 name, rtems_status_text(sc));
+rc_conf_destroy(rc_conf);
 errno = EIO;
 return -1;
   }
@@ -808,6 +820,7 @@ rtems_bsd_run_rc_conf_script(const char* name,
  &worker);
   if (sc != RTEMS_SUCCESSFUL) {
 fprintf (stderr, "error: worker create: %s", rtems_status_text(sc));
+rc_conf_destroy(rc_conf);
 errno = EIO;
 return -1;
   }
@@ -817,6 +830,7 @@ rtems_bsd_run_rc_conf_script(const char* name,
 (rtems_task_argument) rc_conf);
   if (sc != RTEMS_SUCCESSFUL) {
 fprintf (stderr, "error: worker start: %s", rtems_status_text(sc));
+rc_conf_destroy(rc_conf);
 errno = EIO;
 return - 1;
   }
diff --git a/rtemsbsd/rtems/rtems-routes.c b/rtemsbsd/rtems/rtems-routes.c
index 6663e8d4..0b5250f0 100644
--- a/rtemsbsd/rtems/rtems-routes.c
+++ b/rtemsbsd/rtems/rtems-routes.c
@@ -85,8 +85,10 @@ int rtems_get_route(const struct sockaddr_in* sin, struct 
sockaddr** rti_info)
   }
 
   s = socket(AF_ROUTE, SOCK_RAW, AF_UNSPEC);
-  if (s < 0)
+  if (s < 0) {
+free(buf);
 return -1;
+  }
 
   rtm = (struct rt_msghdr *) buf;
   rtm->rtm_msglen = sizeof(struct rt_msghdr) + sizeof(struct sockaddr_in);
-- 
2.39.2

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


Re: [RTEMS Tools 0/1] trace/wscript: Improve C++ standard selection

2024-01-23 Thread Chris Johns
On 23/1/2024 5:55 pm, Sebastian Huber wrote:
> - Am 22. Jan 2024 um 22:56 schrieb Chris Johns chr...@rtems.org:
> 
>> On 22/1/2024 6:18 pm, Sebastian Huber wrote:
>>> On 22.01.24 00:47, Chris Johns wrote:
 On 22/1/2024 3:42 am, Sebastian Huber wrote:
> Does XCode ship a Symbolize.h and llvm-config?

 No ...

 % uname -a
 Darwin weka.contemporary.net.au 23.2.0 Darwin Kernel Version 23.2.0: Wed 
 Nov 15
 21:55:06 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6020 arm64
 % c++ -v
 Apple clang version 15.0.0 (clang-1500.1.0.2.5)
 Target: arm64-apple-darwin23.2.0
 Thread model: posix
 InstalledDir:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 % type llvm-config
 llvm-config not found
 % find
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
 -name Symbolize.h
 %
>>>
>>> Ok, thanks for checking. It seems that using the LLVM from brew is then the
>>> right approach.
>>
>> I have stated for years now we will not depend on brew or macports for 
>> building
>> RTEMS tools. Those distro packagers are rolling releases. Also what about
>> MacPorts?
>>
>> FYI when I first moved to Macs and I starting building native tools with
>> macports then brew and gave up. At the time our tool versions exposed issues 
>> in
>> their tools and updates broke working things and exposed new issues till the
>> point I found myself attempting to fix issue is those distros. Xcode tools 
>> just
>> worked and have done so for 20+ years.
> 
> What I meant with right approach is that using the brew provided LLVM for a 
> Github job is the right approach to test to RTEMS Tools build with LLVM. You 
> can of course build the RTEMS Tools with XCode only.

Thanks for explaining this. Sorry, I had misunderstood the comment.

> 
>>
>>>
>>> Can I check in the patch now?
>>>
>>
>> If the changes does not build for me without brew or macports then I am a no.
> 
> The usage of LLVM for the RTEMS Tools is optional. You can build them without 
> LLVM. However, this patch is relevant to a host which has LLVM installed. So, 
> to test this patch you need an LLVM installation.

Great and thanks. The change is fine to push however I like to understand some
things ...

Does this mean that tool does not work on some operating systems?

Does the user get any indication?

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


Re: [PATCH rtems6 1/1] libmisc/shell: Fix timeout in getting terminal size

2024-01-23 Thread Chris Johns
On 23/1/2024 9:00 pm, Peter Dufault wrote:
>> On Jan 22, 2024, at 1:51 PM, Peter Dufault  wrote:
>>> On Jan 22, 2024, at 12:16 PM, Gedare Bloom  wrote:
>>>
>>> I have a couple minor notes below. More important, does this change
>>> require updating documentation?
>>
>> I'd have to look to see if this window size detection is documented, I 
>> wanted to fix the problem it caused me.   
>>
>>>
>>> I know we have a somewhat aging shell-specific guide:
>>> https://docs.rtems.org/branches/master/shell/index.html
>>>

The original change is by me so I can take a look at this. Thanks for mentioning
this. :)

>>>
>>> On Fri, Jan 19, 2024 at 5:19 AM  wrote:

 From: Peter Dufault 

 - Fix detection of timeout in rtems_shell_term_wait_for().

 - Switch to using "termios" VTIME inter-character timeout.
 The previous implementation is dependent on the BSP clock tick value.

 Updates #4763
 ---
 cpukit/libmisc/shell/shell.c | 101 
 ++-
 1 file changed, 62 insertions(+), 39 deletions(-)

 diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
 index 9cefc80..60cdb4f 100644
 --- a/cpukit/libmisc/shell/shell.c
 +++ b/cpukit/libmisc/shell/shell.c
 @@ -805,28 +805,52 @@ void rtems_shell_print_env(
 }
 #endif

 +/* Debugging output for the terminal I/O associated with window size 
 detection
 + * can be sent with rtems_shell_winsize_db().
 + */
 +
 +/* Window size detection knobs.
 + */
 +static bool rtems_shell_winsize_dbf;/* Debug.  "true" to debug. */
>>> Is this necessary? How does the application set/test this?
>>
>> I don't know.  Same with the "vtime" setting, no way to change that either. 
>> Rationale:
>>
>> - It puts what you may want to change in one place.
>> - I'm not a fan of "#define".
>> - I didn't want to add a public interface to tweak things (then I *would* 
>> need to document).
>> - It was useful. I left it in to make it clear how to compile-time turn it 
>> on if you need it.
>>
>> I can make the "dbf" behavior pre-processor enabled at compile-time.  Or 
>> take it out.
> 
> I'm embarrassed to say I didn't see that SHELL_WINSIZE_DEBUG is already in 
> the code.  I will switch to use that.
> I don't like losing the format checking when a flag is undefined.  I can 
> avoid that by unconditionally adding .  There is already 
> SHELL_DEBUG conditional code using "printk()" without including 
> .

Thanks for look into this and cleaning up the cruft. It couuld be BPS specific
and why it the include is an issue for some and not others.

> 
> #define SHELL_STD_DEBUG 1  /* Or 0. */
> #define SHELL_WINSIZE_DEBUG 1  /* Or 0. */
> 
> #if SHELL_STD_DEBUG | SHELL_WINSIZE_DEBUG
> #include 
> #define shell_std_debug_(...) \
>   do { printk("shell[%08x]: ", rtems_task_self()); printk(__VA_ARGS__); } 
> while (0)
> #endif
> 
> #if SHELL_STD_DEBUG
> #define shell_std_debug(...) do { shell_std_debug_(__VA_ARGS__); } while (0)
> #else
> #define shell_std_debug(...)
> #endif
> 
> #if SHELL_WINSIZE_DEBUG
> #define shell_winsize_debug(...) do { shell_std_debug_(__VA_ARGS__); } while 
> (0)
> #else
> #define shell_winsize_debug(...)
> #endif

Compiling out the debug code is a good approach if not enabled.

> 
> - OR: Polluted (with rtems/bspIo.h) implementation:
> 
> #define SHELL_STD_DEBUG 1  /* Or 0. */
> #define SHELL_WINSIZE_DEBUG 1  /* Or 0. */
> 
> #include 
> #define shell_std_debug_(ENABLE, ...) \
>   do { if (ENABLE) printk("shell[%08x]: ", rtems_task_self()); 
> printk(__VA_ARGS__); } while (0)
> 
> #define shell_std_debug(...) shell_std_debug_(SHELL_STD_DEBUG, __VA_ARGS__)
> #define shell_winsize_debug(...) shell_std_debug_(SHELL_WINSIZE_DEBUG, 
> __VA_ARGS__)
> 
>>
>> I would leave the "vtime" static, there was no way to change the previous 
>> timeout either.
>>
>>>
 +static int rtems_shell_winsize_vtime = 1;  /* VTIME timeout in .1 seconds 
 */

Why is this in RAM. Do you see users needing to adjust this value? If so now
would a user change it?

 +
 +static void rtems_shell_winsize_vdb(const char *format, va_list ap) {
 +  if (rtems_shell_winsize_dbf == false)
 +return;
 +  printf("shell_winsize: ");
 +  vprintf(format, ap);
 +  fflush(stdout);
 +}
 +
 +static void rtems_shell_winsize_db(const char *format, ...) {
 +  va_list ap;
 +  va_start(ap, format);
 +  rtems_shell_winsize_vdb(format, ap);
 +  va_end(ap);
 +}
 +
 /*
 * Wait for the string to return or timeout.
 */
 -static bool rtems_shell_term_wait_for(const int fd, const char* str, 
 const int timeout)
 +static bool rtems_shell_term_wait_for(const int fd, const char* str)
 {
 -  int msec = timeout;
  int i = 0;
 -  while (msec-- > 0 && str[i] != '\0') {
 +  while (str[i] != '\0') {
char ch[2];
 -if (read(fd, &ch[0], 1) == 1) {
 -

Xilinx QSPI Flash Patches

2024-01-23 Thread aaron . nyholm
Hi All,

Attached are V2 of the patches that adds a wrapper around Xilinx's$
XQspiPsu flash driver to rtems_flashdev. This has been placed in$
bsp/shared. The JFFS2 driver has been removed as it is outdated.

Thanks,
Aaron.


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


[PATCH v2 1/3] build: Fix build issues with xqspipsu on versal

2024-01-23 Thread aaron . nyholm
From: Aaron Nyholm 

---
 spec/build/bsps/aarch64/xilinx-versal/grp.yml|  2 ++
 .../bsps/aarch64/xilinx-versal/optxilversal.yml  | 16 
 2 files changed, 18 insertions(+)
 create mode 100644 spec/build/bsps/aarch64/xilinx-versal/optxilversal.yml

diff --git a/spec/build/bsps/aarch64/xilinx-versal/grp.yml 
b/spec/build/bsps/aarch64/xilinx-versal/grp.yml
index badfa07fcc..6b4ea31133 100644
--- a/spec/build/bsps/aarch64/xilinx-versal/grp.yml
+++ b/spec/build/bsps/aarch64/xilinx-versal/grp.yml
@@ -42,6 +42,8 @@ links:
   uid: optclkuart
 - role: build-dependency
   uid: optconminor
+- role: build-dependency
+  uid: optxilversal
 - role: build-dependency
   uid: ../../obj
 - role: build-dependency
diff --git a/spec/build/bsps/aarch64/xilinx-versal/optxilversal.yml 
b/spec/build/bsps/aarch64/xilinx-versal/optxilversal.yml
new file mode 100644
index 00..892f26cca7
--- /dev/null
+++ b/spec/build/bsps/aarch64/xilinx-versal/optxilversal.yml
@@ -0,0 +1,16 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+actions:
+- get-integer: null
+- define: null
+build-type: option
+copyrights:
+- Copyright (C) 2023 Aaron Nyholm
+default:
+- enabled-by: true
+  value: 1
+description: Replicate versal define for XQspiPsu files.
+enabled-by: true
+format: '{}'
+links: []
+name: versal
+type: build
-- 
2.25.1

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


[PATCH v2 2/3] bsps: Add flash wrapper for Xilinx GQSPI

2024-01-23 Thread aaron . nyholm
From: Aaron Nyholm 

---
 bsps/aarch64/xilinx-versal/include/bsp/irq.h  |   1 +
 bsps/include/dev/spi/xqspi_flash.h|  65 ++
 bsps/include/dev/spi/xqspipsu-flash-helper.h  |  20 ++
 bsps/shared/dev/spi/xqspi_flash.c | 210 ++
 bsps/shared/dev/spi/xqspipsu-flash-helper.c   |  13 ++
 spec/build/bsps/aarch64/xilinx-versal/grp.yml |   4 +
 spec/build/bsps/objxilinxsupportlp64.yml  |   4 +-
 spec/build/bsps/objxqspiflash.yml |  22 ++
 spec/build/bsps/optxilsupportpath.yml |   4 +-
 9 files changed, 341 insertions(+), 2 deletions(-)
 create mode 100644 bsps/include/dev/spi/xqspi_flash.h
 create mode 100644 bsps/shared/dev/spi/xqspi_flash.c
 create mode 100644 spec/build/bsps/objxqspiflash.yml

diff --git a/bsps/aarch64/xilinx-versal/include/bsp/irq.h 
b/bsps/aarch64/xilinx-versal/include/bsp/irq.h
index b34bdfd345..6f4d387e8f 100644
--- a/bsps/aarch64/xilinx-versal/include/bsp/irq.h
+++ b/bsps/aarch64/xilinx-versal/include/bsp/irq.h
@@ -61,6 +61,7 @@ extern "C" {
 #define VERSAL_IRQ_ETHERNET_0_WAKEUP 89
 #define VERSAL_IRQ_ETHERNET_1 90
 #define VERSAL_IRQ_ETHERNET_1_WAKEUP 91
+#define VERSAL_IRQ_QSPI 157
 
 /** @} */
 
diff --git a/bsps/include/dev/spi/xqspi_flash.h 
b/bsps/include/dev/spi/xqspi_flash.h
new file mode 100644
index 00..e4bc4a5183
--- /dev/null
+++ b/bsps/include/dev/spi/xqspi_flash.h
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/*
+ * Copyright (C) 2023, 2023 Aaron Nyholm
+ *
+ * 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 XILINX_XQSPI_FLASH_H
+#define XILINX_XQSPI_FLASH_H
+
+#include 
+#include 
+
+#define XQSPI_MAX_REGIONS 32
+#define MAX_READ_SIZE 0x8000
+
+/*
+ * @brief Initializes a flash device using Xilinx's xqspi flash
+ * driver. The flash device is not registered in this call.
+ * If an rtems_flashdev is created using xqspi_flash_init it must be
+ * destroyed using xqspi_flash_destroy.
+ *
+ * @param[in] xQspiDev A configured XQspiPsu device to initialise.
+ *
+ * @retval A pointer to the rtems_flashdev.
+ * @retval NULL on failure.
+*/
+rtems_flashdev* xqspi_flash_init(XQspiPsu *xQspiDev);
+
+/*
+ * @brief Destroys a rtems_flashdev initialised with xqspi_flash_init.
+ * If an rtems_flashdev is created using xqspi_flash_init it must be
+ * destroyed using xqspi_flash_destroy. The XQspiPsu originally passed in
+ * is untouched.
+ *
+ * @param[in] flash The flashdev to destroy
+*/
+void xqspi_flash_destroy(rtems_flashdev* flash);
+
+typedef struct versal_xqspi_region_table {
+  rtems_flashdev_region versal_xqspi_regions[XQSPI_MAX_REGIONS];
+  uint32_t versal_xqspi_bit_allocator;
+} versal_xqspi_region_table;
+
+#endif /* XILINX_XQSPI_FLASH_H */
diff --git a/bsps/include/dev/spi/xqspipsu-flash-helper.h 
b/bsps/include/dev/spi/xqspipsu-flash-helper.h
index e689660881..e73952769c 100644
--- a/bsps/include/dev/spi/xqspipsu-flash-helper.h
+++ b/bsps/include/dev/spi/xqspipsu-flash-helper.h
@@ -190,3 +190,23 @@ int QspiPsu_NOR_RDSFDP(
   u32 ByteCount,
   u8 **ReadBfrPtr
 );
+
+/**
+ * This function returns the page size of attached flash parts.
+ *
+ * @param  QspiPsuPtr is a pointer to the QSPIPSU driver component to use.
+ *
+ * @return The page size of attached flash in bytes.
+ *
+ 
**/
+u32 QspiPsu_NOR_Get_Page_Size(XQspiPsu *QspiPsuPtr);
+
+/**
+ * This function returns the JEDEC ID of attached flash parts.
+ *
+ * @param  QspiPsuPtr is a pointer to the QSPIPSU driver component to use.
+ *
+ * @return The JEDEC ID of attached flash in bytes.
+ *
+ 
**/
+u32 QspiPsu_NO

[PATCH v2 3/3] libmisc/shell: Improve print messages for flashdev command

2024-01-23 Thread aaron . nyholm
From: Aaron Nyholm 

---
 cpukit/libmisc/shell/main_flashdev.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/cpukit/libmisc/shell/main_flashdev.c 
b/cpukit/libmisc/shell/main_flashdev.c
index ca2454b33c..dc73d3f9db 100644
--- a/cpukit/libmisc/shell/main_flashdev.c
+++ b/cpukit/libmisc/shell/main_flashdev.c
@@ -199,7 +199,7 @@ int flashdev_shell_read(
   }
 
   /* Print buffer out in 32bit blocks */
-  printf("Reading %s at 0x%08x for %d bytes\n", dev_path, address, bytes);
+  printf("Reading %s at 0x%08x for 0x%x bytes\n", dev_path, address, bytes);
   for (int i = 0; i < (bytes/4); i++) {
 printf("%08x ", ((uint32_t*)buffer)[i]);
 if ((i+1)%4 == 0) {
@@ -281,6 +281,13 @@ int flashdev_shell_write(
 return -1;
   }
 
+  printf(
+"Writing %s to %s at 0x%08x for 0x%jx bytes\n",
+file_path,
+dev_path,
+address,
+length
+  );
   /* Create buffer */
   buffer = calloc(1, 0x1000);
 
@@ -358,7 +365,7 @@ int flashdev_shell_erase(
 return -1;
   }
 
-  printf("Erasing at %08x for %x bytes\n", address, bytes);
+  printf("Erasing at 0x%08x for 0x%x bytes\n", address, bytes);
 
   /* Erase flash */
   args.offset = address;
-- 
2.25.1

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