Skip to contentSkip to conversation

barebox on x86

PATCH Stefan Reinauer 4 participants 10 messages Aug 31, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

here's some initial work on getting barebox working on x86 (again?).

The patch is very ugly, and it makes some assumptions on me using Darwin/Mac OS X to compile barebox.
What kind of becomes clear though, is that there is no clear distinction between which set of headers are used for the user space utilities and which set of headers are used for the barebox binary. I think that's the reason why barebox features an include/linux directory which seems to duplicate about half of what Linux usually has in there, but more than barebox uses (or should use, ftm).

With the attached patch I get as far as the linking stage.

Quoted 1 line

i386-elf-ld -Map barebox.map -o barebox -T arch/x86/lib/barebox.lds

--start-group common/built-in.o drivers/built-in.o commands/built-in.o lib/built-in.o net/built-in.o fs/built-in.o arch/x86/boards/x86_generic/built-in.o arch/x86/mach-i386/built-in.o arch/x86/lib/built-in.o arch/x86/boot/built-in.o --end-group

When I define CONFIG_X86_HDBOOT
I get:

i386-elf-ld: barebox section .initcall.8' will not fit in region mbr'
i386-elf-ld: section .initcall.8 loaded at [0000000000000400,000000000000040b] overlaps section .bootstrapping loaded at [0000000000000400,00000000000008e7]
i386-elf-ld: region `mbr' overflowed by 12 bytes

If I choose "native", I get

arch/x86/lib/barebox.lds:124: nonconstant expression for load base

Since barebox is not really specialized in doing complex hardware initialization like it's needed on x86 machines, and coreboot is not really specialized in providing any kind of user interface I would like to work on making barebox available as a coreboot payload. For that I need to produce an ELF file that does no BIOS calls because coreboot is not a BIOS or UEFI but only does the most necessary hardware initialization on x86 systems.

Any hints and help is highly appreciated.

Best regards,
Stefan

Signature · 5 lines
coresystems GmbH • Brahmsstr. 16 • D-79104 Freiburg i. Br.
      Tel.: +49 761 7668825 • Fax: +49 761 7664613
Email: [email protected]  • http://www.coresystems.de/
Registergericht: Amtsgericht Freiburg • HRB 7656
Geschäftsführer: Stefan Reinauer • Ust-IdNr.: DE245674866

commit 972ad58107b54e94a19eba37158572ce827de489

Author: Stefan Reinauer <stepan@[email protected]>
Date:   Tue Aug 31 12:13:09 2010 +0200

inital work to get x86 port back to life again

Makefile +4 -4
index 62053c8..6235784 100644
@@ -834,15 +834,15 @@ define check-symlink
 endef
 
 # We create the target directory of the symlink if it does
-# not exist so the test in chack-symlink works and we have a
+# not exist so the test in check-symlink works and we have a
 # directory for generated filesas used by some architectures.
 define create-symlink
 	if [ ! -L include/asm ]; then					\
 			echo '  SYMLINK $@ -> include/asm-$(SRCARCH)';	\
-			if [ ! -d include/asm-$(SRCARCH) ]; then	\
-				mkdir -p include/asm-$(SRCARCH);	\
+			if [ ! -d arch/$(SRCARCH)/include/asm ]; then	\
+				mkdir -p arch/$(SRCARCH)/include/asm;	\
 			fi;						\
-			ln -fsn asm-$(SRCARCH) $@;			\
+			ln -fsn ../arch/$(SRCARCH)/include/asm $@;	\
 	fi
 endef
 
arch/x86/include/asm/types.h +3 -0
index 17c5fd7..23f942e 100644
@@ -33,10 +33,13 @@ typedef unsigned int __u32;
 typedef __signed__ long long __s64;
 typedef unsigned long long __u64;
 
+typedef signed char s8;
 typedef unsigned char u8;
 
+typedef signed short s16;
 typedef unsigned short u16;
 
+typedef signed int s32;
 typedef unsigned int u32;
 
 #endif /* __ASSEMBLY__ */
commands/Kconfig +1 -0
index 57c9b75..9ee9c78 100644
@@ -244,6 +244,7 @@ config CMD_BOOTU
 config CMD_LINUX16
 	tristate
 	default y if X86
+	depends on BROKEN
 	prompt "linux16"
 	help
 	  Compile the linux16 command to be able to boot bzImages
include/envfs.h +18 -0
index b5849d9..e3e7fbd 100644
@@ -1,7 +1,25 @@
 #ifndef _ENVFS_H
 #define _ENVFS_H
 
+#ifndef __LINUX__
+#define __BIG_ENDIAN 0
+#define __LITTLE_ENDIAN 1
+#ifdef __i386__
+#define __BYTE_ORDER __LITTLE_ENDIAN
+#else
+#define __BYTE_ORDER __BIG_ENDIAN
+#endif
+typedef unsigned long ulong;
+typedef uint32_t __u32;
+#define bswap_32(x) \
+	((__u32)( \
+		(((__u32)(x) & (__u32)0x000000ffUL) << 24) | \
+		(((__u32)(x) & (__u32)0x0000ff00UL) <<  8) | \
+		(((__u32)(x) & (__u32)0x00ff0000UL) >>  8) | \
+		(((__u32)(x) & (__u32)0xff000000UL) >> 24) ))
+#else
 #include <asm/byteorder.h>
+#endif
 
 #define ENVFS_MAGIC		    0x798fba79	/* some random number */
 #define ENVFS_INODE_MAGIC	0x67a8c78d
include/image.h +6 -1
index 13d0303..bc11e7a 100644
@@ -31,7 +31,12 @@
 #ifndef __IMAGE_H__
 #define __IMAGE_H__
 
+#ifndef __KERNEL__
+#include <stdint.h>
+typedef unsigned long ulong;
+#else
 #include <linux/types.h>
+#endif
 
 /*
  * Operating System Codes
@@ -84,7 +89,7 @@
 #define IH_CPU IH_CPU_PPC
 #elif defined(__ARM__)
 #define IH_CPU IH_CPU_ARM
-#elif defined(__I386__) || defined(__x86_64__)
+#elif defined(__I386__) || defined(__i386__) || defined(__x86_64__)
 #define IH_CPU IH_CPU_I386
 #elif defined(__mips__)
 #define IH_CPU IH_CPU_MIPS
scripts/mod/elf.h new file +2637 -0

2,637 lines not on this page · raw message

scripts/mod/mk_elfconfig.c +1 -1
index db3881f..ddd2654 100644
@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <elf.h>
+#include "elf.h"
 
 int
 main(int argc, char **argv)
scripts/mod/modpost.h +1 -1
index 4156dd3..8d0f793 100644
@@ -7,7 +7,7 @@
 #include <sys/mman.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include <elf.h>
+#include "elf.h"
 
 #include "elfconfig.h"
 
scripts/setupmbr/arch.h +11 -0
index a720dfe..65b909f 100644
@@ -1,6 +1,17 @@
 
 /* we need the one from the host */
+#ifdef __APPLE__
+#define __ASSERT_VOID_CAST (void)
+#define __BIG_ENDIAN	0
+#define __LITTLE_ENDIAN	1
+#ifdef __i386__
+# define __BYTE_ORDER __LITTLE_ENDIAN
+#else
+# define __BYTE_ORDER __BIG_ENDIAN
+#endif
+#else
 #include <endian.h>
+#endif
 #include <stdint.h>
 
 /* Byte-orders.  */

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw
Quoted 13 lines · Stefan Reinauer

Hi,

here's some initial work on getting barebox working on x86 (again?).

The patch is very ugly, and it makes some assumptions on me using Darwin/Mac OS X to compile barebox.
What kind of becomes clear though, is that there is no clear distinction between which set of headers are used for the user space utilities and which set of headers are used for the barebox binary. I think that's the reason why barebox features an include/linux directory which seems to duplicate about half of what Linux usually has in there, but more than barebox uses (or should use, ftm).

Quoted 1 line

With the attached patch I get as far as the linking stage.

why do you touch it?
barebox is self content so I do not understand why you do such modificaton specially uf we are supposed to do crosscompile

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#2 lore raw

Hi Jean-Christophe,

Quoted 1 line · Jean-Christophe PLAGNIOL-VILLARD

why do you touch it?

Sorry, touch _what_ in particular?

Quoted 3 lines

barebox is self content so I do not understand why you do such modificaton specially uf we are supposed to do crosscompile

Unfortunately that assumption is wrong, at least for the x86 target. Almost all my patch does is trying to fix exactly that (along with dropping the requirement to use Linux on the host side)

And, yes, I am using an i386-elf- cross compiler.

Best regards,
Stefan

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#3 lore raw
Quoted 6 lines · Stefan Reinauer

Hi Jean-Christophe,

Quoted 1 line · Jean-Christophe PLAGNIOL-VILLARD

why do you touch it?

Sorry, touch _what_ in particular?

Quoted 8 lines
Quoted 3 lines

barebox is self content so I do not understand why you do such modificaton specially uf we are supposed to do crosscompile

Unfortunately that assumption is wrong, at least for the x86 target. Almost all my patch does is trying to fix exactly that (along with dropping the requirement to use Linux on the host side)

And, yes, I am using an i386-elf- cross compiler.

you need a linux toolchains and it's build correctly I build it on MacOS too

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw

Hi Jean-Christophe,

Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 9 lines · Stefan Reinauer

Hi Jean-Christophe,

Quoted 1 line · Jean-Christophe PLAGNIOL-VILLARD

why do you touch it?

Sorry, touch _what_ in particular?

Quoted 3 lines

barebox is self content so I do not understand why you do such modificaton specially uf we are supposed to do crosscompile

Quoted 6 lines
Quoted 5 lines

Unfortunately that assumption is wrong, at least for the x86 target. Almost all my patch does is trying to fix exactly that (along with dropping the requirement to use Linux on the host side)

And, yes, I am using an i386-elf- cross compiler.

you need a linux toolchains and it's build correctly

So, barebox needs glibc and a Linux kernel to build? Hm. Then consider my patch fixing that problem. Almost. With my patch it's self-content. But the linking problems are still open. Do you have any hint on those, too, maybe?

Quoted 2 lines

I build it on MacOS too

How did you overcome the programs in scripts/ using Linux system headers that are not there with HOSTCC (even with a Linux cross toolchain)?

Quoted 3 lines

Best Regards,
J.

Best regards,
Stefan

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#5 lore raw
Quoted 18 lines · Stefan Reinauer

Hi Jean-Christophe,

Quoted 15 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 14 lines · Stefan Reinauer

Hi Jean-Christophe,

Quoted 1 line · Jean-Christophe PLAGNIOL-VILLARD

why do you touch it?

Sorry, touch _what_ in particular?

Quoted 2 lines

barebox is self content so I do not understand why you do such modificaton specially uf we are supposed to do crosscompile

Unfortunately that assumption is wrong, at least for the x86 target. Almost all my patch does is trying to fix exactly that (along with dropping the requirement to use Linux on the host side)

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

And, yes, I am using an i386-elf- cross compiler.

you need a linux toolchains and it's build correctly

So, barebox needs glibc and a Linux kernel to build?

No. Everything needed comes with the barebox sources. Else it is a bug.

jbe

Signature · 9 lines
Pengutronix e.K.                              | Juergen Beisert             |
Linux Solutions for Science and Industry      | Phone: +49-8766-939 228     |
Vertretung Sued/Muenchen, Germany             | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686              | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw
In reply to Stefan Reinauer
Quoted 25 lines · Stefan Reinauer

Hi Jean-Christophe,

Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 9 lines · Stefan Reinauer

Hi Jean-Christophe,

Quoted 1 line · Jean-Christophe PLAGNIOL-VILLARD

why do you touch it?

Sorry, touch _what_ in particular?

Quoted 3 lines

barebox is self content so I do not understand why you do such modificaton specially uf we are supposed to do crosscompile

Quoted 6 lines
Quoted 5 lines

Unfortunately that assumption is wrong, at least for the x86 target. Almost all my patch does is trying to fix exactly that (along with dropping the requirement to use Linux on the host side)

And, yes, I am using an i386-elf- cross compiler.

you need a linux toolchains and it's build correctly

So, barebox needs glibc and a Linux kernel to build? Hm. Then consider my patch fixing that problem. Almost. With my patch it's self-content. But the linking problems are still open. Do you have any hint on those, too, maybe?

Quoted 4 lines
Quoted 2 lines

I build it on MacOS too

How did you overcome the programs in scripts/ using Linux system headers that are not there with HOSTCC (even with a Linux cross toolchain)?

the tool chain provive it and it's the same for compiling the kernel on MacOS

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#7 lore raw
Quoted 5 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 4 lines
Quoted 2 lines

I build it on MacOS too

How did you overcome the programs in scripts/ using Linux system headers that are not there with HOSTCC (even with a Linux cross toolchain)?

the tool chain provive it and it's the same for compiling the kernel on MacOS

Hm... maybe I need a different host toolchain on MacOS then?

I am using Xcode 3.2.2, i.e. gcc version 4.2.1 (Apple Inc. build 5659) for the host parts - that's those not intended for the target but for running on MacOS during the build process, like setupmbr, mk_elfconfig and modpost. And that toolchain does for example not come with an elf.h header file (mostly because ELF is not used on MacOS). For obvious reasons, the target compiler's (cross compiler) include files are taboo for compiling the host programs.

Best regards,
Stefan

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#8 lore raw
In reply to Stefan Reinauer

Hi Stefan,

Quoted 20 lines · Stefan Reinauer

here's some initial work on getting barebox working on x86 (again?).

The patch is very ugly, and it makes some assumptions on me using Darwin/Mac OS X to compile barebox.
What kind of becomes clear though, is that there is no clear distinction between which set of headers are used for the user space utilities and which set of headers are used for the barebox binary. I think that's the reason why barebox features an include/linux directory which seems to duplicate about half of what Linux usually has in there, but more than barebox uses (or should use, ftm).

With the attached patch I get as far as the linking stage.

Quoted 1 line

i386-elf-ld -Map barebox.map -o barebox -T arch/x86/lib/barebox.lds

--start-group common/built-in.o drivers/built-in.o commands/built-in.o lib/built-in.o net/built-in.o fs/built-in.o arch/x86/boards/x86_generic/built-in.o arch/x86/mach-i386/built-in.o arch/x86/lib/built-in.o arch/x86/boot/built-in.o --end-group

Quoted 8 lines

When I define CONFIG_X86_HDBOOT
I get:

i386-elf-ld: barebox section .initcall.8' will not fit in region mbr'
i386-elf-ld: section .initcall.8 loaded at [0000000000000400,000000000000040b] overlaps section .bootstrapping loaded at [0000000000000400,00000000000008e7]
i386-elf-ld: region `mbr' overflowed by 12 bytes

-> MBR -> 16 Bit boot loader.

Quoted 3 lines

If I choose "native", I get

arch/x86/lib/barebox.lds:124: nonconstant expression for load base

The 'native' case is not finished yet. It does not use any 16 bit code nor BIOS calls. But need adaptions to get some vital information about the system (for example memory size).

Quoted 7 lines

Since barebox is not really specialized in doing complex hardware initialization like it's needed on x86 machines, and coreboot is not really specialized in providing any kind of user interface I would like to work on making barebox available as a coreboot payload. For that I need to produce an ELF file that does no BIOS calls because coreboot is not a BIOS or UEFI but only does the most necessary hardware initialization on x86 systems.

The 'native' case is the correct direction to get it work with coreboot.

jbe

Signature · 9 lines
Pengutronix e.K.                              | Juergen Beisert             |
Linux Solutions for Science and Industry      | Phone: +49-8766-939 228     |
Vertretung Sued/Muenchen, Germany             | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686              | http://www.pengutronix.de/  |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw
Quoted 25 lines · Juergen Beisert

Hi Stefan,

Quoted 22 lines · Stefan Reinauer

here's some initial work on getting barebox working on x86 (again?).

The patch is very ugly, and it makes some assumptions on me using Darwin/Mac OS X to compile barebox.
What kind of becomes clear though, is that there is no clear distinction between which set of headers are used for the user space utilities and which set of headers are used for the barebox binary. I think that's the reason why barebox features an include/linux directory which seems to duplicate about half of what Linux usually has in there, but more than barebox uses (or should use, ftm).

With the attached patch I get as far as the linking stage.

Quoted 1 line

i386-elf-ld -Map barebox.map -o barebox -T arch/x86/lib/barebox.lds

--start-group common/built-in.o drivers/built-in.o commands/built-in.o lib/built-in.o net/built-in.o fs/built-in.o arch/x86/boards/x86_generic/built-in.o arch/x86/mach-i386/built-in.o arch/x86/lib/built-in.o arch/x86/boot/built-in.o --end-group

When I define CONFIG_X86_HDBOOT
I get:

Quoted 6 lines
Quoted 5 lines

i386-elf-ld: barebox section .initcall.8' will not fit in region mbr'
i386-elf-ld: section .initcall.8 loaded at [0000000000000400,000000000000040b] overlaps section .bootstrapping loaded at [0000000000000400,00000000000008e7]
i386-elf-ld: region `mbr' overflowed by 12 bytes

-> MBR -> 16 Bit boot loader.

Yes, I wanted to compile the "known working" version first, but it seems to choke on the "late_initcall" mechanism somehow.

Quoted 6 lines
Quoted 3 lines

If I choose "native", I get

arch/x86/lib/barebox.lds:124: nonconstant expression for load base

The 'native' case is not finished yet. It does not use any 16 bit code nor BIOS calls. But need adaptions to get some vital information about the system (for example memory size).

Ok, will try to figure this one out.

Quoted 8 lines
Quoted 7 lines

Since barebox is not really specialized in doing complex hardware initialization like it's needed on x86 machines, and coreboot is not really specialized in providing any kind of user interface I would like to work on making barebox available as a coreboot payload. For that I need to produce an ELF file that does no BIOS calls because coreboot is not a BIOS or UEFI but only does the most necessary hardware initialization on x86 systems.

The 'native' case is the correct direction to get it work with coreboot.

Great! That's what I assumed. Thanks for the input.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox