mbox series

[kvm-unit-tests,0/4] Fix the devicetree parser for stdout-path

Message ID 20210316152405.50363-1-nikos.nikoleris@arm.com (mailing list archive)
Headers show
Series Fix the devicetree parser for stdout-path | expand

Message

Nikos Nikoleris March 16, 2021, 3:24 p.m. UTC
This set of patches fixes the way we parse the stdout-path which is
used to set up the console. Prior to this, the code ignored the fact
that stdout-path is made of the path to the uart node as well as
parameters and as a result it would fail to find the relevant DT
node. In addition to minor fixes in the device tree code, this series
pulls a new version of libfdt from upstream.

Thanks,

Nikos

Nikos Nikoleris (4):
  lib/string: add strnlen and strrchr
  libfdt: Pull v1.6.0
  Makefile: Avoid double definition of libfdt_clean
  devicetree: Parse correctly the stdout-path

 lib/libfdt/README            |   3 +-
 Makefile                     |  12 +-
 lib/libfdt/Makefile.libfdt   |  10 +-
 lib/libfdt/version.lds       |  24 +-
 lib/libfdt/fdt.h             |  53 +--
 lib/libfdt/libfdt.h          | 766 +++++++++++++++++++++++++-----
 lib/libfdt/libfdt_env.h      | 109 ++---
 lib/libfdt/libfdt_internal.h | 206 +++++---
 lib/string.h                 |   5 +-
 lib/devicetree.c             |  15 +-
 lib/libfdt/fdt.c             | 200 +++++---
 lib/libfdt/fdt_addresses.c   | 101 ++++
 lib/libfdt/fdt_check.c       |  74 +++
 lib/libfdt/fdt_empty_tree.c  |  48 +-
 lib/libfdt/fdt_overlay.c     | 881 +++++++++++++++++++++++++++++++++++
 lib/libfdt/fdt_ro.c          | 512 +++++++++++++++-----
 lib/libfdt/fdt_rw.c          | 231 +++++----
 lib/libfdt/fdt_strerror.c    |  53 +--
 lib/libfdt/fdt_sw.c          | 297 ++++++++----
 lib/libfdt/fdt_wip.c         |  90 ++--
 lib/string.c                 |  30 +-
 21 files changed, 2890 insertions(+), 830 deletions(-)
 create mode 100644 lib/libfdt/fdt_addresses.c
 create mode 100644 lib/libfdt/fdt_check.c
 create mode 100644 lib/libfdt/fdt_overlay.c

Comments

Andrew Jones March 16, 2021, 4:12 p.m. UTC | #1
On Tue, Mar 16, 2021 at 03:24:03PM +0000, Nikos Nikoleris wrote:
> This change updates the libfdt source files to v1.6.0 from
> git://git.kernel.org/pub/scm/utils/dtc/dtc.git
> 
> Signed-off-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
> ---
>  lib/libfdt/README            |   3 +-
>  lib/libfdt/Makefile.libfdt   |  10 +-
>  lib/libfdt/version.lds       |  24 +-
>  lib/libfdt/fdt.h             |  53 +--
>  lib/libfdt/libfdt.h          | 766 +++++++++++++++++++++++++-----
>  lib/libfdt/libfdt_env.h      | 109 ++---
>  lib/libfdt/libfdt_internal.h | 206 +++++---
>  lib/libfdt/fdt.c             | 200 +++++---
>  lib/libfdt/fdt_addresses.c   | 101 ++++
>  lib/libfdt/fdt_check.c       |  74 +++
>  lib/libfdt/fdt_empty_tree.c  |  48 +-
>  lib/libfdt/fdt_overlay.c     | 881 +++++++++++++++++++++++++++++++++++
>  lib/libfdt/fdt_ro.c          | 512 +++++++++++++++-----
>  lib/libfdt/fdt_rw.c          | 231 +++++----
>  lib/libfdt/fdt_strerror.c    |  53 +--
>  lib/libfdt/fdt_sw.c          | 297 ++++++++----
>  lib/libfdt/fdt_wip.c         |  90 ++--
>  17 files changed, 2844 insertions(+), 814 deletions(-)
>  create mode 100644 lib/libfdt/fdt_addresses.c
>  create mode 100644 lib/libfdt/fdt_check.c
>  create mode 100644 lib/libfdt/fdt_overlay.c
> 
> diff --git a/lib/libfdt/README b/lib/libfdt/README
> index 24ad4fe..aed3454 100644
> --- a/lib/libfdt/README
> +++ b/lib/libfdt/README
> @@ -1,4 +1,5 @@
>  
>  The code in this directory is originally imported from the libfdt
                                 ^^  says originally, so we should
replace the whole paragraph with something like

The code in this directory has been imported from the libfdt directory
of git://git.kernel.org/pub/scm/utils/dtc/dtc.git - version 1.6.0.

> -directory of git://git.jdl.com/software/dtc.git - version 1.4.0.
> +directory of git://git.kernel.org/pub/scm/utils/dtc/dtc.git -
> +version 1.60
>

Thanks,
drew
Andrew Jones March 16, 2021, 5:03 p.m. UTC | #2
On Tue, Mar 16, 2021 at 03:24:01PM +0000, Nikos Nikoleris wrote:
> This set of patches fixes the way we parse the stdout-path which is
> used to set up the console. Prior to this, the code ignored the fact
> that stdout-path is made of the path to the uart node as well as
> parameters and as a result it would fail to find the relevant DT
> node. In addition to minor fixes in the device tree code, this series
> pulls a new version of libfdt from upstream.
> 
> Thanks,
> 
> Nikos
> 
> Nikos Nikoleris (4):
>   lib/string: add strnlen and strrchr
>   libfdt: Pull v1.6.0
>   Makefile: Avoid double definition of libfdt_clean
>   devicetree: Parse correctly the stdout-path
> 
>  lib/libfdt/README            |   3 +-
>  Makefile                     |  12 +-
>  lib/libfdt/Makefile.libfdt   |  10 +-
>  lib/libfdt/version.lds       |  24 +-
>  lib/libfdt/fdt.h             |  53 +--
>  lib/libfdt/libfdt.h          | 766 +++++++++++++++++++++++++-----
>  lib/libfdt/libfdt_env.h      | 109 ++---
>  lib/libfdt/libfdt_internal.h | 206 +++++---
>  lib/string.h                 |   5 +-
>  lib/devicetree.c             |  15 +-
>  lib/libfdt/fdt.c             | 200 +++++---
>  lib/libfdt/fdt_addresses.c   | 101 ++++
>  lib/libfdt/fdt_check.c       |  74 +++
>  lib/libfdt/fdt_empty_tree.c  |  48 +-
>  lib/libfdt/fdt_overlay.c     | 881 +++++++++++++++++++++++++++++++++++
>  lib/libfdt/fdt_ro.c          | 512 +++++++++++++++-----
>  lib/libfdt/fdt_rw.c          | 231 +++++----
>  lib/libfdt/fdt_strerror.c    |  53 +--
>  lib/libfdt/fdt_sw.c          | 297 ++++++++----
>  lib/libfdt/fdt_wip.c         |  90 ++--
>  lib/string.c                 |  30 +-
>  21 files changed, 2890 insertions(+), 830 deletions(-)
>  create mode 100644 lib/libfdt/fdt_addresses.c
>  create mode 100644 lib/libfdt/fdt_check.c
>  create mode 100644 lib/libfdt/fdt_overlay.c
> 
> -- 
> 2.25.1
>

Just tried to give this a test run, but I couldn't compile it on my x86
Fedora machine with my cross compiler:

  gcc-aarch64-linux-gnu-9.2.1-3.fc32.1.x86_64 

Every file that includes libfdt_env.h gives me a message like this

In file included from lib/libfdt/fdt_overlay.c:7:
lib/libfdt/libfdt_env.h:13:10: fatal error: stdlib.h: No such file or directory
   13 | #include <stdlib.h>
      |          ^~~~~~~~~~
compilation terminated

So I commented out the #include line to see why it was there. We need
strtoul(). I quick hacked an incomplete one (below) and was able to
compile and run tests. However I see that 'make clean' is leaving behind
several libfdt files

$ git clean -ndx
Would remove lib/libfdt/.fdt.d
Would remove lib/libfdt/.fdt_addresses.d
Would remove lib/libfdt/.fdt_check.d
Would remove lib/libfdt/.fdt_empty_tree.d
Would remove lib/libfdt/.fdt_overlay.d
Would remove lib/libfdt/.fdt_ro.d
Would remove lib/libfdt/.fdt_rw.d
Would remove lib/libfdt/.fdt_strerror.d
Would remove lib/libfdt/.fdt_sw.d
Would remove lib/libfdt/.fdt_wip.d

Thanks,
drew

diff --git a/lib/stdlib.h b/lib/stdlib.h
new file mode 100644
index 000000000000..23a3f318d526
--- /dev/null
+++ b/lib/stdlib.h
@@ -0,0 +1,4 @@
+#ifndef _STDLIB_H_
+#define _STDLIB_H_
+unsigned long int strtoul(const char *nptr, char **endptr, int base);
+#endif
diff --git a/lib/string.c b/lib/string.c
index 9258625c3d15..2336559cd5a1 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -6,6 +6,7 @@
  */
 
 #include "libcflat.h"
+#include "stdlib.h"
 
 size_t strlen(const char *buf)
 {
@@ -161,7 +162,7 @@ void *memchr(const void *s, int c, size_t n)
     return NULL;
 }
 
-long atol(const char *ptr)
+static long __atol(const char *ptr, char **endptr)
 {
     long acc = 0;
     const char *s = ptr;
@@ -189,9 +190,23 @@ long atol(const char *ptr)
     if (neg)
         acc = -acc;
 
+    if (endptr)
+        *endptr = (char *)s;
+
     return acc;
 }
 
+long atol(const char *ptr)
+{
+       return __atol(ptr, NULL);
+}
+
+unsigned long int strtoul(const char *nptr, char **endptr, int base)
+{
+       assert(base == 10);
+       return __atol(nptr, endptr);
+}
+
 extern char **environ;
 
 char *getenv(const char *name)
Nikos Nikoleris March 16, 2021, 6:54 p.m. UTC | #3
Hey Drew,

On 16/03/2021 17:03, Andrew Jones wrote:
> On Tue, Mar 16, 2021 at 03:24:01PM +0000, Nikos Nikoleris wrote:
>> This set of patches fixes the way we parse the stdout-path which is
>> used to set up the console. Prior to this, the code ignored the fact
>> that stdout-path is made of the path to the uart node as well as
>> parameters and as a result it would fail to find the relevant DT
>> node. In addition to minor fixes in the device tree code, this series
>> pulls a new version of libfdt from upstream.
>>
>> Thanks,
>>
>> Nikos
>>
>> Nikos Nikoleris (4):
>>    lib/string: add strnlen and strrchr
>>    libfdt: Pull v1.6.0
>>    Makefile: Avoid double definition of libfdt_clean
>>    devicetree: Parse correctly the stdout-path
>>
>>   lib/libfdt/README            |   3 +-
>>   Makefile                     |  12 +-
>>   lib/libfdt/Makefile.libfdt   |  10 +-
>>   lib/libfdt/version.lds       |  24 +-
>>   lib/libfdt/fdt.h             |  53 +--
>>   lib/libfdt/libfdt.h          | 766 +++++++++++++++++++++++++-----
>>   lib/libfdt/libfdt_env.h      | 109 ++---
>>   lib/libfdt/libfdt_internal.h | 206 +++++---
>>   lib/string.h                 |   5 +-
>>   lib/devicetree.c             |  15 +-
>>   lib/libfdt/fdt.c             | 200 +++++---
>>   lib/libfdt/fdt_addresses.c   | 101 ++++
>>   lib/libfdt/fdt_check.c       |  74 +++
>>   lib/libfdt/fdt_empty_tree.c  |  48 +-
>>   lib/libfdt/fdt_overlay.c     | 881 +++++++++++++++++++++++++++++++++++
>>   lib/libfdt/fdt_ro.c          | 512 +++++++++++++++-----
>>   lib/libfdt/fdt_rw.c          | 231 +++++----
>>   lib/libfdt/fdt_strerror.c    |  53 +--
>>   lib/libfdt/fdt_sw.c          | 297 ++++++++----
>>   lib/libfdt/fdt_wip.c         |  90 ++--
>>   lib/string.c                 |  30 +-
>>   21 files changed, 2890 insertions(+), 830 deletions(-)
>>   create mode 100644 lib/libfdt/fdt_addresses.c
>>   create mode 100644 lib/libfdt/fdt_check.c
>>   create mode 100644 lib/libfdt/fdt_overlay.c
>>
>> --
>> 2.25.1
>>
>
> Just tried to give this a test run, but I couldn't compile it on my x86
> Fedora machine with my cross compiler:
>
>    gcc-aarch64-linux-gnu-9.2.1-3.fc32.1.x86_64
>
> Every file that includes libfdt_env.h gives me a message like this
>
> In file included from lib/libfdt/fdt_overlay.c:7:
> lib/libfdt/libfdt_env.h:13:10: fatal error: stdlib.h: No such file or directory
>     13 | #include <stdlib.h>
>        |          ^~~~~~~~~~
> compilation terminated
>
> So I commented out the #include line to see why it was there. We need
> strtoul(). I quick hacked an incomplete one (below) and was able to
> compile and run tests. However I see that 'make clean' is leaving behind
> several libfdt files
>
Thanks for testing and for the fixes!

For some reason this isn't causing problems in my setup. gcc is
eliminating unused symbols and it doesn't need to link with strtoul(). I
see how this is a problem though and I will include your fix in the next
version.

> $ git clean -ndx
> Would remove lib/libfdt/.fdt.d
> Would remove lib/libfdt/.fdt_addresses.d
> Would remove lib/libfdt/.fdt_check.d
> Would remove lib/libfdt/.fdt_empty_tree.d
> Would remove lib/libfdt/.fdt_overlay.d
> Would remove lib/libfdt/.fdt_ro.d
> Would remove lib/libfdt/.fdt_rw.d
> Would remove lib/libfdt/.fdt_strerror.d
> Would remove lib/libfdt/.fdt_sw.d
> Would remove lib/libfdt/.fdt_wip.d
>

Sorry for that, I will fix in the Makefile.

Thanks,

Nikos

> Thanks,
> drew
>
> diff --git a/lib/stdlib.h b/lib/stdlib.h
> new file mode 100644
> index 000000000000..23a3f318d526
> --- /dev/null
> +++ b/lib/stdlib.h
> @@ -0,0 +1,4 @@
> +#ifndef _STDLIB_H_
> +#define _STDLIB_H_
> +unsigned long int strtoul(const char *nptr, char **endptr, int base);
> +#endif
> diff --git a/lib/string.c b/lib/string.c
> index 9258625c3d15..2336559cd5a1 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -6,6 +6,7 @@
>    */
>
>   #include "libcflat.h"
> +#include "stdlib.h"
>
>   size_t strlen(const char *buf)
>   {
> @@ -161,7 +162,7 @@ void *memchr(const void *s, int c, size_t n)
>       return NULL;
>   }
>
> -long atol(const char *ptr)
> +static long __atol(const char *ptr, char **endptr)
>   {
>       long acc = 0;
>       const char *s = ptr;
> @@ -189,9 +190,23 @@ long atol(const char *ptr)
>       if (neg)
>           acc = -acc;
>
> +    if (endptr)
> +        *endptr = (char *)s;
> +
>       return acc;
>   }
>
> +long atol(const char *ptr)
> +{
> +       return __atol(ptr, NULL);
> +}
> +
> +unsigned long int strtoul(const char *nptr, char **endptr, int base)
> +{
> +       assert(base == 10);
> +       return __atol(nptr, endptr);
> +}
> +
>   extern char **environ;
>
>   char *getenv(const char *name)
>
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Andrew Jones March 16, 2021, 7:01 p.m. UTC | #4
On Tue, Mar 16, 2021 at 06:54:21PM +0000, Nikos Nikoleris wrote:
> 
> Hey Drew,
> 
> On 16/03/2021 17:03, Andrew Jones wrote:
> > On Tue, Mar 16, 2021 at 03:24:01PM +0000, Nikos Nikoleris wrote:
> > > This set of patches fixes the way we parse the stdout-path which is
> > > used to set up the console. Prior to this, the code ignored the fact
> > > that stdout-path is made of the path to the uart node as well as
> > > parameters and as a result it would fail to find the relevant DT
> > > node. In addition to minor fixes in the device tree code, this series
> > > pulls a new version of libfdt from upstream.
> > > 
> > > Thanks,
> > > 
> > > Nikos
> > > 
> > > Nikos Nikoleris (4):
> > >    lib/string: add strnlen and strrchr
> > >    libfdt: Pull v1.6.0
> > >    Makefile: Avoid double definition of libfdt_clean
> > >    devicetree: Parse correctly the stdout-path
> > > 
> > >   lib/libfdt/README            |   3 +-
> > >   Makefile                     |  12 +-
> > >   lib/libfdt/Makefile.libfdt   |  10 +-
> > >   lib/libfdt/version.lds       |  24 +-
> > >   lib/libfdt/fdt.h             |  53 +--
> > >   lib/libfdt/libfdt.h          | 766 +++++++++++++++++++++++++-----
> > >   lib/libfdt/libfdt_env.h      | 109 ++---
> > >   lib/libfdt/libfdt_internal.h | 206 +++++---
> > >   lib/string.h                 |   5 +-
> > >   lib/devicetree.c             |  15 +-
> > >   lib/libfdt/fdt.c             | 200 +++++---
> > >   lib/libfdt/fdt_addresses.c   | 101 ++++
> > >   lib/libfdt/fdt_check.c       |  74 +++
> > >   lib/libfdt/fdt_empty_tree.c  |  48 +-
> > >   lib/libfdt/fdt_overlay.c     | 881 +++++++++++++++++++++++++++++++++++
> > >   lib/libfdt/fdt_ro.c          | 512 +++++++++++++++-----
> > >   lib/libfdt/fdt_rw.c          | 231 +++++----
> > >   lib/libfdt/fdt_strerror.c    |  53 +--
> > >   lib/libfdt/fdt_sw.c          | 297 ++++++++----
> > >   lib/libfdt/fdt_wip.c         |  90 ++--
> > >   lib/string.c                 |  30 +-
> > >   21 files changed, 2890 insertions(+), 830 deletions(-)
> > >   create mode 100644 lib/libfdt/fdt_addresses.c
> > >   create mode 100644 lib/libfdt/fdt_check.c
> > >   create mode 100644 lib/libfdt/fdt_overlay.c
> > > 
> > > --
> > > 2.25.1
> > > 
> > 
> > Just tried to give this a test run, but I couldn't compile it on my x86
> > Fedora machine with my cross compiler:
> > 
> >    gcc-aarch64-linux-gnu-9.2.1-3.fc32.1.x86_64
> > 
> > Every file that includes libfdt_env.h gives me a message like this
> > 
> > In file included from lib/libfdt/fdt_overlay.c:7:
> > lib/libfdt/libfdt_env.h:13:10: fatal error: stdlib.h: No such file or directory
> >     13 | #include <stdlib.h>
> >        |          ^~~~~~~~~~
> > compilation terminated
> > 
> > So I commented out the #include line to see why it was there. We need
> > strtoul(). I quick hacked an incomplete one (below) and was able to
> > compile and run tests. However I see that 'make clean' is leaving behind
> > several libfdt files
> > 
> Thanks for testing and for the fixes!
> 
> For some reason this isn't causing problems in my setup. gcc is
> eliminating unused symbols and it doesn't need to link with strtoul(). I
> see how this is a problem though and I will include your fix in the next
> version.

Please write a proper strtoul(). Mine was just a minimal hack so I could
progress and see if there was anything else to comment on.

Thanks,
drew

> 
> > $ git clean -ndx
> > Would remove lib/libfdt/.fdt.d
> > Would remove lib/libfdt/.fdt_addresses.d
> > Would remove lib/libfdt/.fdt_check.d
> > Would remove lib/libfdt/.fdt_empty_tree.d
> > Would remove lib/libfdt/.fdt_overlay.d
> > Would remove lib/libfdt/.fdt_ro.d
> > Would remove lib/libfdt/.fdt_rw.d
> > Would remove lib/libfdt/.fdt_strerror.d
> > Would remove lib/libfdt/.fdt_sw.d
> > Would remove lib/libfdt/.fdt_wip.d
> > 
> 
> Sorry for that, I will fix in the Makefile.
> 
> Thanks,
> 
> Nikos
> 
> > Thanks,
> > drew
> > 
> > diff --git a/lib/stdlib.h b/lib/stdlib.h
> > new file mode 100644
> > index 000000000000..23a3f318d526
> > --- /dev/null
> > +++ b/lib/stdlib.h
> > @@ -0,0 +1,4 @@
> > +#ifndef _STDLIB_H_
> > +#define _STDLIB_H_
> > +unsigned long int strtoul(const char *nptr, char **endptr, int base);
> > +#endif
> > diff --git a/lib/string.c b/lib/string.c
> > index 9258625c3d15..2336559cd5a1 100644
> > --- a/lib/string.c
> > +++ b/lib/string.c
> > @@ -6,6 +6,7 @@
> >    */
> > 
> >   #include "libcflat.h"
> > +#include "stdlib.h"
> > 
> >   size_t strlen(const char *buf)
> >   {
> > @@ -161,7 +162,7 @@ void *memchr(const void *s, int c, size_t n)
> >       return NULL;
> >   }
> > 
> > -long atol(const char *ptr)
> > +static long __atol(const char *ptr, char **endptr)
> >   {
> >       long acc = 0;
> >       const char *s = ptr;
> > @@ -189,9 +190,23 @@ long atol(const char *ptr)
> >       if (neg)
> >           acc = -acc;
> > 
> > +    if (endptr)
> > +        *endptr = (char *)s;
> > +
> >       return acc;
> >   }
> > 
> > +long atol(const char *ptr)
> > +{
> > +       return __atol(ptr, NULL);
> > +}
> > +
> > +unsigned long int strtoul(const char *nptr, char **endptr, int base)
> > +{
> > +       assert(base == 10);
> > +       return __atol(nptr, endptr);
> > +}
> > +
> >   extern char **environ;
> > 
> >   char *getenv(const char *name)
> > 
> IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
>