Patchwork pc-bios: build OpenBIOS if possible

login
register
mail settings
Submitter Blue Swirl
Date Feb. 9, 2013, 7:01 p.m.
Message ID <a1f05716c57ccf8cadca10b464de87c0010fefc4.1360436437.git.blauwirbel@gmail.com>
Download mbox | patch
Permalink /patch/219427/
State New
Headers show

Comments

Blue Swirl - Feb. 9, 2013, 7:01 p.m.
Check if xsltproc and Sparc32, Sparc64 and PPC compilers
are available. If found, rebuild OpenBIOS ROMs from submodule.

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
---
A patch to OpenBIOS is also needed to support out of tree build,
just sent to the list.
---
 configure                 |   25 ++++++++++++++++++++++++-
 pc-bios/openbios/Makefile |   29 +++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 1 deletions(-)
 create mode 100644 pc-bios/openbios/Makefile
Michael Tokarev - Feb. 10, 2013, 6:42 a.m.
09.02.2013 23:01, Blue Swirl wrote:
> Check if xsltproc and Sparc32, Sparc64 and PPC compilers
> are available. If found, rebuild OpenBIOS ROMs from submodule.
>
> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
> ---
> A patch to OpenBIOS is also needed to support out of tree build,
> just sent to the list.
[]
> +# OpenBIOS needs xsltproc, and Sparc32, Sparc64 and PPC cross compilers
> +if has xsltproc; then
> +    if has_crossgcc "sparc" -a has_crossgcc "sparc64" -a \
> +        \( has_crossgcc "powerpc" -o  has_crossgcc "ppc" \); then
> +        roms="$roms openbios"
> +    fi
> +fi

Do we need to be able to turn it off?  Or maybe we should just
stop doing this by default (since binaries are already present
in the tarball), but instead suggest user to run `make -C roms'
if [s]he needs/wants these roms to be rebuilt?

I guess this is not a question for this patch but a more general
question.

I dislike rebuilding stuff this way, in particular because current
system may have some outdated (or too new) compiler for that stuff
to produce somehow broken binary, because this way, the resulting
blobs differs from ones in the tarball and comparing in attempt to
find what has changed shows these and makes some noize, -- stuff
like that.


> +++ b/pc-bios/openbios/Makefile
> +config-timestamp: $(SRC_PATH)/roms/openbios/config/scripts/switch-arch
> +	mkdir build || true

That's what `mkdir -p' if for.

Thanks,

/mjt
Blue Swirl - Feb. 10, 2013, 9:32 a.m.
On Sun, Feb 10, 2013 at 6:42 AM, Michael Tokarev <mjt@tls.msk.ru> wrote:
> 09.02.2013 23:01, Blue Swirl wrote:
>>
>> Check if xsltproc and Sparc32, Sparc64 and PPC compilers
>> are available. If found, rebuild OpenBIOS ROMs from submodule.
>>
>> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
>> ---
>> A patch to OpenBIOS is also needed to support out of tree build,
>> just sent to the list.
>
> []
>
>> +# OpenBIOS needs xsltproc, and Sparc32, Sparc64 and PPC cross compilers
>> +if has xsltproc; then
>> +    if has_crossgcc "sparc" -a has_crossgcc "sparc64" -a \
>> +        \( has_crossgcc "powerpc" -o  has_crossgcc "ppc" \); then
>> +        roms="$roms openbios"
>> +    fi
>> +fi
>
>
> Do we need to be able to turn it off?  Or maybe we should just
> stop doing this by default (since binaries are already present
> in the tarball), but instead suggest user to run `make -C roms'
> if [s]he needs/wants these roms to be rebuilt?

We also build optionroms and spapr-rtas automatically, not seabios
though and there's no option to disable/enable those.

I'm not sure why we build those either except to encourage using self
built ROMs instead of the supplied binaries. I think it has more to do
with keeping in line with the spirit of open source rather than any
technical advantages.

>
> I guess this is not a question for this patch but a more general
> question.
>
> I dislike rebuilding stuff this way, in particular because current
> system may have some outdated (or too new) compiler for that stuff
> to produce somehow broken binary, because this way, the resulting
> blobs differs from ones in the tarball and comparing in attempt to
> find what has changed shows these and makes some noize, -- stuff
> like that.

This could also apply to optionroms and spapr-rtas. Clang/LLVM
assembler does not support 16 bit x86 code yet, so we already have a
workaround for that. For OpenBIOS this is also a real concern since
GCC 4.7.0 does not produce working binaries.

>
>
>> +++ b/pc-bios/openbios/Makefile
>>
>> +config-timestamp: $(SRC_PATH)/roms/openbios/config/scripts/switch-arch
>> +       mkdir build || true
>
>
> That's what `mkdir -p' if for.

Thanks, will fix. The directory could be also made by configure.

>
> Thanks,
>
> /mjt
Anthony Liguori - Feb. 11, 2013, 7:50 p.m.
Blue Swirl <blauwirbel@gmail.com> writes:

> On Sun, Feb 10, 2013 at 6:42 AM, Michael Tokarev <mjt@tls.msk.ru> wrote:
>> 09.02.2013 23:01, Blue Swirl wrote:
>>>
>>> Check if xsltproc and Sparc32, Sparc64 and PPC compilers
>>> are available. If found, rebuild OpenBIOS ROMs from submodule.
>>>
>>> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
>>> ---
>>> A patch to OpenBIOS is also needed to support out of tree build,
>>> just sent to the list.
>>
>> []
>>
>>> +# OpenBIOS needs xsltproc, and Sparc32, Sparc64 and PPC cross compilers
>>> +if has xsltproc; then
>>> +    if has_crossgcc "sparc" -a has_crossgcc "sparc64" -a \
>>> +        \( has_crossgcc "powerpc" -o  has_crossgcc "ppc" \); then
>>> +        roms="$roms openbios"
>>> +    fi
>>> +fi
>>
>>
>> Do we need to be able to turn it off?  Or maybe we should just
>> stop doing this by default (since binaries are already present
>> in the tarball), but instead suggest user to run `make -C roms'
>> if [s]he needs/wants these roms to be rebuilt?
>
> We also build optionroms and spapr-rtas automatically, not seabios
> though and there's no option to disable/enable those.

It's all historical I guess.  We should try to build everything we can
and prefer to install that over the binaries that are shipped.

Regards,

Anthony Liguori

> I'm not sure why we build those either except to encourage using self
> built ROMs instead of the supplied binaries. I think it has more to do
> with keeping in line with the spirit of open source rather than any
> technical advantages.
>
>>
>> I guess this is not a question for this patch but a more general
>> question.
>>
>> I dislike rebuilding stuff this way, in particular because current
>> system may have some outdated (or too new) compiler for that stuff
>> to produce somehow broken binary, because this way, the resulting
>> blobs differs from ones in the tarball and comparing in attempt to
>> find what has changed shows these and makes some noize, -- stuff
>> like that.

I don't really think this is a valid argument.  If you have a broken
compiler, then you have bigger concerns then whether the blobs got built
correctly.

Regards,

Anthony Liguori

>
> This could also apply to optionroms and spapr-rtas. Clang/LLVM
> assembler does not support 16 bit x86 code yet, so we already have a
> workaround for that. For OpenBIOS this is also a real concern since
> GCC 4.7.0 does not produce working binaries.
>
>>
>>
>>> +++ b/pc-bios/openbios/Makefile
>>>
>>> +config-timestamp: $(SRC_PATH)/roms/openbios/config/scripts/switch-arch
>>> +       mkdir build || true
>>
>>
>> That's what `mkdir -p' if for.
>
> Thanks, will fix. The directory could be also made by configure.
>
>>
>> Thanks,
>>
>> /mjt

Patch

diff --git a/configure b/configure
index 8789324..918c423 100755
--- a/configure
+++ b/configure
@@ -76,6 +76,20 @@  has() {
     type "$1" >/dev/null 2>&1
 }
 
+# check for cross compile or native tools for arch $1
+has_crossgcc() {
+    if test "$cpu" = "$1"; then
+        return 1
+    fi
+    for ccprefix in "${1}-linux-gnu-" "${1}-linux-" \
+        "${1}-elf-" "${1}-eabi-"; do
+        if has "${1}gcc"; then
+            return 1
+        fi
+    done
+    return 0
+}
+
 # search for an executable in PATH
 path_of() {
     local_command="$1"
@@ -3241,6 +3255,14 @@  if test "$cpu" = "ppc64" -a "$targetos" != "Darwin" ; then
   roms="$roms spapr-rtas"
 fi
 
+# OpenBIOS needs xsltproc, and Sparc32, Sparc64 and PPC cross compilers
+if has xsltproc; then
+    if has_crossgcc "sparc" -a has_crossgcc "sparc64" -a \
+        \( has_crossgcc "powerpc" -o  has_crossgcc "ppc" \); then
+        roms="$roms openbios"
+    fi
+fi
+
 # add pixman flags after all config tests are done
 QEMU_CFLAGS="$QEMU_CFLAGS $pixman_cflags"
 libs_softmmu="$libs_softmmu $pixman_libs"
@@ -4280,7 +4302,7 @@  fi
 
 # build tree in object directory in case the source is not in the current directory
 DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32"
-DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas"
+DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas pc-bios/openbios"
 DIRS="$DIRS roms/seabios roms/vgabios"
 DIRS="$DIRS qapi-generated"
 FILES="Makefile tests/tcg/Makefile qdict-test-data.txt"
@@ -4288,6 +4310,7 @@  FILES="$FILES tests/tcg/cris/Makefile tests/tcg/cris/.gdbinit"
 FILES="$FILES tests/tcg/lm32/Makefile"
 FILES="$FILES pc-bios/optionrom/Makefile pc-bios/keymaps"
 FILES="$FILES pc-bios/spapr-rtas/Makefile"
+FILES="$FILES pc-bios/openbios/Makefile"
 FILES="$FILES roms/seabios/Makefile roms/vgabios/Makefile"
 for bios_file in \
     $source_path/pc-bios/*.bin \
diff --git a/pc-bios/openbios/Makefile b/pc-bios/openbios/Makefile
new file mode 100644
index 0000000..77d0815
--- /dev/null
+++ b/pc-bios/openbios/Makefile
@@ -0,0 +1,29 @@ 
+all: build-all
+# Dummy command so that make thinks it has done something
+	@true
+
+include ../../config-host.mak
+
+.PHONY : all clean build-all
+
+# Avoid polluting sub-make environment, especially MAKEFLAGS causes build to fail
+unexport AS AS_FLAGS CC CFLAGS CPP INCLUDES LD LDFLAGS VERSION SRCDIR ODIR
+unexport HOSTCC HOSTCFLAGS HOSTARCH HOSTINCLUDES TARGET MAKE MAKEFLAGS MFLAGS
+
+build-all: config
+	make -C build build-verbose
+	cp build/obj-sparc32/openbios-builtin.elf ../openbios-sparc32
+	cp build/obj-sparc64/openbios-builtin.elf ../openbios-sparc64
+	cp build/obj-ppc/openbios-qemu.elf ../openbios-ppc
+
+config: config-timestamp
+	@cmp $< $@ >/dev/null 2>&1 || cp $< $@
+
+config-timestamp: $(SRC_PATH)/roms/openbios/config/scripts/switch-arch
+	mkdir build || true
+	cd build && sh $(SRC_PATH)/roms/openbios/config/scripts/switch-arch sparc32 sparc64 ppc
+	touch $@
+
+clean:
+	make -C build $@
+	rm -f config config-timestamp