[PATCH v2] user: Add docu for use of Rust with RTEMS

2024-02-23 Thread Frank Kuehndel
From: Frank Kühndel 

---
 user/index.rst   |   3 +-
 user/overview/index.rst  |   2 +
 user/rust/bare-metal.rst | 548 +++
 user/rust/index.rst  |  64 +
 4 files changed, 616 insertions(+), 1 deletion(-)
 create mode 100644 user/rust/bare-metal.rst
 create mode 100644 user/rust/index.rst

diff --git a/user/index.rst b/user/index.rst
index 5b7f3ce..0cc6b2c 100644
--- a/user/index.rst
+++ b/user/index.rst
@@ -18,7 +18,7 @@ RTEMS User Manual (|version|).
 | |copy| 2018 Shashvat Jain
 | |copy| 2018 Vidushi Vashishth
 | |copy| 2017 Tanu Hari Dixit
-| |copy| 2016, 2019 embedded brains GmbH & Co. KG
+| |copy| 2016, 2024 embedded brains GmbH & Co. KG
 | |copy| 2016, 2019 Sebastian Huber
 | |copy| 2012, 2022 Chris Johns
 | |copy| 2012, 2020 Gedare Bloom
@@ -51,5 +51,6 @@ RTEMS User Manual (|version|).
 
 tools/index
 rsb/index
+rust/index
 
 glossary/index
diff --git a/user/overview/index.rst b/user/overview/index.rst
index 16389d9..cc292e1 100644
--- a/user/overview/index.rst
+++ b/user/overview/index.rst
@@ -66,6 +66,8 @@ RTEMS provides the following basic feature set:
 
 - Python and MicroPython
 
+- :ref:`Rust `
+
 - Parallel languages
 
 - :ref:term:`EMB²`
diff --git a/user/rust/bare-metal.rst b/user/rust/bare-metal.rst
new file mode 100644
index 000..b1c3980
--- /dev/null
+++ b/user/rust/bare-metal.rst
@@ -0,0 +1,548 @@
+.. SPDX-License-Identifier: CC-BY-SA-4.0
+
+.. Copyright (C) 2024 embedded brains GmbH & Co. KG
+
+.. _RustBareMetal:
+
+Bare Metal Rust with RTEMS
+==
+
+To develop with Rust and RTEMS together, you must find a Rust bare metal
+target which matches an RTEMS BSP. The instructions in this section
+are for a SPARC and a Risc-V *hello world* program. These examples use
+the combinations shown in the table below:
+
+++--++--+
+| RTEMS Architecture | RTEMS BSP| Rust Target| Rust 
CPU |
+++==++==+
+| rtems-sparc| sparc/leon3  | sparc-unknown-none-elf | leon3   
 |
+++--++--+
+| rtems-riscv| riscv/rv64imafdc | riscv64gc-unknown-none-elf | 
generic-rv64 |
+++--++--+
+
+The following sources may be helpful to find a matching BSP and target:
+
+- ``./waf bsplist`` -- executed in an RTEMS git clone
+- ``source-builder/sb-set-builder --list-bsets`` -- executed in an
+  RTEMS source builder git clone
+- `RTEMS Supported Architectures 
`_
+- `RTEMS Board Support Packages 
`_
+- ``rustc --print target-list``
+- ``rustc --target=riscv64gc-unknown-none-elf --print target-features``
+- ``rustc --target=riscv64gc-unknown-none-elf  --print target-cpus``
+- `Rust Platform Support 
`_
+
+The sample instructions which follow build two executables using the
+same source code for the RTEMS configuration ``init.c`` and the Rust
+hello-world application ``lib.rs``. Only the configuration as well as
+the compile and link commands differ for SPARC Leon3 and RISC-V
+64 bit. The Rust application uses ``printk()`` from RTEMS to print
+text to the console.
+
+After building the RTEMS BSP and installing Rust, the basic steps are:
+
+1. Compile the RTEMS configuration in ``init.c`` into an object
+   file using the GNU C compiler from the RTEMS tool chain.
+2. Compile the Rust code containing ``main()`` into a
+   static library using the Rust compiler.
+3. Link the static library with the Rust code,
+   the RTEMS configuration and the RTEMS OS libraries
+   together into one single executable.
+4. Finally run the executable on a simulator.
+
+You can build the examples in a container. This is optional. If you
+prefer to follow these instructions directly on your machine simply
+skip the section *Build a Container*. Just make sure that you machine
+meets all prerequisites to build the RTEMS tools and install the Rust
+tools.
+
+.. _RustBareMetal_Container:
+
+Build a Container
+-
+
+The container must be able to execute the RTEMS source builder and to
+install and run the Rust tools. In an empty directory of your choice
+create the following ``Dockerfile``.
+
+.. code-block:: shell
+
+cat >Dockerfile <<"EOF"
+# Dockerfile to build a container image to use Rust on top of RTEMS
+FROM ubuntu:22.04
+RUN apt-get update && \
+apt-get -y upgrade && \
+apt-get install -y \
+bison \
+build-essential \
+curl \
+flex \
+g++ \
+gdb \
+

[PATCH rtems-docs 1/1] user: Add docu for use of Rust with RTEMS

2024-02-16 Thread Frank Kuehndel
From: Frank Kühndel 

---
 user/index.rst   |   3 +-
 user/overview/index.rst  |   2 +
 user/rust/bare-metal.rst | 549 +++
 user/rust/index.rst  |  64 +
 4 files changed, 617 insertions(+), 1 deletion(-)
 create mode 100644 user/rust/bare-metal.rst
 create mode 100644 user/rust/index.rst

diff --git a/user/index.rst b/user/index.rst
index 5b7f3ce..0cc6b2c 100644
--- a/user/index.rst
+++ b/user/index.rst
@@ -18,7 +18,7 @@ RTEMS User Manual (|version|).
 | |copy| 2018 Shashvat Jain
 | |copy| 2018 Vidushi Vashishth
 | |copy| 2017 Tanu Hari Dixit
-| |copy| 2016, 2019 embedded brains GmbH & Co. KG
+| |copy| 2016, 2024 embedded brains GmbH & Co. KG
 | |copy| 2016, 2019 Sebastian Huber
 | |copy| 2012, 2022 Chris Johns
 | |copy| 2012, 2020 Gedare Bloom
@@ -51,5 +51,6 @@ RTEMS User Manual (|version|).
 
 tools/index
 rsb/index
+rust/index
 
 glossary/index
diff --git a/user/overview/index.rst b/user/overview/index.rst
index 16389d9..cc292e1 100644
--- a/user/overview/index.rst
+++ b/user/overview/index.rst
@@ -66,6 +66,8 @@ RTEMS provides the following basic feature set:
 
 - Python and MicroPython
 
+- :ref:`Rust `
+
 - Parallel languages
 
 - :ref:term:`EMB²`
diff --git a/user/rust/bare-metal.rst b/user/rust/bare-metal.rst
new file mode 100644
index 000..b893f57
--- /dev/null
+++ b/user/rust/bare-metal.rst
@@ -0,0 +1,549 @@
+.. SPDX-License-Identifier: CC-BY-SA-4.0
+
+.. Copyright (C) 2024 embedded brains GmbH & Co. KG
+
+.. _RustBareMetal:
+
+Bare Metal Rust with RTEMS
+==
+
+To develop with Rust and RTEMS together, you must find a Rust bare metal
+target which matches an RTEMS BSP. The instructions in this section
+are for a SPARC and a Risc-V *hello world* program. These examples use
+the combinations shown in the table below:
+
+++--++--+
+| RTEMS Architecture | RTEMS BSP| Rust Target| Rust 
CPU |
+++==++==+
+| rtems-sparc| sparc/leon3  | sparc-unknown-none-elf | leon3   
 |
+++--++--+
+| rtems-riscv| riscv/rv64imafdc | riscv64gc-unknown-none-elf | 
generic-rv64 |
+++--++--+
+
+The following sources may be helpful to find a matching BSP and target:
+
+- ``./waf bsplist`` -- executed in an RTEMS git clone
+- ``source-builder/sb-set-builder --list-bsets`` -- executed in an
+  RTEMS source builder git clone
+- `RTEMS Supported Architectures 
`_
+- `RTEMS Board Support Packages 
`_
+- ``rustc --print target-list``
+- ``rustc --target=riscv64gc-unknown-none-elf --print target-features``
+- ``rustc --target=riscv64gc-unknown-none-elf  --print target-cpus``
+- `Rust Platform Support 
`_
+
+The sample instructions which follow build two executables using the
+same source code for the RTEMS configuration ``init.c`` and the Rust
+hello-world application ``lib.rs``. Only the configuration as well as
+the compile and link commands differ for SPARC Leon3 and RISC-V
+64 bit. The Rust application uses ``printk()`` from RTEMS to print
+text to the console.
+
+After building the RTEMS BSP and installing Rust, the basic steps are:
+
+(1) Compile the RTEMS configuration in ``init.c`` into an object
+file using the GNU C compiler from the RTEMS tool chain.
+(2) Compile the Rust code containing ``main()`` into a
+static library using the Rust compiler.
+(3) Link the static library with the Rust code,
+the RTEMS configuration and the RTEMS OS libraries
+together into one single executable.
+(4) Finally run the executable on a simulator.
+
+I build the examples in a container. This is optional. If you prefer
+to follow these instructions directly on your machine simply skip the
+section *Build a Container*. Just make sure that you machine meets all
+prerequisites to build the RTEMS tools and install the Rust tools.
+
+.. _RustBareMetal_Container:
+
+Build a Container
+-
+
+The container must be able to execute the RTEMS source builder and to
+install and run the Rust tools. In an empty directory of your choice
+create the following ``Dockerfile``.
+
+.. code-block:: shell
+
+cat >Dockerfile <<"EOF"
+# Dockerfile to build a container image to use Rust on top of RTEMS
+FROM ubuntu:22.04
+RUN apt-get update && \
+apt-get -y upgrade && \
+apt-get install -y \
+binutils \
+bison \
+bzip2 \
+curl \
+flex \
+gcc \
+g++ 

[PATCH rtems-docs 0/1] user: Add docu for use of Rust with RTEMS

2024-02-16 Thread Frank Kuehndel
From: Frank Kühndel 

This is the long promised Rust on RTEMS step-by-step guide.

For reviewing it, I suggest the natural order:

  1) user/rust/index.rst -- The introduction
  2) user/rust/bare-metal.rst -- The step-by-step guide
  
If you prefer reviewing the PDF or HTML, you can download them here:

  https://share.embedded-brains.de/index.php/s/morK77CeTdXwpc4

Some notes/questions:

* I did not find the right place where to put this text. Currently,
  it is an extra chapter at top level in the user manual. Chapter
  "Quick Start" seemed not to be the right place to me.

* I assume that someone (DLR?) writes a step-by-step guide for
  using Rust with libstd once it becomes available. This might be
  an additional section in an extra file next to

user/rust/bare-metal.rst

  Moreover, the current paragraph "At the time of writing no such
  target exists. [...]" will then be removed/replaced.

* There are a few links to external sources. Should they be deleted?

* There is a sub-section on creating a container. This sub-section
  is completely optional. I used this container to test the
  instructions in a clean environment. There are good reasons to keep
  it in the document and there are good reasons to remove it. What do
  you think?

* I wrote instructions to "Build the RTEMS Tools" and to "Build and
  Install the RTEMS BSPs". Yet, I could just refer to the
  "Quick Start" sections instead. I believe it is more straightforward
  for the reader the way it is now. Do you prefer these sections to be
  removed?

Frank Kühndel (1):
  user: Add docu for use of Rust with RTEMS

 user/index.rst   |   3 +-
 user/overview/index.rst  |   2 +
 user/rust/bare-metal.rst | 549 +++
 user/rust/index.rst  |  64 +
 4 files changed, 617 insertions(+), 1 deletion(-)
 create mode 100644 user/rust/bare-metal.rst
 create mode 100644 user/rust/index.rst

-- 
2.35.3

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

[PATCH v2 1/1] RSB: Mitigate too short error reports

2023-01-20 Thread Frank Kuehndel
From: Frank Kühndel 

Close #4642
---
 source-builder/sb/ereport.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/source-builder/sb/ereport.py b/source-builder/sb/ereport.py
index d8fb5f6..52ee2eb 100755
--- a/source-builder/sb/ereport.py
+++ b/source-builder/sb/ereport.py
@@ -54,7 +54,9 @@ def generate(name, opts, header = None, footer = None):
 name = name.replace('/', '-')
 with open(name, 'w') as l:
 l.write(os.linesep.join(r))
-log.notice('  See error report: %s' % (name))
+log.notice(os.linesep.join(['  See error report: %s' % (name),
+'  Note: In some cases the error appears only in',
+'  the complete build log (see --log option)']))
 except:
 log.stderr('error: failure to create error report')
 raise
-- 
2.35.3

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

[PATCH v2 0/1] RSB: Mitigate too short error reports

2023-01-20 Thread Frank Kuehndel
From: Frank Kühndel 

Hello,

this is the promised patch to close my bug report #4642
https://devel.rtems.org/ticket/4642
"RSB: log.py tends to remove relevant error messages".

I tested it using Christian's Github CI  - see his Email:
https://lists.rtems.org/pipermail/devel/2023-January/074099.html

You can see the automated build and test results of the "draft" pull
request for this patch here:
https://github.com/embedded-brains/rtems-source-builder/pull/4/checks

If you have a Github account (needed to see the details and artifacts),
you can see the new error report message at the end of the output of
failing builds, as for example here (click on the red-bubble at
"build toolchain" and scroll to the bottom):
https://github.com/embedded-brains/rtems-source-builder/actions/runs/3968465295/jobs/6801666558

Greetings
Frank

Frank Kühndel (1):
  RSB: Mitigate too short error reports

 source-builder/sb/ereport.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

-- 
2.35.3

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

[PATCH 0/1] RSB: Mitigate too short error reports

2022-12-20 Thread Frank Kuehndel
From: Frank Kühndel 

Hello Chris,

I am making an attempt to close my bug report #4642
https://devel.rtems.org/ticket/4642
"RSB: log.py tends removes relevant error messages".

The difficulty seems to be to find a rather short text indicating
that the relevant error can sometimes be so far way from the
bottom of the build log, that it is not at all in the last 400
lines which are stored in the error report. Moreover, the errors
reported do not all stem from "make".

Instead of the suggested notice in the patch, alternative wordings
are possible like:

"The first error may appear so far way from the bottom of the report
that it can only be found in the whole build log."

or even simpler:

"The first error may be far way from the end of the build log."

If you do not like any text, then it is OK with me to close the ticket
without any fix.

Greetings,
Frank

Frank Kühndel (1):
  RSB: Mitigate too short error reports

 source-builder/sb/ereport.py | 4 
 1 file changed, 4 insertions(+)

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

[PATCH 1/1] RSB: Mitigate too short error reports

2022-12-20 Thread Frank Kuehndel
From: Frank Kühndel 

Close #4642
---
 source-builder/sb/ereport.py | 4 
 1 file changed, 4 insertions(+)

diff --git a/source-builder/sb/ereport.py b/source-builder/sb/ereport.py
index d8fb5f6..d391917 100755
--- a/source-builder/sb/ereport.py
+++ b/source-builder/sb/ereport.py
@@ -55,6 +55,10 @@ def generate(name, opts, header = None, footer = None):
 with open(name, 'w') as l:
 l.write(os.linesep.join(r))
 log.notice('  See error report: %s' % (name))
+log.notice('  (Hint: The first error may be in front of a '
+'line containing\n'
+'  "Error 1" [GNU make] and may be only in the whole log '
+'["--log" option].)')
 except:
 log.stderr('error: failure to create error report')
 raise
-- 
2.35.3

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

[PATCH] TFTPFS: Adding missing diagram

2022-10-13 Thread Frank Kuehndel
From: Frank Kühndel 

---
 filesystem/trivial_ftp.rst  |   8 --
 images/filesystem/tftpfs_usage.png  | Bin 0 -> 47217 bytes
 images/filesystem/tftpfs_usage.puml |  37 
 3 files changed, 43 insertions(+), 2 deletions(-)
 create mode 100644 images/filesystem/tftpfs_usage.png
 create mode 100644 images/filesystem/tftpfs_usage.puml

diff --git a/filesystem/trivial_ftp.rst b/filesystem/trivial_ftp.rst
index 3ef8bba..b8e1ae4 100644
--- a/filesystem/trivial_ftp.rst
+++ b/filesystem/trivial_ftp.rst
@@ -275,16 +275,20 @@ repository):
 Usage
 =
 
-The following diagram shows how the TFTP filesystem is used by an
+The following diagram usage_ shows how the TFTP filesystem is used by an
 application.  The mount point can be any directory.  The name ``/tftp``
 used in the figure serves only as an example.  The final unmounting and
 remove directory steps are optional.
 
+.. _usage:
+
 .. figure:: ../images/filesystem/tftpfs_usage.png
-  :width: 90%
+  :width: 75%
   :align: center
   :alt: TFTP Usage Diagram
 
+  TFTP file system usage
+
 Mounting the TFTP Filesystem
 
 
diff --git a/images/filesystem/tftpfs_usage.png 
b/images/filesystem/tftpfs_usage.png
new file mode 100644
index 
..5faa72f768a0742c50f32fa30380a3be33e7
GIT binary patch
literal 47217
zcmb5Wby$>L+ci#zAl)E{bV!4eN_PuL!_b}5jg%6C(jX-zQVt=V64EW*NaxTE-$uOe
z=Xu}n_w73c!9DElX9HKD_0=San
z*c$|XJ#m)MbT+nk@USs8bB2>LwKH`zbT&1iF!G?VaCUa!XJd1)F|>1bv9)0}wztJ$
z=X(SPhrnm~O4IqD>u~VkHts1!s>=40?AX2^TK#zU@GCyj#!|)SsZ`=JGT_JFBUXwM
zdsHlKWAgmvm#b60Y+-HN7`k4i)!N8pa5eLMrq6!w-AZLxPZBlZbIdD^yz0w$8d9ut#Px<*CupWi+|;*
zU|>3Q^mp4Q;VcFRQ=(_}U;O!xYLrPvbaUF#rc20=k*UY@&$}=Kmw#ad`m%3d_yxG{
zj6tek_x&%zzDhmOu?@C5>8sGT{Vi%Wr^0j9}
z+s>1px>}=N=|8;8`pD~KAZ~G;dE^if=27L`W<=m>KzNv}XB)J}FJ(=OtGb<$h$EDr
z2)#nU*yktFSNXvW2loa}MqK2TJ7g>Mf#xfE2|OB}>?ZI4W!1U>lB}-m5z^J>5JpLwY}WhwD;m
zhgd11Y^a(G3f3lPW4}Mpml)Y7Vi=tqsjHQQ{u*>*4c_kW_hQ~A!tJ!8s_W9{S^V&`
z{1JTD*B7;4-<_ptmFwb_o=Ijl6TE*aQ0D2ev1VCYa3YK)KDLuwtr%4SI(C9RIV
zpw>6EvYLLVgH^a?IiQ61{mBi~x#&2k`~2LWEL2Y_g9o#YZ)5hXV5pBOikYRkzy_(}
zn%9BQB6{cIET+!*g`MuOMiv59UCj>j*b@O>MkXdE9-foIEUBRe>L_MP@BtUc3Rb(e
zp+u?o;TPA-L03>LI73yjtY;(@g^8JkmWqmJt>#ho3UCibUR>yh1rQj7jHFo
z(mpw`KYbd5B3Jqr1?m{9?ls@5>_u{zWsM-25`$B82#Z|XEl@8AEvB&!fia5dO(h2m
zsNvOxnxkrM9j^PLo^aRl*wQyg7lLM>#~m+ZhREvelasIdixOTe90fL6kAJo-DJikE
zv?Ph3E8aDL8Og8kyCDm|3rs>IhK9zboDzx{)|QQBdbD>@Dt
z^XAL@?ys-ju|KBm`NqLrTf`Z9my
z>CI5XWU&)HKR@5mAziMW8W%^qt%|#zB<>!UY)6+9NW_Cn@Ip3GVJS9rqNmHU!~4OP
zY#dCg8t4Q|qSJ
z8BH5Tz@(o4s?%xJsMSJF=7GgvCJv;+=FG~|^J}&+WpaXs#3M8>cYHTDH}lX+JKE!&
znQz`_r9Ky~!k_aiWtt_|hjQo?A8F>P1nSY!m3_J!T7eA97f
z%t8by4>ovUNI1VcY)V7lCrat;p#POp|9(b>T$9$Ts5lq6+Tw+kmAC9k1fuS=6Uw)-
zHvwb(*f9Vxd@kr)R_Qj3O3)S0tkv8>2@AzD?4T>0VAG#%|HjR(QJ}8X(V0NO%J}pt
zD&^Dk=6qoqo%))wH}HD>X)_VA1scC!R=s3ih%=D_tB|f>k(S-GIZ@DjT<
zKSW96+ok+hq90%0Nxc^TBpPPWaPPHph?>4vkzjfN_agz4LY9y`jl#sUpQI7rkp>HD
zYcF;iH^24ZLS&8!7S!xY@gXH)$QV$)aKHVfs*j1uUc_kL%-bR*!Dv3+32fG1o0J3}
z4i@PYTwdnd&2Rr6_E_mrrm%P1cS9q*JSbwTr`5|>_g)IA9Rd|F^?ZwIN+#78K
zM51SwLm%TtYu#$Ao!Su_^nH$S{^^F?0>R^FU%fzJ7OxS~+s(ef+C0}T&+kp<$#C7?
z;N$D`M00j>LQD;ogKxYnMGGB+wx4W{;q0*?Oc}Sk5?kVOTm6E4dS;1zkp`EkEQmA_
z9bLg?JBj`7nf-N`Hd%-4bHD3!d(56hjue<|Y1Zu`$mw2xqx0d;>02feSI)e)yZe
zM(=I<;*(Z6V}O>u1_S)1E+s{6QYA9KM|`LWQrKJFS*(kj6tRw}?s=DTQTa
z(UsKGQQqYPd!&2!upu=ZPN}#n0s-!J0T-0R`z$nr`=zvU#c%=p7M4oDGONKD
z7o-u*1@?qo%>)>;yRCgb3q!pAEG3_BnQWHMgb%r}MXdfS89ML{fS#8Jj
zrgVpp(InKR|IL$8Z4Pfb(XoMnm-BIUxeB*$EFGzL(r}I6#GhK4c{hf+@BP~Jrqm&7
zs6L`}ShJWQgQ*F%Zm7jT`nF$vvRIKS@$1BDl}d_|*e#9cIm8<<{*MgzNkmCCf0d
zmX;1V?Sd2N`e-5ohL5?>2_%l#xSA(nUgT$MP8yiT2Rqp**JgP;Wrd5gTc6;Jt%d#9
zM5h1b19M93VT)(Pm6WS0{ZBj_{fw>y<{IW4sFe-n^dm5N%N)-}5`}#e)O;u%
zhL!YLcn56Xmx}AmxD{*HK{czDd(;<7g|)Rw!r>A$el+s8AE~cuvMa{F4w{s12=_OprzbHg%z7Rwu{_ii(mQgbyD+eEgWT)fr_Op(t;jPwvgw
zJYP+%`V@rsc?xwO{%UyH&+07X0jxEQ!v`gCCbT#ZJqZeFJ3Bjdb;1BH10<%!prCs%
z>G=6cszexw>=f2V*W0w;`BjV7w9qwAEIfMsg;zg?tB*|Jjjyo%=f7>=&^G!gQAg)M
zSYSMVKSMWwtK4t7vT5@=ZtAwxDP(;(=8P{11cVJ}wRD0s#^Q*}HL1cMlqL?rk#L**kxgZxo?9~UesiJZuNtP_iq
zsTv1(s6oL{*7icBP@EZUlnH$^Q)gI>3xnADtmMMzO6#+k6G;CzbPTo;k%du`^`SzV
z=q-Thv@}Yf7!hB8iLHOBEtho9?5H`RYvRzliK0A
zAnB)3(vJAx(R#}>eQIi3ggY6vGmLd*ue{D*hA{?AhF`^{0}lw(W2`<#8aX
zDrX;Vx^#2jf14rV9oMUu0-(}dooy`0W`#U%gQ9^1&)sH7eoE-cD03EKf1_u#@a>
z1w=+z^X*GsDqD`lNYjPGHoR-xt~dO7qztd=UCCUonlOuw?@g5U-7x9leYaE!^j%wu
z@g@C!b~bbaA8HbS0#*EyEVG`Ess}J8Bm#B5TDanK`VyJk$(1hA`CP0-jD?
z&^{TycBR0g3w?5j8%Kl>h^1WKW=D?L+`iM^o@ahv!9zKOm
z|GKJ~e{tt#Am@7242_exy9-Iq1*@v(_ukHsl~tjMeBWp{8_=qJjr(6!RYHnsh9%rx
zFlPk3WVEI)THo_sF40dleVSK5F`!dpw6)Cs^nEG5yShl=o(D
z4`5IH8T!_rKfmPUSU{x^k%tXhEmi`>l-UrBPd_$E))F}U4P%@kK$Xzd)s>W#
z1S<`xnC3UQp?}(CQm%uwlhvS+Z(oe<%F_a8eM*$sI)(qjo1Co81$b+-)l7-wpFS
zrc|b}>5i*b*jNhAMA?pT>!VMF-H0|Vf=Vp|z+M!Cva)rpMH=JVyO(0!1cmwt2*#!#
z1VqFD1Y50DmH?nlSOmz^w4vU
z>xo$P0T}g?2w{~O6B9G?{d+JNT3T8|egvU3xCoXh4p3IOiBOd;xtk$@`nn5ip@
znYr7JnjO!i
zVK(r2hs(q=R{rwjf79Ko!
zkd&14?=YFLLj3dp17IoLW48!2pV$cbdZVvtHO^v@@)j#3)4jzsy#I^e*mg+^%inL`BV;LUJ6^_xB>s(CA7$ehiTQ&(1~Z=slh%HIARf=K

[PATCH] tftpDriver.c: Fix Coverity issues

2022-09-16 Thread Frank Kuehndel
From: Frank Kühndel 

CID 1506523: Unchecked return value from library (CHECKED_RETURN)
CID 1506522: Unchecked return value from library (CHECKED_RETURN)
CID 1437618: Unchecked return value from library (CHECKED_RETURN)

Close #4718
---
 cpukit/libfs/src/ftpfs/tftpDriver.c | 27 ++-
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/cpukit/libfs/src/ftpfs/tftpDriver.c 
b/cpukit/libfs/src/ftpfs/tftpDriver.c
index 59136ef59f..0246ed9611 100644
--- a/cpukit/libfs/src/ftpfs/tftpDriver.c
+++ b/cpukit/libfs/src/ftpfs/tftpDriver.c
@@ -525,8 +525,10 @@ static void send_error (
 
 /*
  * Send it
+ *
+ * Ignoring result because error packets are sent once and maybe lost.
  */
-sendto (tp->socket, (char *), len, 0, (struct sockaddr *)to, sizeof 
*to);
+(void) sendto (tp->socket, (char *), len, 0, (struct sockaddr *)to, 
sizeof *to);
 }
 
 /*
@@ -552,11 +554,21 @@ getPacket (struct tftpStream *tp, int retryCount)
 } else if (retryCount == 0) {
 tv.tv_sec = tp->config.first_timeout / 1000L;
 tv.tv_usec = (tp->config.first_timeout % 1000L) * 1000L;
-setsockopt (tp->socket, SOL_SOCKET, SO_RCVTIMEO, , sizeof tv);
+/*
+ * Ignoring result because all possible errors indicate wrong
+ * arguments and these arguments are OK as tested by test suite.
+ */
+(void) setsockopt (tp->socket, SOL_SOCKET, SO_RCVTIMEO, ,
+sizeof tv);
 } else {
 tv.tv_sec = tp->config.timeout / 1000L;
 tv.tv_usec = (tp->config.timeout % 1000L) * 1000L;
-setsockopt (tp->socket, SOL_SOCKET, SO_RCVTIMEO, , sizeof tv);
+/*
+ * Ignoring result because all possible errors indicate wrong
+ * arguments and these arguments are OK as tested by test suite.
+ */
+(void) setsockopt (tp->socket, SOL_SOCKET, SO_RCVTIMEO, ,
+sizeof tv);
 }
 for (;;) {
 union {
@@ -591,7 +603,12 @@ getPacket (struct tftpStream *tp, int retryCount)
 if (retryCount != GET_PACKET_DONT_WAIT) {
 tv.tv_sec = 0;
 tv.tv_usec = 0;
-setsockopt (tp->socket, SOL_SOCKET, SO_RCVTIMEO, , sizeof tv);
+/*
+ * Ignoring result because all possible errors indicate wrong
+ * arguments and these arguments are OK as tested by test suite.
+ */
+(void) setsockopt (tp->socket, SOL_SOCKET, SO_RCVTIMEO, ,
+sizeof tv);
 }
 return len;
 }
@@ -724,7 +741,7 @@ static int process_data_packet (struct tftpStream *tp, 
ssize_t len)
 /*
  * Send it. Errors during send will not matter for this last ACK.
  */
-sendto (
+(void) sendto (
 tp->socket,
 send_buf,
 plen,
-- 
2.35.3

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

[PATCH rtems-docs v2] TFTPFS: New documentation

2022-06-09 Thread Frank Kuehndel
From: Frank Kühndel 

---
 filesystem/index.rst   |   1 +
 filesystem/trivial_ftp.rst | 564 -
 2 files changed, 562 insertions(+), 3 deletions(-)

diff --git a/filesystem/index.rst b/filesystem/index.rst
index f4e2ed6..64a2f1d 100644
--- a/filesystem/index.rst
+++ b/filesystem/index.rst
@@ -9,6 +9,7 @@ RTEMS Filesystem Design Guide (|version|).
 .. topic:: Copyrights and License
 
 | |copy| 1988, 2015 On-Line Applications Research Corporation (OAR)
+| |copy| 2022 embedded brains GmbH (http://www.embedded-brains.de)
 
 .. include:: ../common/license.rst
 
diff --git a/filesystem/trivial_ftp.rst b/filesystem/trivial_ftp.rst
index e43c036..3ef8bba 100644
--- a/filesystem/trivial_ftp.rst
+++ b/filesystem/trivial_ftp.rst
@@ -3,7 +3,565 @@
 Trivial FTP Client Filesystem
 *
 
-This chapter describes the Trivial FTP (TFTP) Client Filesystem.
+This chapter describes the Trivial File Transfer Protocol (TFTP) Client
+Filesystem.  TFTP is designed to be an especially simple protocol which
+uses the User Datagram Protocol (UDP) for data transfer over the Internet.
+Its purpose is to send a single file between to network nodes (client and
+server).  A file can be sent in both directions, i.e. a client can either
+read a file from a server or write a file to the server.
 
-This chapter should be written after the IMFS chapter is completed and describe
-the implementation of the TFTP.
+Besides reading or writing a file no other operations are supported.  That
+is, one cannot seek the file, not append to the end of a file, not open
+the file for reading and writing at the same time, not list directories,
+not move files and so on.
+
+TFTP is inherent insecure as it does not provide any means for
+authentication or encryption.  Therefore, it is highly recommended not
+to employ it on public networks.  Nevertheless, it is still widely used
+to load software and configuration data during early boot stages over
+a Local Area Network (LAN).
+
+RTEMS TFTP Filesystem Implementation
+
+
+The RTEMS TFTP filesystem implements a TFTP client which can be used
+through the file system.  With other words, one needs to mount the
+TFTP filesystem and can afterwards open a file for reading or writing
+below that mount point.  The content of that file is then effectively
+read from or written to the remote server.  The RTEMS implementation
+implements the following features:
+
+* `RFC 1350 `_
+  *The TFTP Protocol (Revision 2)*
+* `RFC 2347 `_
+  *TFTP Option Extension*
+* `RFC 2348 `_
+  *TFTP Blocksize Option*
+* `RFC 7440 `_
+  *TFTP Windowsize Option*
+
+Many simple TFTP server do not support options (RFC 2347). Therefore, in
+case the server rejects the first request with options, the RTEMS client
+makes automatically a second attempt using only the "classical" RFC 1350.
+
+The implementation has the following shortcomings:
+
+* IPv6 is not supported (yet).
+
+* No congestion control is implemented.
+
+  (Congestion is simply expressed a network traffic jam which involves
+  package loss.)  This implementation would worsen a congestion situation
+  and squeeze out TCP connections.  If that is a concern in your setup,
+  it can be prevented by using value `1` as `windowsize` when mounting
+  the TFTP file system.
+
+* One must call ``open()``, ``read()``, ``write()`` and ``close()``
+  at a good pace.
+
+  TFTP is designed to read or write a whole already existing file in
+  one sweep.  It uses timeouts (of unspecified length) and it does not
+  know keep-alive messages.  If the client does not respond to the
+  server in due time, the server sets the connection faulty and drops it.
+  To avoid this, the user must read or write enough data fast enough.
+
+  The point here is, one cannot pause the reading or writing for longer
+  periods of time.  TFTP cannot be used for example to write log files
+  where all few seconds a line is written.  Also opening the
+  file at the beginning of an application and closing it that the end
+  will certainly lead to a timeout.  As another example, one cannot
+  read a file by reading one byte per second, this will trigger a
+  timeout and the server closes the connection.  The opening, reading
+  or writing and closing must happen in swift consecutive steps.
+
+* The transfer mode is always ``octet``.  The only alternative
+  ``netascii`` cannot be selected.
+
+* Block number roll-over is currently not supported.  Therefore,
+  the maximum file size is limited to max-block-number times blocksize.
+  For RFC 1350 blocksize is would be 65535 * 512 = 32 MB.  For the
+  default blocksize is would be 65535 * 1456 = 90 MB.
+
+* The inherent insecurity of the protocol has already be mentioned but
+  it is worth 

[PATCH 6/7] TFTPFS: Add tests

2022-06-03 Thread Frank Kuehndel
From: Frank Kühndel 

---
 testsuites/fstests/tftpfs/init.c | 3197 --
 1 file changed, 3032 insertions(+), 165 deletions(-)

diff --git a/testsuites/fstests/tftpfs/init.c b/testsuites/fstests/tftpfs/init.c
index 91308ec75b..a7ef03cf74 100644
--- a/testsuites/fstests/tftpfs/init.c
+++ b/testsuites/fstests/tftpfs/init.c
@@ -171,6 +171,32 @@ static const T_fixture fixture_default_options = {
   .initial_context = _context
 };
 
+static void setup_mount_point( void *context )
+{
+  int result;
+
+  _Tftp_Reset();
+  result = mkdir( tftpfs_mount_point, S_IRWXU | S_IRWXG | S_IRWXO );
+  T_assert_eq_int( result, 0 );
+}
+
+static void teardown_mount_point( void *context )
+{
+  int result;
+
+  result = rmdir( tftpfs_mount_point );
+  T_assert_eq_int( result, 0 );
+  _Tftp_Reset();
+}
+
+static const T_fixture fixture_mount_point = {
+  .setup = setup_mount_point,
+  .stop = NULL,
+  .teardown = teardown_mount_point,
+  .scope = NULL,
+  .initial_context = _context
+};
+
 /*
  * Test helper functions
  */
@@ -618,191 +644,540 @@ static int rdwt_tftp_client_file(
 }
 
 /*
- * Test cases for the TFTP client interface
- *
- * Since the TFTP file system uses the TFTP client interface for all
- * file transfers, the function of the TFTP client is almost
- * completely tested by the tests for the file system interface.
- * The test cases here - for the TFTP client interface - test only
- * those aspects not (easily) testable through the file system interface.
+ * Unit test cases
  */
 
-#if ENABLE_ALL_TESTS
 /*
- * Write a file to the server using the TFTP client interface.
- * The test uses the default options.
- * The file is 2 and a half data packet long.  No timeouts, packet loss, ...
+ * This is a classical unit test for the function tftp_initialize_net_config().
  * Tests:
- *   * The default options (windowsize = 8 and blocksize = 1456) are used.
- *   * tftp_open() is called with default configuration values.
- *   * The test writes a file using only the TFTP client (i.e. not using the
- * file system)
- *   * The code supports the use of a server name instead of an IP address.
- *   * The first window is also the last window.
- *   * The only ACK packet is the one at the end of window.
- *   * Between sending data packets, the client checks whether any packets
- * are received.
- *   * The client handles files correctly which end in the middle of a window.
+ *   * tftp_initialize_net_config() sets correct default values as defined
+ * in the documentation of the data structures tftp_net_config
+ * and tftp_options.
  */
-T_TEST_CASE_FIXTURE( client_write_simple_file, _default_options )
+T_TEST_CASE( tftp_initialize_net_config )
 {
-  tftp_test_context *ctx = T_fixture_context();
   tftp_net_config config;
-  int bytes_written;
-  uint16_t block_num = 1;
-  size_t pos_in_file = 0;
-  const char options[] =
-TFTP_OPTION_BLKSIZE "\0"
-RTEMS_XSTRING( TFTP_DEFAULT_BLOCK_SIZE ) "\0"
-TFTP_OPTION_WINDOWSIZE "\0"
-RTEMS_XSTRING( TFTP_DEFAULT_WINDOW_SIZE );
+  memset( , 0, sizeof( config ) );
+  tftp_initialize_net_config(  );
+  T_eq_u16( config.retransmissions, 6 );
+  T_eq_u16( config.server_port, 69 );
+  T_eq_u32( config.timeout, 1000 );
+  T_eq_u32( config.first_timeout, 400 );
+  T_eq_u16( config.options.block_size, 1456 );
+  T_eq_u16( config.options.window_size, 8 );
+}
 
-  /* T_set_verbosity( T_VERBOSE ); */
-  _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
-#ifdef RTEMS_NETWORKING
-  _Tftp_Add_interaction_bind( TFTP_FIRST_FD, AF_INET, 0 );
-#endif
-  _Tftp_Add_interaction_send_wrq(
-TFTP_FIRST_FD,
+/*
+ * This is a classical unit test for the function tftp_initialize_net_config().
+ * Tests:
+ *   * tftp_initialize_net_config() does not crash when called with a
+ * NULL pointer.
+ */
+T_TEST_CASE( tftp_initialize_net_config_null )
+{
+  tftp_initialize_net_config( NULL );
+}
+
+/*
+ * This is a classical unit test for the function tftp_open().
+ * Tests:
+ *   * tftp_open() returns an error when called with a NULL pointer
+ * for hostname.
+ */
+T_TEST_CASE_FIXTURE( tftp_open_null_hostname, _rfc1350 )
+{
+  tftp_test_context *ctx = T_fixture_context();
+  int res;
+
+  res = tftp_open(
+NULL, /* hostname */
 tftpfs_file,
-TFTP_STD_PORT,
-tftpfs_server0_ipv4,
-TFTP_DEFAULT_BLOCK_SIZE,
-TFTP_DEFAULT_WINDOW_SIZE,
-true
-  );
-  _Tftp_Add_interaction_recv_oack(
-TFTP_FIRST_FD,
-FIRST_TIMEOUT_MILLISECONDS,
-SERV_PORT,
-tftpfs_server0_ipv4,
-options,
-sizeof( options ),
-true
-  );
-  _Tftp_Add_interaction_send_data(
-TFTP_FIRST_FD,
-block_num++,
-pos_in_file,
-TFTP_DEFAULT_BLOCK_SIZE,
-get_file_content,
-SERV_PORT,
-tftpfs_server0_ipv4,
-true
-  );
-  pos_in_file += TFTP_DEFAULT_BLOCK_SIZE;
-  _Tftp_Add_interaction_recv_nothing(
-TFTP_FIRST_FD,
-DO_NOT_WAIT_FOR_ANY_TIMEOUT
-  );
-  _Tftp_Add_interaction_send_data(
-

[PATCH 5/7] TFTPFS: Add test suite framework

2022-06-03 Thread Frank Kuehndel
From: Frank Kühndel 

---
 spec/build/testsuites/fstests/grp.yml |2 +
 spec/build/testsuites/fstests/tftpfs.yml  |   25 +
 testsuites/fstests/tftpfs/init.c  | 1054 +
 .../fstests/tftpfs/tftpfs_interactions.c  |  984 +++
 .../fstests/tftpfs/tftpfs_interactions.h  |  205 
 .../fstests/tftpfs/tftpfs_udp_network_fake.c  |  983 +++
 .../fstests/tftpfs/tftpfs_udp_network_fake.h  |  283 +
 7 files changed, 3536 insertions(+)
 create mode 100644 spec/build/testsuites/fstests/tftpfs.yml
 create mode 100644 testsuites/fstests/tftpfs/init.c
 create mode 100644 testsuites/fstests/tftpfs/tftpfs_interactions.c
 create mode 100644 testsuites/fstests/tftpfs/tftpfs_interactions.h
 create mode 100644 testsuites/fstests/tftpfs/tftpfs_udp_network_fake.c
 create mode 100644 testsuites/fstests/tftpfs/tftpfs_udp_network_fake.h

diff --git a/spec/build/testsuites/fstests/grp.yml 
b/spec/build/testsuites/fstests/grp.yml
index 378157d3dc..ed8917504a 100644
--- a/spec/build/testsuites/fstests/grp.yml
+++ b/spec/build/testsuites/fstests/grp.yml
@@ -138,6 +138,8 @@ links:
   uid: mrfsfssymlink
 - role: build-dependency
   uid: mrfsfstime
+- role: build-dependency
+  uid: tftpfs
 type: build
 use-after: []
 use-before:
diff --git a/spec/build/testsuites/fstests/tftpfs.yml 
b/spec/build/testsuites/fstests/tftpfs.yml
new file mode 100644
index 00..37d55d4132
--- /dev/null
+++ b/spec/build/testsuites/fstests/tftpfs.yml
@@ -0,0 +1,25 @@
+SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
+build-type: test-program
+cflags: []
+copyrights:
+- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+cppflags: []
+cxxflags: []
+enabled-by: true
+features: c cprogram
+includes:
+- cpukit/libfs/src/ftpfs
+ldflags:
+- -Wl,--wrap=close
+links: []
+source:
+- cpukit/libtest/testwrappers.c
+- testsuites/fstests/tftpfs/init.c
+- testsuites/fstests/tftpfs/tftpfs_udp_network_fake.c
+- testsuites/fstests/tftpfs/tftpfs_interactions.c
+stlib:
+- tftpfs
+target: testsuites/fstests/tftpfs.exe
+type: build
+use-after: []
+use-before: []
diff --git a/testsuites/fstests/tftpfs/init.c b/testsuites/fstests/tftpfs/init.c
new file mode 100644
index 00..91308ec75b
--- /dev/null
+++ b/testsuites/fstests/tftpfs/init.c
@@ -0,0 +1,1054 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup RTEMSTestSuiteTestsTftpfs
+ *
+ * @brief This source file contains the implementation of tests for libtftpfs.
+ *
+ * The tested source files are:
+ *   + @ref tftpfs.c "tftpfs.c: TFTP file system"
+ *   + @ref tftpDriver.c "tftpDriver.c: TFTP client library"
+ * These tests focus on testing the UDP network interaction of libtftpfs.
+ */
+
+/*
+ * 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.
+ */
+
+/**
+ * @defgroup RTEMSTestSuiteTestsTftpfs Test suite for libtftpsfs tests
+ *
+ * @ingroup RTEMSTestSuites
+ *
+ * @brief This test suite provides a tests for libtftpfs.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include  /* malloc(), free() */
+#include  /* isprint() */
+#include 
+#include  /* mkdir(), open() */
+#include  /* mkdir(), open() */
+#include  /* AF_INET, SOCK_DGRAM */
+#include  /* open() */
+#include  /* read(), close(), rmdir() */
+
+#include 
+#include  /* mount(), RTEMS_FILESYSTEM_TYPE_TFTPFS */
+#include 
+#include 
+#include  /* RTEMS_TEST_VERBOSITY */
+#include 
+
+#include "tftpfs_udp_network_fake.h"
+#include "tftpfs_interactions.h"
+#include "tftp_driver.h"
+
+#define SERV_PORT 12345
+#define FIRST_TIMEOUT_MILLISECONDS  400
+#define TIMEOUT_MILLISECONDS1000
+#define 

[PATCH 7/7] TFTPFS: Add more tests

2022-06-03 Thread Frank Kuehndel
From: Frank Kühndel 

---
 testsuites/fstests/tftpfs/init.c | 3397 ++
 1 file changed, 3397 insertions(+)

diff --git a/testsuites/fstests/tftpfs/init.c b/testsuites/fstests/tftpfs/init.c
index a7ef03cf74..0c6df5fa5c 100644
--- a/testsuites/fstests/tftpfs/init.c
+++ b/testsuites/fstests/tftpfs/init.c
@@ -171,6 +171,47 @@ static const T_fixture fixture_default_options = {
   .initial_context = _context
 };
 
+static void setup_large_blocksize( void *context )
+{
+  tftp_test_context *ctx = context;
+  _Tftp_Reset();
+  ctx->fd0 = -1;
+  ctx->tftp_handle = NULL;
+  mount_tftp_fs(
+tftpfs_mount_point,
+"verbose,blocksize=" RTEMS_XSTRING(LARGE_BLOCK_SIZE) ",windowsize=1"
+  );
+}
+
+static const T_fixture fixture_large_blocksize = {
+  .setup = setup_large_blocksize,
+  .stop = NULL,
+  .teardown = teardown,
+  .scope = NULL,
+  .initial_context = _context
+};
+
+static void setup_small_opt_size( void *context )
+{
+  tftp_test_context *ctx = context;
+  _Tftp_Reset();
+  ctx->fd0 = -1;
+  ctx->tftp_handle = NULL;
+  mount_tftp_fs(
+tftpfs_mount_point,
+"blocksize=" RTEMS_XSTRING(SMALL_BLOCK_SIZE)
+",windowsize=" RTEMS_XSTRING(SMALL_WINDOW_SIZE)
+  );
+}
+
+static const T_fixture fixture_small_opt_size = {
+  .setup = setup_small_opt_size,
+  .stop = NULL,
+  .teardown = teardown,
+  .scope = NULL,
+  .initial_context = _context
+};
+
 static void setup_mount_point( void *context )
 {
   int result;
@@ -240,6 +281,15 @@ static uint8_t get_file_content( size_t pos )
   }
 }
 
+/*
+ * Produce bad file content.
+ */
+static uint8_t get_bad_file_content( size_t pos )
+{
+  static const char buf[] = "BAD!";
+  return (uint8_t) buf[ pos % strlen( buf ) ];
+}
+
 static const char *create_tftpfs_path(
   const char *sever_addr,
   const char *file_name
@@ -3836,6 +3886,3353 @@ T_TEST_CASE_FIXTURE( write_simple_file, 
_rfc1350 )
 }
 #endif /* ENABLE_ALL_TESTS */
 
+#if ENABLE_ALL_TESTS
+/*
+ * Write a file to the server using only RFC1350.
+ * As response to the first DATA packet, the server sends an error packet.
+ * Tests:
+ *   * The code supports requests without options (RFC1350 only).
+ *   * The code supports the use of an IPv4 address instead of a server name.
+ *   * The first packet is sent to standard port 69 of server.
+ *   * All other packets are sent to the port used for this connection.
+ *   * The first data packet is full.
+ *   * The second packet from the server is an error packet.
+ *   * The TFTP client ends the connection after receiving an error packet.
+ *   * The test writes a file to the file system with a call to write()
+ * for each byte.
+ */
+T_TEST_CASE_FIXTURE( write_simple_file_disk_full, _rfc1350 )
+{
+  tftp_test_context *ctx = T_fixture_context();
+  int bytes_written;
+  uint16_t block_num = 0;
+  size_t pos_in_file = 0;
+
+  /* T_set_verbosity( T_VERBOSE ); */
+  _Tftp_Add_interaction_socket( AF_INET, SOCK_DGRAM, 0, TFTP_FIRST_FD );
+#ifdef RTEMS_NETWORKING
+  _Tftp_Add_interaction_bind( TFTP_FIRST_FD, AF_INET, 0 );
+#endif
+  _Tftp_Add_interaction_send_wrq(
+TFTP_FIRST_FD,
+tftpfs_file,
+TFTP_STD_PORT,
+tftpfs_ipv4_loopback,
+NO_BLOCK_SIZE_OPTION,
+NO_WINDOW_SIZE_OPTION,
+true
+  );
+  _Tftp_Add_interaction_recv_ack(
+TFTP_FIRST_FD,
+FIRST_TIMEOUT_MILLISECONDS,
+SERV_PORT,
+tftpfs_ipv4_loopback,
+block_num++,
+true
+  );
+  _Tftp_Add_interaction_send_data(
+TFTP_FIRST_FD,
+block_num,
+pos_in_file,
+TFTP_RFC1350_BLOCK_SIZE,
+get_file_content,
+SERV_PORT,
+tftpfs_ipv4_loopback,
+true
+  );
+  pos_in_file += TFTP_RFC1350_BLOCK_SIZE;
+  _Tftp_Add_interaction_recv_error(
+TFTP_FIRST_FD,
+FIRST_TIMEOUT_MILLISECONDS,
+SERV_PORT,
+tftpfs_ipv4_loopback,
+TFTP_ERROR_CODE_DISK_FULL,
+"disk full",
+true
+  );
+  _Tftp_Add_interaction_close( TFTP_FIRST_FD, 0 );
+
+  bytes_written = write_tftp_file(
+create_tftpfs_path( tftpfs_ipv4_loopback, tftpfs_file ),
+pos_in_file, /* Size of file */
+1, /* Bytes written per call to write() */
+>fd0
+  );
+  T_eq_int( errno, ENOSPC );
+  T_eq_int( bytes_written, pos_in_file - 1 );
+  T_no_more_interactions();
+}
+#endif /* ENABLE_ALL_TESTS */
+
+#if ENABLE_ALL_TESTS
+/*
+ * Write a file to the server using only RFC1350.
+ * The file is one and a half data packet long.
+ * The server sends a malformed packet.
+ * Tests:
+ *   * The code supports requests without options (RFC1350 only).
+ *   * The code supports the use of an IPv4 address instead of a server name.
+ *   * The first packet is sent to standard port 69 of server.
+ *   * All other packets are sent to the port used for this connection.
+ *   * The first ACK to the WRQ packet is malformed.
+ * It is only one byte long.
+ *   * The client sends an error upon the reception of a malformed packet
+ * and terminates the file transfer.
+ */
+T_TEST_CASE_FIXTURE( write_file_malformed_ack_1, _rfc1350 )
+{
+  

[PATCH 3/7] TFTPFS: Restore tftpDriver.c

2022-06-03 Thread Frank Kuehndel
From: Frank Kühndel 

---
 cpukit/libfs/src/ftpfs/tftpDriver.c | 1088 +++
 1 file changed, 1088 insertions(+)
 create mode 100644 cpukit/libfs/src/ftpfs/tftpDriver.c

diff --git a/cpukit/libfs/src/ftpfs/tftpDriver.c 
b/cpukit/libfs/src/ftpfs/tftpDriver.c
new file mode 100644
index 00..d0eadcf99a
--- /dev/null
+++ b/cpukit/libfs/src/ftpfs/tftpDriver.c
@@ -0,0 +1,1088 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * Trivial File Transfer Protocol file system (TFTP client) for RFC 1350.
+ *
+ * Transfer file to/from remote host
+ */
+
+/*
+ * Copyright (c) 1998 Eric Norum 
+ *
+ * Modifications to support reference counting in the file system are
+ * Copyright (c) 2012 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef RTEMS_NETWORKING
+#include 
+#endif
+
+#ifdef RTEMS_TFTP_DRIVER_DEBUG
+int rtems_tftp_driver_debug = 1;
+#endif
+
+/*
+ * Range of UDP ports to try
+ */
+#define UDP_PORT_BASE3180
+
+/*
+ * Default limits
+ */
+#define PACKET_FIRST_TIMEOUT_MILLISECONDS  400L
+#define PACKET_TIMEOUT_MILLISECONDS6000L
+#define OPEN_RETRY_LIMIT   10
+#define IO_RETRY_LIMIT 10
+
+/*
+ * TFTP opcodes
+ */
+#define TFTP_OPCODE_RRQ 1
+#define TFTP_OPCODE_WRQ 2
+#define TFTP_OPCODE_DATA3
+#define TFTP_OPCODE_ACK 4
+#define TFTP_OPCODE_ERROR   5
+
+/*
+ * Largest data transfer
+ */
+#define TFTP_BUFSIZE512
+
+/*
+ * Packets transferred between machines
+ */
+union tftpPacket {
+/*
+ * RRQ/WRQ packet
+ */
+struct tftpRWRQ {
+uint16_t  opcode;
+charfilename_mode[TFTP_BUFSIZE];
+} tftpRWRQ;
+
+/*
+ * DATA packet
+ */
+struct tftpDATA {
+uint16_t  opcode;
+uint16_t  blocknum;
+uint8_t   data[TFTP_BUFSIZE];
+} tftpDATA;
+
+/*
+ * ACK packet
+ */
+struct tftpACK {
+uint16_t  opcode;
+uint16_t  blocknum;
+} tftpACK;
+
+/*
+ * ERROR packet
+ */
+struct tftpERROR {
+uint16_t  opcode;
+uint16_t  errorCode;
+charerrorMessage[TFTP_BUFSIZE];
+} tftpERROR;
+};
+
+/*
+ * State of each TFTP stream
+ */
+struct tftpStream {
+/*
+ * Buffer for storing most recently-received packet
+ */
+union tftpPacketpkbuf;
+
+/*
+ * Last block number transferred
+ */
+uint16_t  blocknum;
+
+/*
+ * Data transfer socket
+ */
+int socket;
+struct sockaddr_in  myAddress;
+struct sockaddr_in  farAddress;
+
+/*
+ * Indices into buffer
+ */
+int nleft;
+int nused;
+
+/*
+ * Flags
+ */
+int firstReply;
+int eof;
+int writing;
+};
+
+/*
+ * Flags for filesystem info.
+ */
+#define TFTPFS_VERBOSE (1 << 0)
+
+/*
+ * TFTP File system info.
+ */
+typedef struct tftpfs_info_s {
+  uint32_t flags;
+  rtems_mutex tftp_mutex;
+  int nStreams;
+  struct tftpStream ** volatile tftpStreams;
+} tftpfs_info_t;
+
+#define tftpfs_info_mount_table(_mt) ((tftpfs_info_t*) ((_mt)->fs_info))
+#define tftpfs_info_pathloc(_pl) ((tftpfs_info_t*) 
((_pl)->mt_entry->fs_info))
+#define tftpfs_info_iop(_iop)(tftpfs_info_pathloc 
(&((_iop)->pathinfo)))
+
+/*
+ * Number of streams open at the same time
+ */
+
+static const rtems_filesystem_operations_table  

[PATCH 0/7] TFTPFS: Add block and window size options

2022-06-03 Thread Frank Kuehndel
From: Frank Kühndel 

The following patches extend the TFTP file system to support

  * RFC 2347 TFTP Option Extension
  * RFC 2348 TFTP Blocksize Option
  * RFC 7440 TFTP Windowsize Option

To benefit from improved download and upload speeds, a TFTP
server which supports at least the blocksize option must be used.
The code is still downward compatible to simple/old servers
which implement only RFC 1350.

The patches contain an extensive test suite.

The original code was in the single file tftpDriver.c where
the file system and the network aspects where entangled.
The patches split the code into files tftpfs.c for the file
system part and tftpDriver.c for the network related part.

Since both files are derived from the original tftpDriver.c,
it is possible to keep the git history working for both files
when committing the patches to the git repository.  For example,
as described here:

https://devblogs.microsoft.com/oldnewthing/20190919-00/?p=102904

Yet, this method requires a merge and the history gets lost
when the commits are "rebased".  I cannot say whether this
would be worth the trouble.

TFTP Files
--

``cpukit/include/rtems/tftp.h``
  This file declares the public constants, structures, and functions
  of the Trivial File Transfer Protocol (TFTP) file system.

``cpukit/libfs/src/ftpfs/tftpDriver.c``
  This source file contains the implementation of a Trivial File
  Transfer Protocol (TFTP) client library --- the network related
  part of the code.

``cpukit/libfs/src/ftpfs/tftp_driver.h``
  This file declares private functions of the Trivial File Transfer
  Protocol (TFTP) client library.

``cpukit/libfs/src/ftpfs/tftpfs.c``
  This source file contains the implementation of the Trivial File
  Transfer Protocol (TFTP) filesystem.  The code in this file handles
  the file system operations (such as ``mount()``, ``open()``,
  ``read()``, ``write()``, ``close()`` etc.).

``spec/build/cpukit/libtftpfs.yml``
  This file specifies how the RTEMS WAF build system has to compile,
  link and install ``libtftpfs``.

``spec/build/testsuites/fstests/grp.yml``
  This file specifies how the RTEMS WAF build system has to compile,
  link and install all filesystem test suites.  The TFTP test suite
  must be mentioned in this file to be build.

``spec/build/testsuites/fstests/tftpfs.yml``
  This file specifies how the RTEMS WAF build system has to compile,
  link and install the TFTP test suite.

``testsuites/fstests/tftpfs/init.c``
  This source file contains the test suite with all tests for
  ``libtftpfs``. The test suite uses functions from files
  ``tftpfs_interactions.c`` and ``tftpfs_udp_network_fake.c`` as
  private helpers.

``testsuites/fstests/tftpfs/tftpfs_interactions.h``
  This header file provides definitions and declarations of data
  structures and functions used to implement network interactions
  of the UDP network fake for ``libtftpfs`` tests.

``testsuites/fstests/tftpfs/tftpfs_interactions.c``
  This source file contains the implementation of network interaction
  functions related to the UDP network fake for ``libtftpfs`` tests.

``testsuites/fstests/tftpfs/tftpfs_udp_network_fake.h``
  This header file provides definitions and declarations of data
  structures and functions used to implement the UDP network fake
  for ``libtftpfs`` tests.

``testsuites/fstests/tftpfs/tftpfs_udp_network_fake.c``
  This source file contains the implementation of UDP network fake
  functions related to ``libtftpfs`` testing.  This code provides
  fake implementations for functions like ``socket()``, ``bind()``,
  ``sendto()``, ``recvfrom()``, etc. which would normally be
  provided by libbsd.

Frank Kühndel (7):
  TFTPFS: Cleanup: Remove spaces at lines ends
  TFTPFS: Duplicate tftpDriver.c to tftpfs.c
  TFTPFS: Restore tftpDriver.c
  TFTPFS: Implement block and window size options
  TFTPFS: Add test suite framework
  TFTPFS: Add tests
  TFTPFS: Add more tests

 cpukit/include/rtems/tftp.h   |  404 +-
 cpukit/libfs/src/ftpfs/tftpDriver.c   | 1780 ++--
 cpukit/libfs/src/ftpfs/tftp_driver.h  |   76 +
 cpukit/libfs/src/ftpfs/tftpfs.c   |  624 ++
 spec/build/cpukit/libtftpfs.yml   |3 +-
 spec/build/testsuites/fstests/grp.yml |2 +
 spec/build/testsuites/fstests/tftpfs.yml  |   25 +
 testsuites/fstests/tftpfs/init.c  | 7318 +
 .../fstests/tftpfs/tftpfs_interactions.c  |  984 +++
 .../fstests/tftpfs/tftpfs_interactions.h  |  205 +
 .../fstests/tftpfs/tftpfs_udp_network_fake.c  |  983 +++
 .../fstests/tftpfs/tftpfs_udp_network_fake.h  |  283 +
 12 files changed, 12024 insertions(+), 663 deletions(-)
 create mode 100644 cpukit/libfs/src/ftpfs/tftp_driver.h
 create mode 100644 cpukit/libfs/src/ftpfs/tftpfs.c
 create mode 100644 spec/build/testsuites/fstests/tftpfs.yml
 create mode 100644 testsuites/fstests/tftpfs/init.c
 create mode 100644 testsuites/fstests/tftpfs/tftpfs_interactions.c
 create mode 

[PATCH 2/7] TFTPFS: Duplicate tftpDriver.c to tftpfs.c

2022-06-03 Thread Frank Kuehndel
From: Frank Kühndel 

---
 cpukit/libfs/src/ftpfs/{tftpDriver.c => tftpfs.c} | 0
 spec/build/cpukit/libtftpfs.yml   | 4 ++--
 2 files changed, 2 insertions(+), 2 deletions(-)
 rename cpukit/libfs/src/ftpfs/{tftpDriver.c => tftpfs.c} (100%)

diff --git a/cpukit/libfs/src/ftpfs/tftpDriver.c 
b/cpukit/libfs/src/ftpfs/tftpfs.c
similarity index 100%
rename from cpukit/libfs/src/ftpfs/tftpDriver.c
rename to cpukit/libfs/src/ftpfs/tftpfs.c
diff --git a/spec/build/cpukit/libtftpfs.yml b/spec/build/cpukit/libtftpfs.yml
index 90a0eabc80..f63a50c933 100644
--- a/spec/build/cpukit/libtftpfs.yml
+++ b/spec/build/cpukit/libtftpfs.yml
@@ -2,7 +2,7 @@ SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
 build-type: library
 cflags: []
 copyrights:
-- Copyright (C) 2020 embedded brains GmbH (http://www.embedded-brains.de)
+- Copyright (C) 2020, 2022 embedded brains GmbH (http://www.embedded-brains.de)
 cppflags: []
 cxxflags: []
 enabled-by: true
@@ -15,6 +15,6 @@ install:
 install-path: ${BSP_LIBDIR}
 links: []
 source:
-- cpukit/libfs/src/ftpfs/tftpDriver.c
+- cpukit/libfs/src/ftpfs/tftpfs.c
 target: tftpfs
 type: build
-- 
2.35.3

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

[PATCH 1/7] TFTPFS: Cleanup: Remove spaces at lines ends

2022-06-03 Thread Frank Kuehndel
From: Frank Kühndel 

---
 cpukit/libfs/src/ftpfs/tftpDriver.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/cpukit/libfs/src/ftpfs/tftpDriver.c 
b/cpukit/libfs/src/ftpfs/tftpDriver.c
index bebe748ca5..d0eadcf99a 100644
--- a/cpukit/libfs/src/ftpfs/tftpDriver.c
+++ b/cpukit/libfs/src/ftpfs/tftpDriver.c
@@ -233,12 +233,12 @@ int rtems_tftpfs_initialize(
   fs->flags = 0;
   fs->nStreams = 0;
   fs->tftpStreams = 0;
-  
+
   mt_entry->fs_info = fs;
   mt_entry->mt_fs_root->location.node_access = root_path;
   mt_entry->mt_fs_root->location.handlers = _tftp_handlers;
   mt_entry->ops = _tftp_ops;
-  
+
   /*
*  Now allocate a semaphore for mutual exclusion.
*
@@ -258,7 +258,7 @@ int rtems_tftpfs_initialize(
   token = strtok_r (NULL, " ", );
   }
   }
-  
+
   return 0;
 
 error:
@@ -563,7 +563,7 @@ static int rtems_tftp_open_worker(
  * Get the file system info.
  */
 fs = tftpfs_info_iop (iop);
-
+
 /*
  * Extract the host name component
  */
@@ -595,7 +595,7 @@ static int rtems_tftp_open_worker(
 return ENOENT;
 memcpy (, he->h_addr, sizeof (farAddress));
 }
-
+
 /*
  * Extract file pathname component
  */
@@ -803,7 +803,7 @@ static ssize_t rtems_tftp_read(
 
 if (!tp)
 rtems_set_errno_and_return_minus_one( EIO );
-
+
 /*
  * Read till user request is satisfied or EOF is reached
  */
@@ -918,15 +918,15 @@ static int rtems_tftp_close(
 tftpfs_info_t *fs;
 struct tftpStream *tp = iop->data1;
 inte = 0;
-
+
 /*
  * Get the file system info.
  */
 fs = tftpfs_info_iop (iop);
-
-if (!tp) 
+
+if (!tp)
 rtems_set_errno_and_return_minus_one (EIO);
-
+
 if (tp->writing)
 e = rtems_tftp_flush (tp);
 if (!tp->eof && !tp->firstReply) {
-- 
2.35.3

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

[PATCH rtems-docs 1/1] TFTPFS: New documentation

2022-06-03 Thread Frank Kuehndel
From: Frank Kühndel 

---
 filesystem/index.rst   |   1 +
 filesystem/trivial_ftp.rst | 638 -
 2 files changed, 636 insertions(+), 3 deletions(-)

diff --git a/filesystem/index.rst b/filesystem/index.rst
index f4e2ed6..64a2f1d 100644
--- a/filesystem/index.rst
+++ b/filesystem/index.rst
@@ -9,6 +9,7 @@ RTEMS Filesystem Design Guide (|version|).
 .. topic:: Copyrights and License
 
 | |copy| 1988, 2015 On-Line Applications Research Corporation (OAR)
+| |copy| 2022 embedded brains GmbH (http://www.embedded-brains.de)
 
 .. include:: ../common/license.rst
 
diff --git a/filesystem/trivial_ftp.rst b/filesystem/trivial_ftp.rst
index e43c036..f5940c6 100644
--- a/filesystem/trivial_ftp.rst
+++ b/filesystem/trivial_ftp.rst
@@ -3,7 +3,639 @@
 Trivial FTP Client Filesystem
 *
 
-This chapter describes the Trivial FTP (TFTP) Client Filesystem.
+This chapter describes the Trivial File Transfer Protocol (TFTP) Client
+Filesystem.  TFTP is designed to be an especially simple protocol which
+uses the User Datagram Protocol (UDP) for data transfer over the Internet.
+Its purpose is to send a single file between to network nodes (client and
+server).  A file can be sent in both directions, i.e. a client can either
+read a file from a server or write a file to the server.
 
-This chapter should be written after the IMFS chapter is completed and describe
-the implementation of the TFTP.
+Besides reading or writing a file no other operations are supported.  That
+is, one cannot seek the file, not append to the end of a file, not open
+the file for reading and writing at the same time, not list directories,
+not move files and so on.
+
+TFTP is inherent insecure as it does not provide any means for
+authentication or encryption.  Therefore, it cannot be used over the public
+Internet.  Nevertheless, it is still widely used to load software and
+configuration data during early boot stages over a Local Area Network
+(LAN).
+
+RTEMS TFTP Filesystem Implementation
+
+
+The RTEMS TFTP filesystem implements a TFTP client which can be used
+through the file system.  With other words, one needs to mount the
+TFTP filesystem and can afterwards open a file for reading or writing
+below that mount point.  The content of that file is then effectively
+read from or written to the remote server.  The RTEMS implementation
+implements the following features:
+
+* RFC 1350 *The TFTP Protocol (Revision 2)*
+* RFC 2347 *TFTP Option Extension*
+* RFC 2348 *TFTP Blocksize Option*
+* RFC 7440 *TFTP Windowsize Option*
+
+Many simple TFTP server do not support options (RFC 2347). Therefore, in
+case the server rejects the first request with options, the RTEMS client
+makes automatically a second attempt using only the "classical" RFC 1350.
+
+The implementation has the following shortcomings:
+
+* IPv6 is not supported (yet).
+
+* No congestion control is implemented.
+
+  (Congestion is simply expressed a network traffic jam which involves
+  package loss.)  This implementation would worsen a congestion situation
+  and squeeze out TCP connections.  If that is a concern in your setup,
+  it can be prevented by using value `1` as `windowsize`.
+
+* One must call ``open()``, ``read()``, ``write()`` and ``close()``
+  at a good pace.
+
+  TFTP uses timeouts (of unspecified length).  It does not know keep-alive
+  messages.  If the client does not respond to the server in due time,
+  the server sets the connection faulty and drops it.  To avoid this,
+  the user must read or write enough data fast enough.
+
+  "Enough data" means at least so much data which fills a single data
+  package or all packages of a window if windows are used.  The data
+  can be read or written in anything from one single large chunk to
+  byte-by-byte pieces.  The point is, one cannot pause the reading
+  or writing for longer periods of time.
+
+* The transfer mode is always ``octet``.  The only alternative
+  ``netascii`` cannot be selected.
+
+* Block number roll-over is currently not supported.  Therefore,
+  the maximum file size is limited to max-block-number times blocksize.
+  For RFC 1350 blocksize is would be 65535 * 512 = 32 MB.  For the
+  default blocksize is would be 65535 * 1456 = 90 MB.
+
+* The inherent insecurity of the protocol has already be mentioned but
+  it is worth repeating.
+
+Prerequisites
+=
+
+To use the RTEMS TFTP filesystem one needs:
+
+* The RTEMS tools (cross-compiler, linker, debugger etc.) compiled
+  for the target architecture and installed at a prefix
+* The RTEMS Board Support Package (BSP) compiled for the
+  target board and installed at the same prefix
+* The RTEMS libbsd compiled to match the BSP and installed at the same
+  prefix
+
+Note, this text does not cover RTEMS legacy networking because it is
+outdated.
+
+As an example the ARM architecture and a xilinx_zynq_a9 BSP is used below.
+The 

[PATCH rtems-docs 0/1] TFTPFS: Add block and window size options

2022-06-03 Thread Frank Kuehndel
From: Frank Kühndel 

Hello all,

I extended the TFTP file system to support the block size and the
window size options (RFCs 2347, 2348, 7440).  Essentially, this
significantly improves the download and upload speeds provided the
TFTP server on the other side also supports at least one of these
options.

To implement it I had to substantially change the network related
part of the code.  I also created a test suite for the TFTP code.
Indeed the test suite is by far the largest part.  Moreover, I wrote
a documentation.

This patch set provides the new documentation.  It replaces the
already existing but basically empty chapter "Trivial FTP Client
Filesystem" in the "RTEMS Filesystem Design Guide".  There are also
two image files - an .svg and an .png - which are used in the text.
These are not in this patch set as I believe no one will review SVG
code or binary PNG.  Instead I put the generated PDF (including the
diagram) for download at the link shown below.  I hope the PDF is
more convenient to read than the patch itself.  

https://share.embedded-brains.de/index.php/s/6MkMHkyRLKR2XBp/download/filesystem.pdf

Please, remind that only chapter "Trivial FTP Client Filesystem" in
this PDF is new.

There is one issue with the copyright which is not clear to me.  I
adapted the copyright notice in filesystem/index.rst.  This copyright
notice appears in a box just before chapter "PREFACE".  Yet, there
is a second different copyright notice "1988, 2020 RTEMS Project and
contributors" which appears at the first page of the PDF and at the
bottom of each HTML page.  I do not want to complain about this.  I
just found it a bit inconsistent.

Next I will send the changed code as an own patch set to the mailing
list.

Thanks in advance for your review efforts, any questions and comments.
Note, due to a bank holiday I will response to your emails no earlier
than Tuesday.

Greetings
Frank


Frank Kühndel (1):
  TFTPFS: New documentation

 filesystem/index.rst   |   1 +
 filesystem/trivial_ftp.rst | 638 -
 2 files changed, 636 insertions(+), 3 deletions(-)

-- 
2.35.3

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

[PATCH] RSB: Remove option --with-java

2022-05-06 Thread Frank Kuehndel
From: Frank Kühndel 

The sb-set-builder options --with-java / --without-java do not work.
GCC configure does not known language "java". See
https://gcc.gnu.org/install/configure.html option --enable-languages.

update #4647
---
 source-builder/config/checks.cfg   | 9 -
 source-builder/config/gcc-common-1.cfg | 3 ---
 2 files changed, 12 deletions(-)

diff --git a/source-builder/config/checks.cfg b/source-builder/config/checks.cfg
index 93d4c97..b374d2c 100644
--- a/source-builder/config/checks.cfg
+++ b/source-builder/config/checks.cfg
@@ -19,8 +19,6 @@
 %{?without_ada:%define enable_ada 0}
 %{?with_fortran:%define enable_fortran 1}
 %{?without_fortran:%define enable_fortran 0}
-%{?with_java:%define enable_java 1}
-%{?without_java:%define enable_java 0}
 %{?with_objc:%define enable_objc 1}
 %{?without_objc:%define enable_objc 0}
 
@@ -52,13 +50,6 @@
  %define enable_fortran 0
 %endif
 
-#
-# Default to Java off.
-#
-%ifn %{defined enable_java}
- %define enable_java 0
-%endif
-
 #
 # Default to ObjC off.
 #
diff --git a/source-builder/config/gcc-common-1.cfg 
b/source-builder/config/gcc-common-1.cfg
index 05e0e3c..9723946 100644
--- a/source-builder/config/gcc-common-1.cfg
+++ b/source-builder/config/gcc-common-1.cfg
@@ -165,9 +165,6 @@ URL:   http://gcc.gnu.org/
 %if %{enable_fortran}
   languages="$languages,fortran"
 %endif
-%if %{enable_java}
-  languages="$languages,java"
-%endif
 %if %{enable_objc}
   languages="$languages,objc"
 %endif
-- 
2.35.3

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

[PATCH 1/1] libbsd: Add TFTP filesystem to test media01

2022-04-08 Thread Frank Kuehndel
From: Frank Kühndel 

How test media01 can be executed is described in section
*Qemu and Networking* of the README.md at the top of the
rtems-libbsd GIT repository.

When connected via `telnet` with the RTEMS shell of the
media01.exe test executed by QEMU, one can list the filesystems
available for mounting:

TLNT [/] # mount -L
File systems: / dosfs tftpfs

The list will contain `tftpfs`.  The filesystem can be mounted
as in the following example:

TLNT [/] # mkdir /tftp
TLNT [/] # mount -t tftpfs -o verbose "" /tftp

A TFTP server is needed to use this filesystem.  The simplest way
would be to run such a server on the host machine and open the
firewall for the TFTP protocol (port 69) on the TAP device used.
Files can then be downloaded using the usual shell commands
as in the following example:

TLNT [/] # cat /tftp/169.254.1.1:hello.txt

Uploading is also possible provided the TFTP server supports it,
for example:

TLNT [/] # cp /etc/dhcpcd.duid /tftp/169.254.1.1:myfile
---
 libbsd.py | 2 +-
 testsuite/media01/test_main.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/libbsd.py b/libbsd.py
index 32cb741f..974934fb 100644
--- a/libbsd.py
+++ b/libbsd.py
@@ -5425,7 +5425,7 @@ class tests(builder.Module):
 self.addTest(mm.generator['test']('smp01', ['test_main'], extraLibs = 
['rtemstest']))
 self.addTest(mm.generator['test']('media01', ['test_main', 
'pattern-test'],
   runTest = False,
-  extraLibs = ['ftpd', 'telnetd']))
+  extraLibs = ['tftpfs', 'ftpd', 
'telnetd']))
 self.addTest(mm.generator['test']('mcast01', ['test_main']))
 self.addTest(mm.generator['test']('vlan01', ['test_main'], netTest = 
True))
 self.addTest(mm.generator['test']('lagg01', ['test_main'], netTest = 
True))
diff --git a/testsuite/media01/test_main.c b/testsuite/media01/test_main.c
index 2a1c9aae..001c80a8 100644
--- a/testsuite/media01/test_main.c
+++ b/testsuite/media01/test_main.c
@@ -201,6 +201,8 @@ early_initialization(void)
 
 #define CONFIGURE_FILESYSTEM_DOSFS
 
+#define CONFIGURE_FILESYSTEM_TFTPFS
+
 #define CONFIGURE_MAXIMUM_PROCESSORS 32
 
 #define CONFIGURE_RECORD_PER_PROCESSOR_ITEMS 4096
-- 
2.34.1

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

[PATCH 0/1] libbsd: Add TFTP filesystem to test media01

2022-04-08 Thread Frank Kuehndel
From: Frank Kühndel 

Hello,

I would like to ask the community whether it would be possible
to accept the little patch which follows?  The patch permits to
mount and use the TFTP filesystem through the RTEMS shell of test
media01.  It serves demonstration purposes and permits users
to try out TFTP without modifying any code before.

Greetings,

Frank Kühndel (1):
  libbsd: Add TFTP filesystem to test media01

 libbsd.py | 2 +-
 testsuite/media01/test_main.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

-- 
2.34.1

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

[PATCH v2] libtftpfs: Change to BSD-2-Clause license

2022-03-15 Thread Frank Kuehndel
From: Frank Kühndel 

Eric Norum's permission to change the license can be found here:
https://devel.rtems.org/attachment/ticket/3053/EricNorum-Permission.pdf

Update #3053
---
 cpukit/include/rtems/tftp.h | 72 +++--
 cpukit/libfs/src/ftpfs/tftpDriver.c | 44 ++
 2 files changed, 93 insertions(+), 23 deletions(-)

diff --git a/cpukit/include/rtems/tftp.h b/cpukit/include/rtems/tftp.h
index ed3ebd7865..2f36a39cd2 100644
--- a/cpukit/include/rtems/tftp.h
+++ b/cpukit/include/rtems/tftp.h
@@ -1,23 +1,69 @@
-/*
- * Trivial File Transfer Protocol (TFTP)
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
  *
- * Transfer file to/from remote host
+ * @ingroup RTEMSTFTPFS
  *
- * W. Eric Norum
- * Saskatchewan Accelerator Laboratory
- * University of Saskatchewan
- * Saskatoon, Saskatchewan, CANADA
- * e...@skatter.usask.ca
+ * @brief This header file provides interfaces and functions used to
+ *   implement the TFTP File System.
+ *
+ * This file declares the public functions of the Trivial File
+ * Transfer Protocol (TFTP) File System.
  */
 
 /*
- * Usage:
+ * Copyright (C) 1998 W. Eric Norum
+ *
+ * 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.
+ */
+
+/**
+ * @defgroup RTEMSTFTPFS Trivial File Transfer Protocol (TFTP) File System
+ *
+ * @ingroup FileSystemTypesAndMount
+ *
+ * @brief The TFTP File System provides the ability to read files from and
+ *   to write files to remote servers using the Trivial File Transfer
+ *   Protocol (TFTP).
+ *
+ * Usage
+ * =
+ *
+ * To open `/bootfiles/image` on `hostname` for reading:
+ *
+ * fd = open ("/TFTP/hostname:bootfiles/image", O_RDONLY);
+ *
+ * The `TFTP` is the mount path and the `hostname` must be
+ *
+ * + an IPv4 address (acceptable to `inet_aton()`) or
+ * + the (full-qualified) name of an IPv4 host (acceptable to
+ *  `gethostbyname()`)
  *
- * To open `/bootfiles/image' on `hostname' for reading:
- * fd = open ("/TFTP/hostname/bootfiles/image", O_RDONLY);
+ * IPv6 is currently not supported. `bootfiles/image` is a path on the
+ * TFTP server `hostname` where the file (here `image`) can be found.
  *
- * The 'TFTP' is the mount path and the `hostname' must be four dot-separated
- * decimal values.
+ * See also the _RTEMS Filesystem Design Guide_ Chapter [_Trivial FTP Client
+ * 
Filesystem_](https://docs.rtems.org/branches/master/filesystem/trivial_ftp.html).
  */
 
 #ifndef _RTEMS_TFTP_H
diff --git a/cpukit/libfs/src/ftpfs/tftpDriver.c 
b/cpukit/libfs/src/ftpfs/tftpDriver.c
index bc0e74ad86..f4fd93d535 100644
--- a/cpukit/libfs/src/ftpfs/tftpDriver.c
+++ b/cpukit/libfs/src/ftpfs/tftpDriver.c
@@ -1,17 +1,41 @@
-/*
- * Trivial File Transfer Protocol (RFC 1350)
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup RTEMSTFTPFS
  *
- * Transfer file to/from remote host
+ * @brief This source file contains the implementation of
+ * Trivial File Transfer Protocol (TFTP) File System.
  *
- * W. Eric Norum
- * Saskatchewan Accelerator Laboratory
- * University of Saskatchewan
- * Saskatoon, Saskatchewan, CANADA
- * e...@skatter.usask.ca
+ * The code in this file implements the Trivial File Transfer
+ * Protocol according to RFC 1350.
+ */
+
+/*
+ * Copyright (C) 1998 W. Eric Norum
+ * Copyright (C) 2012 embedded brains GmbH (http://www.embedded-brains.de)
  *
- * Modifications to support reference counting in the file system are
- * Copyright (c) 2012 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 

[PATCH 0/1] libtftpfs: Change to BSD-2-Clause license?

2022-03-15 Thread Frank Kuehndel
From: Frank Kühndel 

Hello,

I want to extend the code of `libtftpfs` to support newer RFCs to
increase the file download speed. This raises the question of the
license of the involved source files. The current state is that
the file headers are old. The code originates from W. Eric Norum.

Fortunately, I found in ticket #3053 a general permission of
Eric Norum to change the code to BSD-2. My question here is:

Shall I use the chance to modernize the headers of the libtftpfs
files as suggested in this patch or shall I keep the original file
headers intact?

Thanks and greetings
Frank

Frank Kühndel (1):
  libtftpfs: Change to BSD-2-Clause license

 cpukit/include/rtems/tftp.h | 72 +++--
 cpukit/libfs/src/ftpfs/tftpDriver.c | 44 ++
 2 files changed, 93 insertions(+), 23 deletions(-)

-- 
2.34.1

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

[PATCH] clock:_TOD_To_seconds(): Fix year 2514 overflow

2021-04-08 Thread Frank Kuehndel
From: Frank Kühndel 

This patch fixes issue #4338 by changing _TOD_Validate()
to only accept years till 2105. This requires another patch
to change the documentation of rtems_clock_set() and other
affected API functions (indicating the end date is 2105 not 2514).

I tried to support till year 2514 but it turned out that
this needs changing the Timer Manager too. That in turn
would mean to change _TOD_Seconds_since_epoch( void )
from 32 to 64 bit. Sebastian pointed out that a naive extension
leads to trouble with 32 bit processors. He deemed a safe
re-implementation too costly performance wise considering
that year 2106 is far away and current binaries using RTEMS
Classic API are unlikely to be in use by 2106.

The constant TOD_SECONDS_AT_2100_03_01_00_00 in
cpukit/rtems/src/clocktodtoseconds.c happens to be wrong by
1 hour. When setting the date 2100-Feb-28 23:59:59 and then
reading the date again you will find yourself in 2100-Feb-27.

Original Bug #4338 Text:

== Short Problem Description ==

[https://docs.rtems.org/branches/master/c-user/clock/directives.html

> RTEMS can represent time points of this clock in nanoseconds
> ranging from 1988-01-01T00:00:00.0Z to
> 2514-05-31T01:53:03.9Z.

* Yet, years larger than roughly 2105 to 2110 cannot be set
  (or at least the date should be wrong but this never
  occured in my tests).

> The possible RETURN VALUES are RTEMS_SUCCESSFUL,
> RTEMS_INVALID_ADDRESS, RTEMS_INVALID_CLOCK

* Yet, rtems_clock_set() can return status RTEMS_INVALID_NUMBER,
  too. (Only for such dates in the far future.)

== How To Replicate? ==

Call rtems_clock_set() with this time_of-day:
{
  year = 2514,
  month = 5,
  day = 31,
  hour = 1,
  minute = 53,
  second = 3,
  ticks = 995
}
The return value will be RTEMS_INVALID_NUMBER.

== Bugs in _TOD_To_seconds() ==

cpukit/rtems/src/clockset.c: rtems_clock_set() calls

* cpukit/rtems/src/clocktodvalidate.c: _TOD_Validate() and
* cpukit/rtems/src/clocktodtoseconds.c: _TOD_To_seconds() and
* cpukit/score/src/coretodset.c: _TOD_Set()

First issue:

_TOD_To_seconds() converts the time_of_day structure into
seconds using a variable `time` of type `uint32_t`. This simply
overflows when in comes close to year 2110.

Debugger output at the end of _TOD_To_seconds():

(gdb) print the_tod->year
$16 = 2104
(gdb) print time
$17 = 4233686400

with a higher year:

(gdb) print the_tod->year
$28 = 2514
(gdb) print *the_tod
$31 = {
  year = 2514,
  month = 5,
  day = 31,
  hour = 1,
  minute = 53,
  second = 3,
  ticks = 995
}
(gdb) print time
$29 = 192272

Second issue:

_TOD_To_seconds() can (most likely) not handle the leap year
issues of the years 2200, 2300, 2400, 2500 because it has
dedicated code for the 2100 case only:

   /* The year 2100 is not a leap year */
   if ( time
   >= (TOD_SECONDS_AT_2100_03_01_00_00 -
  TOD_SECONDS_1970_THROUGH_1988)) {
 time -= TOD_SECONDS_PER_DAY;
   }

== _TOD_Check_time_of_day_and_run_hooks() causes STATUS_INVALID_NUMBER ==

cpukit/score/src/coretodset.c: _TOD_Set() calls

* cpukit/score/src/coretodset.c:
  _TOD_Check_time_of_day_and_run_hooks()

in this code snippet (note `return status`):

status = _TOD_Check_time_of_day_and_run_hooks( tod );
if ( status != STATUS_SUCCESSFUL ) {
  _TOD_Release( lock_context );
  return status;
}

_TOD_Check_time_of_day_and_run_hooks( tod ) can return status
STATUS_INVALID_NUMBER which is not documented for
rtems_clock_set(). The small time in seconds value 192272 from
the integer overrun discussed above triggers the middle `if`
clause:

static Status_Control _TOD_Check_time_of_day_and_run_hooks(
  const struct timespec *tod
)
{
  if ( !_Watchdog_Is_valid_timespec( tod ) ) {
return STATUS_INVALID_NUMBER;
  }

  if ( tod->tv_sec < TOD_SECONDS_1970_THROUGH_1988 ) {
return STATUS_INVALID_NUMBER;
  }

  if ( _Watchdog_Is_far_future_timespec( tod ) ) {
return STATUS_INVALID_NUMBER;
  }

  return _TOD_Hook_Run( TOD_ACTION_SET_CLOCK, tod );
}

== Final Notes ==

* I found #2665 and #2548 but I do not say these are relevant here.
* `#define WATCHDOG_MAX_SECONDS 0x3` in
  cpukit/include/rtems/score/watchdogimpl.h covers 17179869183
  seconds which are some 544 years
* _TOD_Check_time_of_day_and_run_hooks() seems to be only used by
  _TOD_Set() but _TOD_Set() has three users.
* I did not check whether the invers conversation
  (rtems_clock_get_tod())
  works for dates which are centuries in the future.

Update #4338
---
 cpukit/include/rtems/score/todimpl.h | 16 
 cpukit/rtems/src/clocktodtoseconds.c |  2 +-
 cpukit/rtems/src/clocktodvalidate.c  |  1 +
 testsuites/sptests/sp2038/init.c | 28 ++--
 4 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/cpukit/include/rtems/score/todimpl.h 
b/cpukit/include/rtems/score/todimpl.h
index 

[PATCH v2] eng: Requirements counting shall start at zero

2020-12-11 Thread Frank Kuehndel
From: Frank Kühndel 

---
 eng/req/req-for-req.rst | 21 +
 1 file changed, 21 insertions(+)

diff --git a/eng/req/req-for-req.rst b/eng/req/req-for-req.rst
index 9225e95..dcc4c11 100644
--- a/eng/req/req-for-req.rst
+++ b/eng/req/req-for-req.rst
@@ -308,6 +308,27 @@ spec:/classic/task/create-err-invname
 
 ...
 
+If requirements or the YAML files which contain them are to be numbered,
+the numbering shall start with 0. For example:
+
+.. code-block:: none
+
+weak-alias-0.yml
+weak-alias-1.yml
+
+Smaller numbers shall be prefixed with 0 to the same count of digits
+as the largest number. For example:
+
+.. code-block:: none
+
+alias-00.yml
+alias-01.yml
+alias-02.yml
+...
+alias-09.yml
+alias-10.yml
+alias-11.yml
+
 Conflict Free Requirements
 --
 
-- 
2.26.2

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

[PATCH] eng: Requirements counting shall start at zero

2020-12-09 Thread Frank Kuehndel
From: Frank Kühndel 

---
 eng/req/req-for-req.rst | 8 
 1 file changed, 8 insertions(+)

diff --git a/eng/req/req-for-req.rst b/eng/req/req-for-req.rst
index 9225e95..8345e35 100644
--- a/eng/req/req-for-req.rst
+++ b/eng/req/req-for-req.rst
@@ -308,6 +308,14 @@ spec:/classic/task/create-err-invname
 
 ...
 
+If requirements or the YAML files which contain them are to be numbered,
+the numbering shall start with 0. For example:
+
+.. code-block:: none
+
+weak-alias-0.yml
+weak-alias-1.yml
+
 Conflict Free Requirements
 --
 
-- 
2.26.2

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

[PATCH v2] rtems-fdt / shell - Fix string truncation warning

2020-10-19 Thread Frank Kuehndel
From: Frank Kühndel 

The compiler warning was:

../../../cpukit/libmisc/rtems-fdt/rtems-fdt.c:267:5: warning:
'strncpy' specified bound depends on the length of the source argument
  267 | strncpy(path, name, namelen);
  | ^~~~

It turns out that the `strncpy()` nor the buffer `path` is needed when
one uses `strncmp()` instead of `strcmp()`. This needs some change to
the algorithm but has the advantage that `name` is never truncated
to the size of the buffer `path`.
---
 cpukit/libmisc/rtems-fdt/rtems-fdt.c | 40 +---
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/cpukit/libmisc/rtems-fdt/rtems-fdt.c 
b/cpukit/libmisc/rtems-fdt/rtems-fdt.c
index 39e70bffec..0ea365314f 100644
--- a/cpukit/libmisc/rtems-fdt/rtems-fdt.c
+++ b/cpukit/libmisc/rtems-fdt/rtems-fdt.c
@@ -248,48 +248,46 @@ rtems_fdt_index_find_by_name(rtems_fdt_index* index,
 {
   int min = 0;
   int max = index->num_entries;
-  charpath[256];
-  const char* cmp_name = name;
-
   /*
* Handle trailing slash case.
*/
-  int namelen = strlen(name);
+  size_t namelen = strlen(name);
   if (namelen > 0 && name[namelen-1] == '/')
   {
 namelen--;
-
-if (namelen >= (int)sizeof(path) - 1)
-{
-  namelen = sizeof(path) - 1;
-}
-
-strncpy(path, name, namelen);
-path[namelen] = 0;
-cmp_name = path;
   }
 
   /* Binary search for the name. */
   while (min < max)
   {
 int middle = (min + max) / 2;
-int cmp = strcmp(cmp_name, index->entries[middle].name);
+int cmp = strncmp(name, index->entries[middle].name, namelen);
+if (cmp == 0)
+{
+  /* 'namelen' characters are equal but 'index->entries[middle].name' */
+  /* could have additional characters. */
+  if (index->entries[middle].name[namelen] == '\0')
+  {
+/* Found it. */
+return index->entries[middle].offset;
+  }
+  else
+  {
+ /* 'index->entries[middle].name' is longer than 'name'. */
+ cmp = -1;
+  }
+}
 if (cmp < 0)
 {
   /* Look lower than here. */
   max = middle;
 }
-else if (cmp > 0)
+else
 {
   /* Look higher than here. */
   min = middle + 1;
 }
-else
-{
-  /* Found it. */
-  return index->entries[middle].offset;
-}
-  }
+ }
 
   /* Didn't find it. */
   return -FDT_ERR_NOTFOUND;
-- 
2.26.2

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

[PATCH] rtems-fdt / shell - Fix string truncation warning

2020-10-15 Thread Frank Kuehndel
From: Frank Kühndel 

The compiler warning was:

../../../cpukit/libmisc/rtems-fdt/rtems-fdt.c:267:5: warning:
'strncpy' specified bound depends on the length of the source argument
  267 | strncpy(path, name, namelen);
  | ^~~~

It turns out that the `strncpy()` nor the buffer `path` is needed when
one uses `strncmp()` instead of `strcmp()`. This needs some change to
the algorithm but has the advantage that `name` is never truncated
to the size of the buffer `path`.

Note:

rtems-fdt.c, rtems-fdt-shell.c and cpukit/include/rtems/rtems-fdt.h
seem to be dead code. They implement a shell command `fdt` but that
command is not part of the shell nor of any macro in
cpukit/include/rtems/shellconfig.h.
---
 cpukit/libmisc/rtems-fdt/rtems-fdt.c | 40 +---
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/cpukit/libmisc/rtems-fdt/rtems-fdt.c 
b/cpukit/libmisc/rtems-fdt/rtems-fdt.c
index 39e70bffec..0ea365314f 100644
--- a/cpukit/libmisc/rtems-fdt/rtems-fdt.c
+++ b/cpukit/libmisc/rtems-fdt/rtems-fdt.c
@@ -248,48 +248,46 @@ rtems_fdt_index_find_by_name(rtems_fdt_index* index,
 {
   int min = 0;
   int max = index->num_entries;
-  charpath[256];
-  const char* cmp_name = name;
-
   /*
* Handle trailing slash case.
*/
-  int namelen = strlen(name);
+  size_t namelen = strlen(name);
   if (namelen > 0 && name[namelen-1] == '/')
   {
 namelen--;
-
-if (namelen >= (int)sizeof(path) - 1)
-{
-  namelen = sizeof(path) - 1;
-}
-
-strncpy(path, name, namelen);
-path[namelen] = 0;
-cmp_name = path;
   }
 
   /* Binary search for the name. */
   while (min < max)
   {
 int middle = (min + max) / 2;
-int cmp = strcmp(cmp_name, index->entries[middle].name);
+int cmp = strncmp(name, index->entries[middle].name, namelen);
+if (cmp == 0)
+{
+  /* 'namelen' characters are equal but 'index->entries[middle].name' */
+  /* could have additional characters. */
+  if (index->entries[middle].name[namelen] == '\0')
+  {
+/* Found it. */
+return index->entries[middle].offset;
+  }
+  else
+  {
+ /* 'index->entries[middle].name' is longer than 'name'. */
+ cmp = -1;
+  }
+}
 if (cmp < 0)
 {
   /* Look lower than here. */
   max = middle;
 }
-else if (cmp > 0)
+else
 {
   /* Look higher than here. */
   min = middle + 1;
 }
-else
-{
-  /* Found it. */
-  return index->entries[middle].offset;
-}
-  }
+ }
 
   /* Didn't find it. */
   return -FDT_ERR_NOTFOUND;
-- 
2.26.2

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

[PATCH 5/5] shell/main_edit.c: Fix string truncation warning

2020-10-13 Thread Frank Kuehndel
From: Frank Kühndel 

Using strlcpy() instead of strncpy():

1) Prevents the compiler warnings
2) Ensures, the string is NUL terminated.
3) Avoids that strncpy() unnecessary fills the unused part of the buffer with
   0 bytes.

(Note that realpath() also returns NULL if the file does not exist - that
happens always if someone creates a new file with the editor of the shell.)
---
 cpukit/libmisc/shell/main_edit.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/cpukit/libmisc/shell/main_edit.c b/cpukit/libmisc/shell/main_edit.c
index 02214bd942..a0110495e8 100644
--- a/cpukit/libmisc/shell/main_edit.c
+++ b/cpukit/libmisc/shell/main_edit.c
@@ -283,11 +283,13 @@ static void delete_editor(struct editor *ed) {
 }
 
 static struct editor *find_editor(struct env *env, char *filename) {
-  char fn[PATH_MAX];
+  char fnbuf[PATH_MAX];
+  char *fn = fnbuf;
   struct editor *ed = env->current;
   struct editor *start = ed;
 
-  if (!realpath(filename, fn)) strncpy(fn, filename, FILENAME_MAX);
+  /* Note: When realpath() == NULL, usually the file doesn't exist */
+  if (!realpath(filename, fn)) { fn = filename; }
 
   do {
 if (strcmp(fn, ed->filename) == 0) return ed;
@@ -298,7 +300,7 @@ static struct editor *find_editor(struct env *env, char 
*filename) {
 
 static int new_file(struct editor *ed, char *filename) {
   if (*filename) {
-strncpy(ed->filename, filename, FILENAME_MAX);
+strlcpy(ed->filename, filename, sizeof(ed->filename));
   } else {
 sprintf(ed->filename, "Untitled-%d", ++ed->env->untitled);
 ed->newfile = 1;
@@ -1776,8 +1778,8 @@ static void save_editor(struct editor *ed) {
 return;
   }
 }
-strncpy(
-  ed->filename, (const char*) ed->env->linebuf, FILENAME_MAX);
+strlcpy(
+  ed->filename, (const char*) ed->env->linebuf, sizeof(ed->filename));
 ed->newfile = 0;
   }
 
-- 
2.26.2

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

[PATCH 3/5] shell/shell.c: Fix illegal string copy

2020-10-13 Thread Frank Kuehndel
From: Frank Kühndel 

This is an illegal use of strcpy() because one is not allowed to
use this function with overlapping source and destination buffers;
whereas memmove() is explicitly designed to handle such cases.

The copiler warning was:

../../../cpukit/libmisc/shell/shell.c:626:13: warning:
'strcpy' accessing between 1 and 2147483645 bytes at offsets
0 and [1, 2147483647] may overlap up to 2147483644 bytes at
offset [1, 2147483644] [-Wrestrict]
---
 cpukit/libmisc/shell/shell.c | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index c5fc1f5c48..1a3b438b37 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -287,6 +287,16 @@ void rtems_shell_dup_current_env(rtems_shell_env_t *copy)
   copy->managed = false;
 }
 
+/*
+ *  Move a string in a buffer to the left (e.g. when a character
+ *  is deleted). The string must be NUL-terminated and the
+ *  NUL-character will be moved too.
+ */
+static void rtems_shell_move_left( char *start, size_t offset )
+{
+  memmove(start, start + offset, strlen(start + offset) + 1);
+}
+
 /*
  *  Get a line of user input with modest features
  */
@@ -393,7 +403,7 @@ static int rtems_shell_line_editor(
   {
 int end;
 int bs;
-strcpy ([col], [col + 1]);
+rtems_shell_move_left(line + col, 1);
 if (output) {
   fprintf(out,"\r%s%s ", prompt, line);
   end = (int) strlen (line);
@@ -432,7 +442,7 @@ static int rtems_shell_line_editor(
 case 4: /* Control-D */
   if (strlen(line)) {
 if (col < strlen(line)) {
-  strcpy (line + col, line + col + 1);
+  rtems_shell_move_left(line + col, 1);
   if (output) {
 int bs;
 fprintf(out,"%s \b", line + col);
@@ -508,7 +518,7 @@ static int rtems_shell_line_editor(
   {
 int bs;
 col--;
-strcpy (line + col, line + col + 1);
+rtems_shell_move_left(line + col, 1);
 if (output) {
   fprintf(out,"\b%s \b", line + col);
   for (bs = 0; bs < ((int) strlen (line) - col); bs++)
@@ -625,7 +635,7 @@ static int rtems_shell_line_editor(
 int clen = (int) strlen (line);
 int bs;
 
-strcpy (line, line + col);
+rtems_shell_move_left(line, col);
 if (output) {
   fprintf(out,"\r%s%*c", prompt, clen, ' ');
   fprintf(out,"\r%s%s", prompt, line);
-- 
2.26.2

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

[PATCH 4/5] shell/main_edit.c: Fix use of wrong constant

2020-10-13 Thread Frank Kuehndel
From: Frank Kühndel 

realpath() requires a buffer of size PATH_MAX and not of size
FILENAME_MAX according to 'man realpath (3)'.
---
 cpukit/libmisc/shell/main_edit.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/cpukit/libmisc/shell/main_edit.c b/cpukit/libmisc/shell/main_edit.c
index e43ff68d2b..02214bd942 100644
--- a/cpukit/libmisc/shell/main_edit.c
+++ b/cpukit/libmisc/shell/main_edit.c
@@ -32,6 +32,7 @@
 //
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -282,7 +283,7 @@ static void delete_editor(struct editor *ed) {
 }
 
 static struct editor *find_editor(struct env *env, char *filename) {
-  char fn[FILENAME_MAX];
+  char fn[PATH_MAX];
   struct editor *ed = env->current;
   struct editor *start = ed;
 
-- 
2.26.2

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

[PATCH 1/5] fsdosfsname01: Fix string truncation warning

2020-10-13 Thread Frank Kuehndel
From: Frank Kühndel 

This patch fixes a compiler warning:

../../../testsuites/fstests/fsdosfsname01/init.c:430:19: warning:
'%s' directive output may be truncated writing up to 6424 bytes into
a region of size 257 [-Wformat-truncation=]

The buffer 'dirname' is exactly large enough so that no truncation
can ever occur. Using the return value of snprintf() is an official
supported way to suppress the warning.

I considered the comment of Joel Sherrill about not replacing snprintf():
https://lists.rtems.org/pipermail/devel/2020-September/062113.html
---
 testsuites/fstests/fsdosfsname01/init.c | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/testsuites/fstests/fsdosfsname01/init.c 
b/testsuites/fstests/fsdosfsname01/init.c
index 3689da8eed..a916e392f7 100644
--- a/testsuites/fstests/fsdosfsname01/init.c
+++ b/testsuites/fstests/fsdosfsname01/init.c
@@ -422,14 +422,15 @@ static void test_creating_invalid_directories( void )
   unsigned int index;
   int  rc;
   char dirname[MAX_NAME_LENGTH_INVALID + MOUNT_DIR_SIZE + 1];
-
+  int  len;
 
   for ( index = 0; index < NUMBER_OF_DIRECTORIES_INVALID; ++index ) {
-snprintf( dirname,
-  sizeof( dirname ),
-  "%s/%s",
-  MOUNT_DIR,
-  DIRECTORY_NAMES_INVALID[index] );
+len = snprintf( dirname,
+sizeof( dirname ),
+"%s/%s",
+MOUNT_DIR,
+DIRECTORY_NAMES_INVALID[index] );
+rtems_test_assert( len < sizeof( dirname ) );
 rc = mkdir( dirname, S_IRWXU | S_IRWXG | S_IRWXO );
 rtems_test_assert( rc == -1 );
   }
-- 
2.26.2

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

[PATCH 2/5] shell/shell.c: Fix an implicit type cast

2020-10-13 Thread Frank Kuehndel
From: Frank Kühndel 

With some compiler warnings enabled, the implicit cast may trigger
a compiler warning. The explicit cast avoids this.
---
 cpukit/libmisc/shell/shell.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index 77214d0be4..c5fc1f5c48 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -620,7 +620,9 @@ static int rtems_shell_line_editor(
 case 21:/* Control-U */
   if (col > 0)
   {
-int clen = strlen (line);
+/* strlen() returns size_t but fprintf("%*...") below requires
+ * int! */
+int clen = (int) strlen (line);
 int bs;
 
 strcpy (line, line + col);
-- 
2.26.2

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

[PATCH 0/5] Fix several warnings and minor issues

2020-10-13 Thread Frank Kuehndel
From: Frank Kühndel 

This set of small patches fixes a few minor issues such as compiler
warnings, utilization of a wrong constant or bad uses of string copy.

Frank Kühndel (5):
  fsdosfsname01: Fix string truncation warning
  shell/shell.c: Fix an implicit type cast
  shell/shell.c:  Fix illegal string copy
  shell/main_edit.c: Fix use of wrong constant
  shell/main_edit.c: Fix string truncation warning

 cpukit/libmisc/shell/main_edit.c| 13 -
 cpukit/libmisc/shell/shell.c| 22 +-
 testsuites/fstests/fsdosfsname01/init.c | 13 +++--
 3 files changed, 32 insertions(+), 16 deletions(-)

-- 
2.26.2

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

[PATCH v2] testsuites/samples/fileio - Increase of stack size

2020-10-12 Thread Frank Kuehndel
From: Frank Kühndel 

When I use the 'shell' from the fileio sample with the command below:

   env QEMU_AUDIO_DRV="none" \
   qemu-system-arm -no-reboot -net none -nographic -M realview-pbx-a9 \
   -m 256M \
   -kernel build/arm/realview_pbx_a9_qemu/testsuites/samples/fileio.exe

The executable crashes with an "BLOWN STACK!!!" as soon as I try to login
as 'root' with password. (The logins without password work fine.)
Increasing the stack size of the affected thread a bit solves the issue.
Hence, I suggest this patch.

 My config.ini was

[arm/realview_pbx_a9_qemu]
RTEMS_DEBUG = True
RTEMS_NETWORKING = True
RTEMS_POSIX_API = True
RTEMS_SMP = True
BUILD_TESTS = True

RTEMS origin.master at a479686c112144119866391ceb21c48be6a3eca9

Close #4143
---
 testsuites/samples/fileio/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testsuites/samples/fileio/init.c b/testsuites/samples/fileio/init.c
index 86b34b99dd..c552d33613 100644
--- a/testsuites/samples/fileio/init.c
+++ b/testsuites/samples/fileio/init.c
@@ -630,7 +630,7 @@ static void fileio_start_shell(void)
   printf(" =\n");
   rtems_shell_init(
 "SHLL",  /* task_name */
-RTEMS_MINIMUM_STACK_SIZE * 4,/* task_stacksize */
+RTEMS_MINIMUM_STACK_SIZE * 5,/* task_stacksize */
 100, /* task_priority */
 "/dev/foobar",   /* devname */
 /* device is currently ignored by the shell if it is not a pty */
-- 
2.26.2

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

[PATCH] shell: Remove not functioning fdisk mount/unmount command

2020-10-09 Thread Frank Kuehndel
The shell has an 'fdisk' command which has sub-commands 'mount' and 'unmount'.
These two sub-commands have a bug which causes them to be not able
to mount anything. This proposed patch removes the buggy file
cpukit/libblock/src/bdpart-mount.c and the mount/unmount commands
from 'fdisk' as bug fix. The 'fdisk' command itself is not removed.
The reasons for removing the sub-commands (instead of fixing the issue) are:

  1) The bug has been introduced on 2010-May-31 with commit
 29e92b090c8bc35745aa5c89231ce806bcb11e57. Since ten years no one
 can use this feature, nor has anybody complained about it.

  2) Besides of the 'fdisk' 'mount' sub-command, the shell has the
 usual 'mount' and 'unmount' commands which can serve as
 substitutes.

  3) There are additional minor issues (see further down) which needed to
 be addressed when the file will be kept.

What follows below is the precise bug description.

The bug is in function rtems_bdpart_mount() which is only be used
by the 'fdisk' shell command to mount all partitions of a disk with a
single command:

> fdisk DISK_NAME mount
> mounts the file system of each partition of the disk
>
> fdisk DISK_NAME unmount
> unmounts the file system of each partition of the disk

The whole command does not work because in file
cpukit/libblock/src/bdpart-mount.c line 103 specifies the file system type
of each partition to be "msdos". Yet, "msdos" does not exist. The name
must be "dosfs".

Beside of this fundamental problem, there are more issues with the code
in bdpart-mount.c:

  1) The function returns RTEMS_SUCCESSFUL despite the mount always fails.

  2) The reason for errors is not written to the terminal.

  3) The directory '/mnt' is created but not deleted later on (failure or not).

  3) There is no documentation about this special 'fdisk' feature in the
 RTEMS Shell Guide ('fdisk' is mentioned but its documentation is a
 bit short):
 https://docs.rtems.org/branches/master/shell/
 file_and_directory.html#fdisk-format-disk

  4) Only "msdos" formatted partitions can be mounted and all partitions
 are mounted read-only. This is hard coded and cannot be changed by
 options. Moreover, there is no information about this to the user of
 the shell (i.e. using 'fdisk' mount requires insider knowledge).

How to reproduce:

  1) For testing, I use the 'testsuites/samples/fileio.exe' sample with qemu:

> cd rtems
> env QEMU_AUDIO_DRV="none" qemu-system-arm -net none -nographic \
> -M realview-pbx-a9 -m 256M -kernel \
> build/arm/realview_pbx_a9_qemu/testsuites/samples/fileio.exe

  2) Type any key to stop the timer and enter the sample tool.
 Type 's' to enter the shell, login as 'root' with the password
 shown in the terminal.

  3) Type the following shell commands (they create a RAM disk,
 partition it, register it, format it and try to mount it):

> mkrd
> fdisk /dev/rda fat32 16 write mbr
> fdisk /dev/rda register
> mkdos /dev/rda1
> fdisk /dev/rda mount

  4) The last line above is the command which fails - without an error
  message. There exists a '/mnt' directory but no '/mnt/rda1' directory
  as it should be:

> ls -la /mnt

  5) If you change line 103 of 'cpukit/libblock/src/bdpart-mount.c'
 from "msdos" to "dosfs", compile and build the executable and
 re-run the above test, '/mnt/rda1' exists (but the file system
 is mounted read-only).

Close #4131
---
 cpukit/Makefile.am |   1 -
 cpukit/include/rtems/bdpart.h  |  35 +-
 cpukit/libblock/src/bdpart-mount.c | 184 -
 cpukit/libmisc/shell/fdisk.c   |  36 +-
 spec/build/cpukit/librtemscpu.yml  |   1 -
 5 files changed, 7 insertions(+), 250 deletions(-)
 delete mode 100644 cpukit/libblock/src/bdpart-mount.c

diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
index 1f9124e175..bdd8ebef33 100644
--- a/cpukit/Makefile.am
+++ b/cpukit/Makefile.am
@@ -44,7 +44,6 @@ librtemscpu_a_SOURCES += dtc/libfdt/fdt_wip.c
 librtemscpu_a_SOURCES += libblock/src/bdbuf.c
 librtemscpu_a_SOURCES += libblock/src/bdpart-create.c
 librtemscpu_a_SOURCES += libblock/src/bdpart-dump.c
-librtemscpu_a_SOURCES += libblock/src/bdpart-mount.c
 librtemscpu_a_SOURCES += libblock/src/bdpart-read.c
 librtemscpu_a_SOURCES += libblock/src/bdpart-register.c
 librtemscpu_a_SOURCES += libblock/src/bdpart-sort.c
diff --git a/cpukit/include/rtems/bdpart.h b/cpukit/include/rtems/bdpart.h
index 8886c3614d..dde716e146 100644
--- a/cpukit/include/rtems/bdpart.h
+++ b/cpukit/include/rtems/bdpart.h
@@ -7,10 +7,10 @@
  */
 
 /*
- * Copyright (c) 2009-2012 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2009-2012, 2020 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
- *  Obere Lagerstr. 30
+ *  Dornierstr. 4
  *  82178 Puchheim
  *  Germany
  *  
@@ -302,37 +302,6 @@ rtems_status_code rtems_bdpart_unregister(
   size_t count
 );
 
-/**
- * @brief Mounts all supported file systems 

[PATCH] testsuites/samples/fileio - Increase of stack size

2020-10-09 Thread Frank Kuehndel
When I use the 'shell' from the fileio sample with the command below:

   env QEMU_AUDIO_DRV="none" \
   qemu-system-arm -no-reboot -net none -nographic -M realview-pbx-a9 -m 256M \
   -kernel build/arm/realview_pbx_a9_qemu/testsuites/samples/fileio.exe

The executable crashes with an "BLOWN STACK!!!" as soon as I try to login
as 'root' with password. (The logins without password work fine.) Increasing
the stack size of the affected thread a bit solves the issue. Hence,
I suggest this patch.
---
 testsuites/samples/fileio/init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testsuites/samples/fileio/init.c b/testsuites/samples/fileio/init.c
index 86b34b99dd..c552d33613 100644
--- a/testsuites/samples/fileio/init.c
+++ b/testsuites/samples/fileio/init.c
@@ -630,7 +630,7 @@ static void fileio_start_shell(void)
   printf(" =\n");
   rtems_shell_init(
 "SHLL",  /* task_name */
-RTEMS_MINIMUM_STACK_SIZE * 4,/* task_stacksize */
+RTEMS_MINIMUM_STACK_SIZE * 5,/* task_stacksize */
 100, /* task_priority */
 "/dev/foobar",   /* devname */
 /* device is currently ignored by the shell if it is not a pty */
-- 
2.26.2

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


[PATCH] shell: Fixing bug in line editing of the shell with CTRL-U.

2020-09-25 Thread Frank Kuehndel
This patch fixes a tiny bug in the command line editing of the RTEMS shell. 
Typing CTRL-U in the shell should remove all characters left of the cursor. 
After pressing CTRL-U, the current implementation does wrongly place the cursor 
at the end of the line instead at its beginning.


To reproduce the bug, start the shell and type 'abc123' (no ):

> ~/src/rtems $ qemu-system-arm -net none -nographic -M realview-pbx-a9 -m 256M 
> -kernel build/arm/realview_pbx_a9_qemu/testsuites/libtests/dl10.exe
> 
> 
> *** BEGIN OF TEST libdl (RTL) 10 ***
> *** TEST VERSION: 6.0.0.d9bdf166644f612dd628fe4951c12c6f8e94ba5f
> *** TEST STATE: USER_INPUT
> *** TEST BUILD: RTEMS_DEBUG RTEMS_NETWORKING RTEMS_POSIX_API RTEMS_SMP
> *** TEST TOOLS: 10.2.1 20200904 (RTEMS 6, RSB 
> 31f936a7b74d60bda609a9960c6e1a705ba54974, Newlib a0d7982)
> RTL (libdl) commands: dl, rtl
> 
> 
> RTEMS Shell on /dev/foobar. Use 'help' to list commands.
> SHLL [/] # abc123

Then move the cursor onto the '1' by hitting three times the  key. 
Next type -U:

> SHLL [/] # 123 

Note that the cursor is at the end of the line (after '3') instead of correctly 
at the beginning (on the '1'), now.

Continuing typing 'echo ' incorrectly results in the output:

> SHLL [/] # 123echo 123

The patch changes this behavior so that the cursor in the second last step will 
be on the '1' and typing 'echo ' will then correctly reflected as:

> SHLL [/] # echo 123

---
 cpukit/libmisc/shell/shell.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index 13ae411f9c..ee65c1be36 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -621,11 +621,14 @@ static int rtems_shell_line_editor(
   if (col > 0)
   {
 int clen = strlen (line);
+int bs;
 
 strcpy (line, line + col);
 if (output) {
   fprintf(out,"\r%s%*c", prompt, clen, ' ');
   fprintf(out,"\r%s%s", prompt, line);
+  for (bs = 0; bs < strlen (line); bs++)
+fputc('\b', out);
 }
 col = 0;
   }
-- 
2.26.2

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