Skip to contentSkip to conversation

tools/bootconfig: Add O= option and enhance error message

PATCH In review Masami Hiramatsu 5 participants 20 messages Mar 3, 2020 – Mar 6, 2020

Subsystems (3)
lore
Share & tools
lore

Masami Hiramatsu

author maintainer
#0 lore raw

cover tools/bootconfig: Add O= option and enhance error message

Hi,

Here are patches to update tools/bootconfig to add O= option support and enhance error message so that user can easily locate the error position.

Thank you,

---

Masami Hiramatsu (2):
bootconfig: Support O=<builddir> option tools/bootconfig: Show line and column in parse error

 include/linux/bootconfig.h          |    3 ++-
 init/main.c                         |   14 ++++++++++----
 lib/bootconfig.c                    |   35 ++++++++++++++++++++++++++---------
 tools/bootconfig/Makefile           |   27 +++++++++++++++++----------
 tools/bootconfig/main.c             |   35 +++++++++++++++++++++++++++++++----
 tools/bootconfig/test-bootconfig.sh |   14 ++++++++++----
 6 files changed, 96 insertions(+), 32 deletions(-)

--
Masami Hiramatsu (Linaro) <[email protected]>

author maintainer
#1 lore raw

PATCH 1/2 bootconfig: Support O=<builddir> option

Support O=<builddir> option to build bootconfig tool in the other directory. As same as other tools, if you specify O=<builddir>, bootconfig command is build under <builddir>.

---
 tools/bootconfig/Makefile           |   27 +++++++++++++++++----------
 tools/bootconfig/test-bootconfig.sh |   14 ++++++++++----
 2 files changed, 27 insertions(+), 14 deletions(-)
tools/bootconfig/Makefile +17 -10
index a6146ac64458..da5975775337 100644
@@ -1,23 +1,30 @@
 # SPDX-License-Identifier: GPL-2.0
 # Makefile for bootconfig command
+include ../scripts/Makefile.include
 
 bindir ?= /usr/bin
 
-HEADER = include/linux/bootconfig.h
-CFLAGS = -Wall -g -I./include
+ifeq ($(srctree),)
+srctree := $(patsubst %/,%,$(dir $(CURDIR)))
+srctree := $(patsubst %/,%,$(dir $(srctree)))
+endif
 
-PROGS = bootconfig
+LIBSRC = $(srctree)/lib/bootconfig.c $(srctree)/include/linux/bootconfig.h
+CFLAGS = -Wall -g -I$(CURDIR)/include
 
-all: $(PROGS)
+ALL_TARGETS := bootconfig
+ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
 
-bootconfig: ../../lib/bootconfig.c main.c $(HEADER)
+all: $(ALL_PROGRAMS)
+
+$(OUTPUT)bootconfig: main.c $(LIBSRC)
 	$(CC) $(filter %.c,$^) $(CFLAGS) -o $@
 
-install: $(PROGS)
-	install bootconfig $(DESTDIR)$(bindir)
+test: $(ALL_PROGRAMS) test-bootconfig.sh
+	./test-bootconfig.sh $(OUTPUT)
 
-test: bootconfig
-	./test-bootconfig.sh
+install: $(ALL_PROGRAMS)
+	install $(OUTPUT)bootconfig $(DESTDIR)$(bindir)
 
 clean:
-	$(RM) -f *.o bootconfig
+	$(RM) -f $(OUTPUT)*.o $(ALL_PROGRAMS)
tools/bootconfig/test-bootconfig.sh +10 -4
index 1411f4c3454f..81b350ffd03f 100755
@@ -3,9 +3,16 @@
 
 echo "Boot config test script"
 
-BOOTCONF=./bootconfig
-INITRD=`mktemp initrd-XXXX`
-TEMPCONF=`mktemp temp-XXXX.bconf`
+if [ -d "$1" ]; then
+  TESTDIR=$1
+else
+  TESTDIR=.
+fi
+BOOTCONF=${TESTDIR}/bootconfig
+
+INITRD=`mktemp ${TESTDIR}/initrd-XXXX`
+TEMPCONF=`mktemp ${TESTDIR}/temp-XXXX.bconf`
+OUTFILE=`mktemp ${TESTDIR}/tempout-XXXX`
 NG=0
 
 cleanup() {
@@ -65,7 +72,6 @@ new_size=$(stat -c %s $INITRD)
 xpass test $new_size -eq $initrd_size
 
 echo "No error messge while applying"
-OUTFILE=`mktemp tempout-XXXX`
 dd if=/dev/zero of=$INITRD bs=4096 count=1
 printf " \0\0\0 \0\0\0" >> $INITRD
 $BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1
#2 lore raw

Re: [PATCH 1/2] bootconfig: Support O=<builddir> option

Quoted 3 lines · Masami Hiramatsu

Support O=<builddir> option to build bootconfig tool in the other directory. As same as other tools, if you specify O=<builddir>, bootconfig command is build under <builddir>.

Hm. If I use

$ make O=~/tmp -C tools/bootconfig

that works: it builds bootconfig in ~/tmp.

OTOH, if I sit at the top of the kernel source tree and I enter

$ mkdir builddir
$ make O=builddir -C tools/bootconfig

I get this:
make: Entering directory '/home/rdunlap/lnx/next/linux-next-20200304/tools/bootconfig' ../scripts/Makefile.include:4: *** O=builddir does not exist. Stop.
make: Leaving directory '/home/rdunlap/lnx/next/linux-next-20200304/tools/bootconfig'

so it looks like tools/scripts/Makefile.include doesn't handle this case correctly (which is how I do all of my builds).

Quoted 85 lines
---
 tools/bootconfig/Makefile           |   27 +++++++++++++++++----------
 tools/bootconfig/test-bootconfig.sh |   14 ++++++++++----
 2 files changed, 27 insertions(+), 14 deletions(-)
tools/bootconfig/Makefile +17 -10
index a6146ac64458..da5975775337 100644
@@ -1,23 +1,30 @@
 # SPDX-License-Identifier: GPL-2.0
 # Makefile for bootconfig command
+include ../scripts/Makefile.include
 
 bindir ?= /usr/bin
 
-HEADER = include/linux/bootconfig.h
-CFLAGS = -Wall -g -I./include
+ifeq ($(srctree),)
+srctree := $(patsubst %/,%,$(dir $(CURDIR)))
+srctree := $(patsubst %/,%,$(dir $(srctree)))
+endif
 
-PROGS = bootconfig
+LIBSRC = $(srctree)/lib/bootconfig.c $(srctree)/include/linux/bootconfig.h
+CFLAGS = -Wall -g -I$(CURDIR)/include
 
-all: $(PROGS)
+ALL_TARGETS := bootconfig
+ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
 
-bootconfig: ../../lib/bootconfig.c main.c $(HEADER)
+all: $(ALL_PROGRAMS)
+
+$(OUTPUT)bootconfig: main.c $(LIBSRC)
 	$(CC) $(filter %.c,$^) $(CFLAGS) -o $@
 
-install: $(PROGS)
-	install bootconfig $(DESTDIR)$(bindir)
+test: $(ALL_PROGRAMS) test-bootconfig.sh
+	./test-bootconfig.sh $(OUTPUT)
 
-test: bootconfig
-	./test-bootconfig.sh
+install: $(ALL_PROGRAMS)
+	install $(OUTPUT)bootconfig $(DESTDIR)$(bindir)
 
 clean:
-	$(RM) -f *.o bootconfig
+	$(RM) -f $(OUTPUT)*.o $(ALL_PROGRAMS)
tools/bootconfig/test-bootconfig.sh +10 -4
index 1411f4c3454f..81b350ffd03f 100755
@@ -3,9 +3,16 @@
 
 echo "Boot config test script"
 
-BOOTCONF=./bootconfig
-INITRD=`mktemp initrd-XXXX`
-TEMPCONF=`mktemp temp-XXXX.bconf`
+if [ -d "$1" ]; then
+  TESTDIR=$1
+else
+  TESTDIR=.
+fi
+BOOTCONF=${TESTDIR}/bootconfig
+
+INITRD=`mktemp ${TESTDIR}/initrd-XXXX`
+TEMPCONF=`mktemp ${TESTDIR}/temp-XXXX.bconf`
+OUTFILE=`mktemp ${TESTDIR}/tempout-XXXX`
 NG=0
 
 cleanup() {
@@ -65,7 +72,6 @@ new_size=$(stat -c %s $INITRD)
 xpass test $new_size -eq $initrd_size
 
 echo "No error messge while applying"
-OUTFILE=`mktemp tempout-XXXX`
 dd if=/dev/zero of=$INITRD bs=4096 count=1
 printf " \0\0\0 \0\0\0" >> $INITRD
 $BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1
Signature · 2 lines
~Randy
Reported-by: Randy Dunlap <[email protected]>
author maintainer
#3 lore raw

Re: [PATCH 1/2] bootconfig: Support O=<builddir> option

Quoted 15 lines · On Wed, 4 Mar 2020 15:04:43 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 3 lines · Masami Hiramatsu

Support O=<builddir> option to build bootconfig tool in the other directory. As same as other tools, if you specify O=<builddir>, bootconfig command is build under <builddir>.

Hm. If I use

$ make O=~/tmp -C tools/bootconfig

that works: it builds bootconfig in ~/tmp.

OTOH, if I sit at the top of the kernel source tree and I enter

$ mkdir builddir
$ make O=builddir -C tools/bootconfig
Quoted 7 lines

I get this:
make: Entering directory '/home/rdunlap/lnx/next/linux-next-20200304/tools/bootconfig' ../scripts/Makefile.include:4: *** O=builddir does not exist. Stop.
make: Leaving directory '/home/rdunlap/lnx/next/linux-next-20200304/tools/bootconfig'

so it looks like tools/scripts/Makefile.include doesn't handle this case correctly (which is how I do all of my builds).

Yes, I think that should be fixed in another patch. What about below?

tools/scripts/Makefile.include +2 -2
index ded7a950dc40..6d2f3a1b2249 100644
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 ifneq ($(O),)
 ifeq ($(origin O), command line)
-	dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
-	ABSOLUTE_O := $(shell cd $(O) ; pwd)
+	dummy := $(if $(shell cd $(PWD); test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
+	ABSOLUTE_O := $(shell cd $(PWD); cd $(O) ; pwd)
 	OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
 	COMMAND_O := O=$(ABSOLUTE_O)
 ifeq ($(objtree),)

Thank you,

Signature · 1 line
Masami Hiramatsu <[email protected]>
#4 lore raw

Re: [PATCH 1/2] bootconfig: Support O=<builddir> option

In reply to Randy Dunlap
Quoted 15 lines · On Wed, 4 Mar 2020 15:04:43 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 3 lines · Masami Hiramatsu

Support O=<builddir> option to build bootconfig tool in the other directory. As same as other tools, if you specify O=<builddir>, bootconfig command is build under <builddir>.

Hm. If I use

$ make O=~/tmp -C tools/bootconfig

that works: it builds bootconfig in ~/tmp.

OTOH, if I sit at the top of the kernel source tree and I enter

$ mkdir builddir
$ make O=builddir -C tools/bootconfig
Quoted 8 lines

I get this:
make: Entering directory '/home/rdunlap/lnx/next/linux-next-20200304/tools/bootconfig' ../scripts/Makefile.include:4: *** O=builddir does not exist. Stop.
make: Leaving directory '/home/rdunlap/lnx/next/linux-next-20200304/tools/bootconfig'

so it looks like tools/scripts/Makefile.include doesn't handle this case correctly (which is how I do all of my builds).

Do you build perf that way?

$ mkdir buildir
$ make O=buildir -C tools/perf/
make: Entering directory '/work/git/linux-test.git/tools/perf'
  BUILD:   Doing 'make -j24' parallel build
../scripts/Makefile.include:4: *** O=/work/git/linux-test.git/tools/perf/buildir does not exist.  Stop.
make: *** [Makefile:70: all] Error 2
make: Leaving directory '/work/git/linux-test.git/tools/perf'

-- Steve

#5 lore raw

Re: [PATCH 1/2] bootconfig: Support O=<builddir> option

Quoted 23 lines · Steven Rostedt
Quoted 20 lines · On Wed, 4 Mar 2020 15:04:43 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 3 lines · Masami Hiramatsu

Support O=<builddir> option to build bootconfig tool in the other directory. As same as other tools, if you specify O=<builddir>, bootconfig command is build under <builddir>.

Hm. If I use

$ make O=~/tmp -C tools/bootconfig

that works: it builds bootconfig in ~/tmp.

OTOH, if I sit at the top of the kernel source tree and I enter

$ mkdir builddir
$ make O=builddir -C tools/bootconfig

I get this:
make: Entering directory '/home/rdunlap/lnx/next/linux-next-20200304/tools/bootconfig' ../scripts/Makefile.include:4: *** O=builddir does not exist. Stop.
make: Leaving directory '/home/rdunlap/lnx/next/linux-next-20200304/tools/bootconfig'

Quoted 5 lines
Quoted 3 lines

so it looks like tools/scripts/Makefile.include doesn't handle this case correctly (which is how I do all of my builds).

Do you build perf that way?

No. It should also be fixed.

Quoted 9 lines
$ mkdir buildir
$ make O=buildir -C tools/perf/
make: Entering directory '/work/git/linux-test.git/tools/perf'
  BUILD:   Doing 'make -j24' parallel build
../scripts/Makefile.include:4: *** O=/work/git/linux-test.git/tools/perf/buildir does not exist.  Stop.
make: *** [Makefile:70: all] Error 2
make: Leaving directory '/work/git/linux-test.git/tools/perf'

-- Steve

Thanks.

Signature · 1 line
~Randy
author maintainer
#6 lore raw

PATCH 1/1 tools: Let O= makes handle a relative path with -C option

When I compiled tools/bootconfig from top directory with -C option, the O= option didn't work correctly if I passed a relative path.

  $ make O=./builddir/ -C tools/bootconfig/
  make: Entering directory '/home/mhiramat/ksrc/linux/tools/bootconfig'
  ../scripts/Makefile.include:4: *** O=./builddir/ does not exist.  Stop.
  make: Leaving directory '/home/mhiramat/ksrc/linux/tools/bootconfig'

The O= directory existence check failed because the check script ran in the build target directory instead of the directory where I ran the make command.

To fix that, once change directory to $(PWD) and check O= directory, since the PWD is set to where the make command runs.

Fixes c883122acc0d ("perf tools: Let O= makes handle relative paths")
---
 tools/scripts/Makefile.include |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/scripts/Makefile.include +2 -2
index ded7a950dc40..6d2f3a1b2249 100644
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 ifneq ($(O),)
 ifeq ($(origin O), command line)
-	dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
-	ABSOLUTE_O := $(shell cd $(O) ; pwd)
+	dummy := $(if $(shell cd $(PWD); test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
+	ABSOLUTE_O := $(shell cd $(PWD); cd $(O) ; pwd)
 	OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
 	COMMAND_O := O=$(ABSOLUTE_O)
 ifeq ($(objtree),)
maintainer
#7 lore raw

Re: [BUGFIX PATCH] tools: Let O= makes handle a relative path with -C option

Quoted 17 lines · Masami Hiramatsu

When I compiled tools/bootconfig from top directory with -C option, the O= option didn't work correctly if I passed a relative path.

  $ make O=./builddir/ -C tools/bootconfig/
  make: Entering directory '/home/mhiramat/ksrc/linux/tools/bootconfig'
  ../scripts/Makefile.include:4: *** O=./builddir/ does not exist.  Stop.
  make: Leaving directory '/home/mhiramat/ksrc/linux/tools/bootconfig'

The O= directory existence check failed because the check script ran in the build target directory instead of the directory where I ran the make command.

To fix that, once change directory to $(PWD) and check O= directory, since the PWD is set to where the make command runs.

Quoted 6 lines
Fixes c883122acc0d ("perf tools: Let O= makes handle relative paths")
---
 tools/scripts/Makefile.include |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

<formletter>

This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

#8 lore raw

Re: [BUGFIX PATCH] tools: Let O= makes handle a relative path with -C option

In reply to Masami Hiramatsu
Quoted 13 lines · Masami Hiramatsu

When I compiled tools/bootconfig from top directory with -C option, the O= option didn't work correctly if I passed a relative path.

  $ make O=./builddir/ -C tools/bootconfig/
  make: Entering directory '/home/mhiramat/ksrc/linux/tools/bootconfig'
  ../scripts/Makefile.include:4: *** O=./builddir/ does not exist.  Stop.
  make: Leaving directory '/home/mhiramat/ksrc/linux/tools/bootconfig'

The O= directory existence check failed because the check script ran in the build target directory instead of the directory where I ran the make command.

Quoted 7 lines

To fix that, once change directory to $(PWD) and check O= directory, since the PWD is set to where the make command runs.

Fixes c883122acc0d ("perf tools: Let O= makes handle relative paths")

Hi Masami,

This patch doesn't fix anything AFAICT.
Didn't help in my testing.

Thanks.

Quoted 20 lines
---
 tools/scripts/Makefile.include |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/scripts/Makefile.include +2 -2
index ded7a950dc40..6d2f3a1b2249 100644
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 ifneq ($(O),)
 ifeq ($(origin O), command line)
-	dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
-	ABSOLUTE_O := $(shell cd $(O) ; pwd)
+	dummy := $(if $(shell cd $(PWD); test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
+	ABSOLUTE_O := $(shell cd $(PWD); cd $(O) ; pwd)
 	OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
 	COMMAND_O := O=$(ABSOLUTE_O)
 ifeq ($(objtree),)
Signature · 2 lines
~Randy
Reported-by: Randy Dunlap <[email protected]>
author maintainer
#9 lore raw

Re: [BUGFIX PATCH] tools: Let O= makes handle a relative path with -C option

Quoted 18 lines · On Thu, 5 Mar 2020 10:50:43 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 17 lines · Masami Hiramatsu

When I compiled tools/bootconfig from top directory with -C option, the O= option didn't work correctly if I passed a relative path.

  $ make O=./builddir/ -C tools/bootconfig/
  make: Entering directory '/home/mhiramat/ksrc/linux/tools/bootconfig'
  ../scripts/Makefile.include:4: *** O=./builddir/ does not exist.  Stop.
  make: Leaving directory '/home/mhiramat/ksrc/linux/tools/bootconfig'

The O= directory existence check failed because the check script ran in the build target directory instead of the directory where I ran the make command.

To fix that, once change directory to $(PWD) and check O= directory, since the PWD is set to where the make command runs.

Quoted 9 lines
Quoted 3 lines
Fixes c883122acc0d ("perf tools: Let O= makes handle relative paths")

Hi Masami,

This patch doesn't fix anything AFAICT.
Didn't help in my testing.

Hmm, what happens on your case? Maybe PWD is not set?

Thank you,

Quoted 27 lines

Thanks.

Quoted 20 lines
---
 tools/scripts/Makefile.include |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/scripts/Makefile.include +2 -2
index ded7a950dc40..6d2f3a1b2249 100644
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 ifneq ($(O),)
 ifeq ($(origin O), command line)
-	dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
-	ABSOLUTE_O := $(shell cd $(O) ; pwd)
+	dummy := $(if $(shell cd $(PWD); test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
+	ABSOLUTE_O := $(shell cd $(PWD); cd $(O) ; pwd)
 	OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
 	COMMAND_O := O=$(ABSOLUTE_O)
 ifeq ($(objtree),)
Signature · 2 lines
~Randy
Reported-by: Randy Dunlap <[email protected]>
Signature · 1 line
Masami Hiramatsu <[email protected]>
#10 lore raw

Re: [BUGFIX PATCH] tools: Let O= makes handle a relative path with -C option

Quoted 27 lines · Masami Hiramatsu
Quoted 24 lines · On Thu, 5 Mar 2020 10:50:43 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 13 lines · Masami Hiramatsu

When I compiled tools/bootconfig from top directory with -C option, the O= option didn't work correctly if I passed a relative path.

  $ make O=./builddir/ -C tools/bootconfig/
  make: Entering directory '/home/mhiramat/ksrc/linux/tools/bootconfig'
  ../scripts/Makefile.include:4: *** O=./builddir/ does not exist.  Stop.
  make: Leaving directory '/home/mhiramat/ksrc/linux/tools/bootconfig'

The O= directory existence check failed because the check script ran in the build target directory instead of the directory where I ran the make command.

Quoted 7 lines

To fix that, once change directory to $(PWD) and check O= directory, since the PWD is set to where the make command runs.

Fixes c883122acc0d ("perf tools: Let O= makes handle relative paths")

Hi Masami,

Quoted 7 lines
Quoted 3 lines

This patch doesn't fix anything AFAICT.
Didn't help in my testing.

Hmm, what happens on your case? Maybe PWD is not set?

Thank you,

The binary is still built in $srctree/tools/bootconfig/.

If I 'echo $PWD' at a prompt, I get the correct pwd.

Quoted 22 lines
Quoted 22 lines

Thanks.

Quoted 19 lines
---
 tools/scripts/Makefile.include |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/scripts/Makefile.include +2 -2
index ded7a950dc40..6d2f3a1b2249 100644
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 ifneq ($(O),)
 ifeq ($(origin O), command line)
-	dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
-	ABSOLUTE_O := $(shell cd $(O) ; pwd)
+	dummy := $(if $(shell cd $(PWD); test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
+	ABSOLUTE_O := $(shell cd $(PWD); cd $(O) ; pwd)
 	OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
 	COMMAND_O := O=$(ABSOLUTE_O)
 ifeq ($(objtree),)
Signature · 1 line
~Randy
#11 lore raw

Re: [BUGFIX PATCH] tools: Let O= makes handle a relative path with -C option

In reply to Masami Hiramatsu

CC +kbuild, -stable

Quoted 40 lines · Masami Hiramatsu

When I compiled tools/bootconfig from top directory with -C option, the O= option didn't work correctly if I passed a relative path.

  $ make O=./builddir/ -C tools/bootconfig/
  make: Entering directory '/home/mhiramat/ksrc/linux/tools/bootconfig'
  ../scripts/Makefile.include:4: *** O=./builddir/ does not exist.  Stop.
  make: Leaving directory '/home/mhiramat/ksrc/linux/tools/bootconfig'

The O= directory existence check failed because the check script ran in the build target directory instead of the directory where I ran the make command.

To fix that, once change directory to $(PWD) and check O= directory, since the PWD is set to where the make command runs.

Fixes c883122acc0d ("perf tools: Let O= makes handle relative paths")
---
 tools/scripts/Makefile.include |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/scripts/Makefile.include +2 -2
index ded7a950dc40..6d2f3a1b2249 100644
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 ifneq ($(O),)
 ifeq ($(origin O), command line)
-       dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
-       ABSOLUTE_O := $(shell cd $(O) ; pwd)
+       dummy := $(if $(shell cd $(PWD); test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
+       ABSOLUTE_O := $(shell cd $(PWD); cd $(O) ; pwd)
        OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
        COMMAND_O := O=$(ABSOLUTE_O)
 ifeq ($(objtree),)
author maintainer
#12 lore raw

Re: [BUGFIX PATCH] tools: Let O= makes handle a relative path with -C option

Thanks Geert,

So Randy, what you will get if you add "echo $(PWD)" instead of "cd $(PWD)" ? Is that still empty or shows the tools/bootconfig directory?

Thanks,

Quoted 43 lines · On Fri, 6 Mar 2020 08:52:40 +0100 Geert Uytterhoeven <[email protected]>…

CC +kbuild, -stable

Quoted 40 lines · Masami Hiramatsu

When I compiled tools/bootconfig from top directory with -C option, the O= option didn't work correctly if I passed a relative path.

  $ make O=./builddir/ -C tools/bootconfig/
  make: Entering directory '/home/mhiramat/ksrc/linux/tools/bootconfig'
  ../scripts/Makefile.include:4: *** O=./builddir/ does not exist.  Stop.
  make: Leaving directory '/home/mhiramat/ksrc/linux/tools/bootconfig'

The O= directory existence check failed because the check script ran in the build target directory instead of the directory where I ran the make command.

To fix that, once change directory to $(PWD) and check O= directory, since the PWD is set to where the make command runs.

Fixes c883122acc0d ("perf tools: Let O= makes handle relative paths")
---
 tools/scripts/Makefile.include |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/scripts/Makefile.include +2 -2
index ded7a950dc40..6d2f3a1b2249 100644
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 ifneq ($(O),)
 ifeq ($(origin O), command line)
-       dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
-       ABSOLUTE_O := $(shell cd $(O) ; pwd)
+       dummy := $(if $(shell cd $(PWD); test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
+       ABSOLUTE_O := $(shell cd $(PWD); cd $(O) ; pwd)
        OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
        COMMAND_O := O=$(ABSOLUTE_O)
 ifeq ($(objtree),)
Signature · 1 line
Masami Hiramatsu <[email protected]>
#13 lore raw

Re: [BUGFIX PATCH] tools: Let O= makes handle a relative path with -C option

Quoted 6 lines · Masami Hiramatsu

Thanks Geert,

So Randy, what you will get if you add "echo $(PWD)" instead of "cd $(PWD)" ? Is that still empty or shows the tools/bootconfig directory?

Thanks,

OK, in these lines:
+ dummy := $(if $(shell cd $(PWD); test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
+ ABSOLUTE_O := $(shell cd $(PWD); cd $(O) ; pwd)

I changed both "cd $(PWD)" to "echo $(PWD)" and did

$ make O=BUILD -C tools/bootconfig/

and this is the build log:

make: Entering directory '/home/rdunlap/lnx/next/linux-next-20200306/tools/bootconfig' cc ../../lib/bootconfig.c main.c -Wall -g -I./include -o bootconfig
make: Leaving directory '/home/rdunlap/lnx/next/linux-next-20200306/tools/bootconfig'

Does that help?

Thanks.

Quoted 48 lines
Quoted 43 lines · On Fri, 6 Mar 2020 08:52:40 +0100 Geert Uytterhoeven <[email protected]>…

CC +kbuild, -stable

Quoted 40 lines · Masami Hiramatsu

When I compiled tools/bootconfig from top directory with -C option, the O= option didn't work correctly if I passed a relative path.

  $ make O=./builddir/ -C tools/bootconfig/
  make: Entering directory '/home/mhiramat/ksrc/linux/tools/bootconfig'
  ../scripts/Makefile.include:4: *** O=./builddir/ does not exist.  Stop.
  make: Leaving directory '/home/mhiramat/ksrc/linux/tools/bootconfig'

The O= directory existence check failed because the check script ran in the build target directory instead of the directory where I ran the make command.

To fix that, once change directory to $(PWD) and check O= directory, since the PWD is set to where the make command runs.

Fixes c883122acc0d ("perf tools: Let O= makes handle relative paths")
---
 tools/scripts/Makefile.include |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/scripts/Makefile.include +2 -2
index ded7a950dc40..6d2f3a1b2249 100644
@@ -1,8 +1,8 @@
 # SPDX-License-Identifier: GPL-2.0
 ifneq ($(O),)
 ifeq ($(origin O), command line)
-       dummy := $(if $(shell test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
-       ABSOLUTE_O := $(shell cd $(O) ; pwd)
+       dummy := $(if $(shell cd $(PWD); test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
+       ABSOLUTE_O := $(shell cd $(PWD); cd $(O) ; pwd)
        OUTPUT := $(ABSOLUTE_O)/$(if $(subdir),$(subdir)/)
        COMMAND_O := O=$(ABSOLUTE_O)
 ifeq ($(objtree),)
Signature · 2 lines
~Randy
Reported-by: Randy Dunlap <[email protected]>
author maintainer
#14 lore raw

Re: [BUGFIX PATCH] tools: Let O= makes handle a relative path with -C option

Quoted 15 lines · On Fri, 6 Mar 2020 08:26:43 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 6 lines · Masami Hiramatsu

Thanks Geert,

So Randy, what you will get if you add "echo $(PWD)" instead of "cd $(PWD)" ? Is that still empty or shows the tools/bootconfig directory?

Thanks,

OK, in these lines:

tools/scripts/Makefile.include +2 -0
+       dummy := $(if $(shell cd $(PWD); test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
+       ABSOLUTE_O := $(shell cd $(PWD); cd $(O) ; pwd)

I changed both "cd $(PWD)" to "echo $(PWD)" and did

$ make O=BUILD -C tools/bootconfig/
Quoted 8 lines

and this is the build log:

make: Entering directory '/home/rdunlap/lnx/next/linux-next-20200306/tools/bootconfig' cc ../../lib/bootconfig.c main.c -Wall -g -I./include -o bootconfig
make: Leaving directory '/home/rdunlap/lnx/next/linux-next-20200306/tools/bootconfig'

Does that help?

Hmm, did you apply "[PATCH 1/2] bootconfig: Support O=<builddir> option" too?

Also, I found this is not enough for perf. perf does more tricky thing in its Makefile.

Thank you,

Signature · 1 line
Masami Hiramatsu <[email protected]>
#15 lore raw

Re: [BUGFIX PATCH] tools: Let O= makes handle a relative path with -C option

Quoted 20 lines · Masami Hiramatsu
Quoted 17 lines · On Fri, 6 Mar 2020 08:26:43 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 6 lines · Masami Hiramatsu

Thanks Geert,

So Randy, what you will get if you add "echo $(PWD)" instead of "cd $(PWD)" ? Is that still empty or shows the tools/bootconfig directory?

Thanks,

OK, in these lines:

tools/scripts/Makefile.include +2 -0
+       dummy := $(if $(shell cd $(PWD); test -d $(O) || echo $(O)),$(error O=$(O) does not exist),)
+       ABSOLUTE_O := $(shell cd $(PWD); cd $(O) ; pwd)

I changed both "cd $(PWD)" to "echo $(PWD)" and did

$ make O=BUILD -C tools/bootconfig/

and this is the build log:

Quoted 8 lines
Quoted 6 lines

make: Entering directory '/home/rdunlap/lnx/next/linux-next-20200306/tools/bootconfig' cc ../../lib/bootconfig.c main.c -Wall -g -I./include -o bootconfig
make: Leaving directory '/home/rdunlap/lnx/next/linux-next-20200306/tools/bootconfig'

Does that help?

Hmm, did you apply "[PATCH 1/2] bootconfig: Support O=<builddir> option" too?

oh crud. nope. Sorry about that.

Building bootconfig with O=BUILD is now working.

Thanks for your time and patience.

Quoted 1 line

Also, I found this is not enough for perf. perf does more tricky thing in its Makefile.

Ack.

Signature · 1 line
~Randy
#16 lore raw

Re: [BUGFIX PATCH] tools: Let O= makes handle a relative path with -C option

In reply to Geert Uytterhoeven
Quoted 1 line · On Fri, 6 Mar 2020 08:52:40 +0100 Geert Uytterhoeven <[email protected]>…

CC +kbuild, -stable

Thank you, as these are kbuild specific changes and not bootconfig (as building anything in tools doesn't work here with top level O= command).

Masami, any patches you send for this, they should go to the kbuild maintainers.

-- Steve

#17 lore raw

Re: [PATCH 1/2] bootconfig: Support O=<builddir> option

In reply to Randy Dunlap

Hi Randy,

Quoted 24 lines · Randy Dunlap
Quoted 23 lines · Steven Rostedt
Quoted 20 lines · On Wed, 4 Mar 2020 15:04:43 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 3 lines · Masami Hiramatsu

Support O=<builddir> option to build bootconfig tool in the other directory. As same as other tools, if you specify O=<builddir>, bootconfig command is build under <builddir>.

Hm. If I use

$ make O=~/tmp -C tools/bootconfig

that works: it builds bootconfig in ~/tmp.

OTOH, if I sit at the top of the kernel source tree and I enter

$ mkdir builddir
$ make O=builddir -C tools/bootconfig

I get this:
make: Entering directory '/home/rdunlap/lnx/next/linux-next-20200304/tools/bootconfig' ../scripts/Makefile.include:4: *** O=builddir does not exist. Stop.
make: Leaving directory '/home/rdunlap/lnx/next/linux-next-20200304/tools/bootconfig'

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

so it looks like tools/scripts/Makefile.include doesn't handle this case correctly (which is how I do all of my builds).

Do you build perf that way?

No. It should also be fixed.

There are lots of issues when (cross)building the tools and selftest with O=. I tried to fix some of them a while ago, but I lost interest.
https://lore.kernel.org/lkml/[email protected]/

The only thing you can rely on when (cross)building with O=, is the kernel itself ;-)

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#18 lore raw

Re: [PATCH 1/2] bootconfig: Support O=<builddir> option

Quoted 33 lines · Geert Uytterhoeven

Hi Randy,

Quoted 30 lines · Randy Dunlap
Quoted 28 lines · Steven Rostedt
Quoted 15 lines · On Wed, 4 Mar 2020 15:04:43 -0800 Randy Dunlap <[email protected]> wrote:
Quoted 3 lines · Masami Hiramatsu

Support O=<builddir> option to build bootconfig tool in the other directory. As same as other tools, if you specify O=<builddir>, bootconfig command is build under <builddir>.

Hm. If I use

$ make O=~/tmp -C tools/bootconfig

that works: it builds bootconfig in ~/tmp.

OTOH, if I sit at the top of the kernel source tree and I enter

$ mkdir builddir
$ make O=builddir -C tools/bootconfig
Quoted 8 lines

I get this:
make: Entering directory '/home/rdunlap/lnx/next/linux-next-20200304/tools/bootconfig' ../scripts/Makefile.include:4: *** O=builddir does not exist. Stop.
make: Leaving directory '/home/rdunlap/lnx/next/linux-next-20200304/tools/bootconfig'

so it looks like tools/scripts/Makefile.include doesn't handle this case correctly (which is how I do all of my builds).

Do you build perf that way?

Quoted 8 lines
Quoted 1 line

No. It should also be fixed.

There are lots of issues when (cross)building the tools and selftest with O=. I tried to fix some of them a while ago, but I lost interest.
https://lore.kernel.org/lkml/[email protected]/

The only thing you can rely on when (cross)building with O=, is the kernel itself ;-)

Yeah, oh well. I'm not ready to just give up on it though.

thanks.

Signature · 1 line
~Randy
author maintainer
#19 lore raw

PATCH 2/2 tools/bootconfig: Show line and column in parse error

In reply to Masami Hiramatsu

Show line and column when we got a parse error in bootconfig tool. Current lib/bootconfig shows the parse error with byte offset, but that is not human readable.
This makes xbc_init() not showing error message itself but able to pass the error message and position to caller, so that the caller can decode it and show the error message with line number and columns.

With this patch, bootconfig tool shows an error with line:column as below.

  $ cat samples/bad-dotword.bconf
  # do not start keyword with .
  key {
    .word = 1
  }
  $ ./bootconfig -a samples/bad-dotword.bconf initrd
  Parse Error: Invalid keyword at 3:3
---
 include/linux/bootconfig.h |    3 ++-
 init/main.c                |   14 ++++++++++----
 lib/bootconfig.c           |   35 ++++++++++++++++++++++++++---------
 tools/bootconfig/main.c    |   35 +++++++++++++++++++++++++++++++----
 4 files changed, 69 insertions(+), 18 deletions(-)
include/linux/bootconfig.h +2 -1
index d11e183fcb54..9903088891fa 100644
@@ -216,7 +216,8 @@ static inline int __init xbc_node_compose_key(struct xbc_node *node,
 }
 
 /* XBC node initializer */
-int __init xbc_init(char *buf);
+int __init xbc_init(char *buf, const char **emsg, int *epos);
+
 
 /* XBC cleanup data structures */
 void __init xbc_destroy_all(void);
init/main.c +10 -4
index c9b1ee6bbb8d..c749da3ce070 100644
@@ -353,6 +353,8 @@ static int __init bootconfig_params(char *param, char *val,
 static void __init setup_boot_config(const char *cmdline)
 {
 	static char tmp_cmdline[COMMAND_LINE_SIZE] __initdata;
+	const char *msg;
+	int pos;
 	u32 size, csum;
 	char *data, *copy;
 	u32 *hdr;
@@ -400,10 +402,14 @@ static void __init setup_boot_config(const char *cmdline)
 	memcpy(copy, data, size);
 	copy[size] = '\0';
 
-	ret = xbc_init(copy);
-	if (ret < 0)
-		pr_err("Failed to parse bootconfig\n");
-	else {
+	ret = xbc_init(copy, &msg, &pos);
+	if (ret < 0) {
+		if (pos < 0)
+			pr_err("Failed to init bootconfig: %s.\n", msg);
+		else
+			pr_err("Failed to parse bootconfig: %s at %d.\n",
+				msg, pos);
+	} else {
 		pr_info("Load bootconfig: %d bytes %d nodes\n", size, ret);
 		/* keys starting with "kernel." are passed via cmdline */
 		extra_command_line = xbc_make_cmdline("kernel");
lib/bootconfig.c +26 -9
index ec3ce7fd299f..912ef4921398 100644
@@ -29,12 +29,14 @@ static int xbc_node_num __initdata;
 static char *xbc_data __initdata;
 static size_t xbc_data_size __initdata;
 static struct xbc_node *last_parent __initdata;
+static const char *xbc_err_msg __initdata;
+static int xbc_err_pos __initdata;
 
 static int __init xbc_parse_error(const char *msg, const char *p)
 {
-	int pos = p - xbc_data;
+	xbc_err_msg = msg;
+	xbc_err_pos = (int)(p - xbc_data);
 
-	pr_err("Parse error at pos %d: %s\n", pos, msg);
 	return -EINVAL;
 }
 
@@ -738,33 +740,44 @@ void __init xbc_destroy_all(void)
 /**
  * xbc_init() - Parse given XBC file and build XBC internal tree
  * @buf: boot config text
+ * @emsg: A pointer of const char * to store the error message
+ * @epos: A pointer of int to store the error position
  *
  * This parses the boot config text in @buf. @buf must be a
  * null terminated string and smaller than XBC_DATA_MAX.
  * Return the number of stored nodes (>0) if succeeded, or -errno
  * if there is any error.
+ * In error cases, @emsg will be updated with an error message and
+ * @epos will be updated with the error position which is the byte offset
+ * of @buf. If the error is not a parser error, @epos will be -1.
  */
-int __init xbc_init(char *buf)
+int __init xbc_init(char *buf, const char **emsg, int *epos)
 {
 	char *p, *q;
 	int ret, c;
 
+	if (epos)
+		*epos = -1;
+
 	if (xbc_data) {
-		pr_err("Error: bootconfig is already initialized.\n");
+		if (emsg)
+			*emsg = "Bootconfig is already initialized";
 		return -EBUSY;
 	}
 
 	ret = strlen(buf);
 	if (ret > XBC_DATA_MAX - 1 || ret == 0) {
-		pr_err("Error: Config data is %s.\n",
-			ret ? "too big" : "empty");
+		if (emsg)
+			*emsg = ret ? "Config data is too big" :
+				"Config data is empty";
 		return -ERANGE;
 	}
 
 	xbc_nodes = memblock_alloc(sizeof(struct xbc_node) * XBC_NODE_MAX,
 				   SMP_CACHE_BYTES);
 	if (!xbc_nodes) {
-		pr_err("Failed to allocate memory for bootconfig nodes.\n");
+		if (emsg)
+			*emsg = "Failed to allocate bootconfig nodes";
 		return -ENOMEM;
 	}
 	memset(xbc_nodes, 0, sizeof(struct xbc_node) * XBC_NODE_MAX);
@@ -814,9 +827,13 @@ int __init xbc_init(char *buf)
 	if (!ret)
 		ret = xbc_verify_tree();
 
-	if (ret < 0)
+	if (ret < 0) {
+		if (epos)
+			*epos = xbc_err_pos;
+		if (emsg)
+			*emsg = xbc_err_msg;
 		xbc_destroy_all();
-	else
+	} else
 		ret = xbc_node_num;
 
 	return ret;
tools/bootconfig/main.c +31 -4
index a9b97814d1a9..16b9a420e6fd 100644
@@ -130,6 +130,7 @@ int load_xbc_from_initrd(int fd, char **buf)
 	int ret;
 	u32 size = 0, csum = 0, rcsum;
 	char magic[BOOTCONFIG_MAGIC_LEN];
+	const char *msg;
 
 	ret = fstat(fd, &stat);
 	if (ret < 0)
@@ -182,10 +183,12 @@ int load_xbc_from_initrd(int fd, char **buf)
 		return -EINVAL;
 	}
 
-	ret = xbc_init(*buf);
+	ret = xbc_init(*buf, &msg, NULL);
 	/* Wrong data */
-	if (ret < 0)
+	if (ret < 0) {
+		pr_err("parse error: %s.\n", msg);
 		return ret;
+	}
 
 	return size;
 }
@@ -244,11 +247,34 @@ int delete_xbc(const char *path)
 	return ret;
 }
 
+static void show_xbc_error(const char *data, const char *msg, int pos)
+{
+	int lin = 1, col, i;
+
+	if (pos < 0) {
+		pr_err("Error: %s.\n", msg);
+		return;
+	}
+
+	/* Note that pos starts from 0 but lin and col should start from 1. */
+	col = pos + 1;
+	for (i = 0; i < pos; i++) {
+		if (data[i] == '\n') {
+			lin++;
+			col = pos - i;
+		}
+	}
+	pr_err("Parse Error: %s at %d:%d\n", msg, lin, col);
+
+}
+
 int apply_xbc(const char *path, const char *xbc_path)
 {
 	u32 size, csum;
 	char *buf, *data;
 	int ret, fd;
+	const char *msg;
+	int pos;
 
 	ret = load_xbc_file(xbc_path, &buf);
 	if (ret < 0) {
@@ -267,11 +293,12 @@ int apply_xbc(const char *path, const char *xbc_path)
 	*(u32 *)(data + size + 4) = csum;
 
 	/* Check the data format */
-	ret = xbc_init(buf);
+	ret = xbc_init(buf, &msg, &pos);
 	if (ret < 0) {
-		pr_err("Failed to parse %s: %d\n", xbc_path, ret);
+		show_xbc_error(data, msg, pos);
 		free(data);
 		free(buf);
+
 		return ret;
 	}
 	printf("Apply %s to %s\n", xbc_path, path);