Raspberry pi support
Based on Leif Lindholm's patches I could go to GRUB console on raspberry pi. The biggest problem is that cache flushing is simply skipped. Another problem is that due to different linux image format linux loader doesn't work. I didn't test grub-install but fed GRUB to uboot using kermit.
Is there any advantage in building armv6 binary by default unless user overrides through TARGET_CFLAGS?
Some of the fixes are to make tools work on amd64
=== modified file 'conf/Makefile.common'
Makefile.common +1 -2
@@ -40,8 +40,7 @@ if COND_arm # Image entry point always in ARM (A32) state - ensure proper functionality if # the rest is built for the Thumb (T32) state. - CFLAGS_PLATFORM += -mthumb-interwork -mno-unaligned-access -mlong-calls - CCASFLAGS_PLATFORM = -Wa,-mimplicit-it=thumb + CFLAGS_PLATFORM += -mthumb-interwork -march=armv6 -mlong-calls LDFLAGS_PLATFORM = -Wl,--wrap=__clear_cache endif
=== modified file 'configure.ac'
configure.ac +1 -1
@@ -717,7 +717,7 @@ fi # Check for libgcc symbols -AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __ucmpdi2 _restgpr_14_x __udivsi3 __umoddi3 __udivdi3 __divsi3 __modsi3 __umodsi3 __moddi3 __divdi3 __ctzdi2 __ctzsi2) +AC_CHECK_FUNCS(__bswapsi2 __bswapdi2 __ashldi3 __ashrdi3 __lshrdi3 __ucmpdi2 _restgpr_14_x __udivsi3 __umoddi3 __udivdi3 __divsi3 __modsi3 __umodsi3 __moddi3 __divdi3 __ctzdi2 __ctzsi2 __aeabi_ulcmp) if test "x$TARGET_APPLE_CC" = x1 ; then CFLAGS="$TARGET_CFLAGS -nostdlib"
=== modified file 'grub-core/kern/arm/dl.c'
kern/arm/dl.c +3 -5
@@ -27,9 +27,6 @@#ifdef GRUB_UTIL # include <grub/util/misc.h> #else -# if !defined(__thumb2__) -# error "Relocations not implemented for A32 ("ARM") instruction set yet!" -# endif grub_err_t reloc_jump24 (grub_uint32_t *addr,Elf32_Addr sym_addr);grub_err_t reloc_thm_call (grub_uint16_t *addr,Elf32_Addr sym_addr);
@@ -169,8 +166,8 @@ }#ifdef GRUB_UTIL -grub_util_info (" relative destination = 0x%08x" , - (unsigned int )target + offset); +grub_util_info (" relative destination = 0x%08lx" , + (unsigned long )target + offset);#endif /* Reassemble instruction word */
@@ -358,6 +355,7 @@return retval; }break ; +case R_ARM_CALL :case R_ARM_JUMP24 : { retval =reloc_jump24 (target, sym_addr);
=== modified file 'grub-core/kern/dl.c'
kern/dl.c +1 -1
@@ -588,7 +588,7 @@ {grub_dprintf ("modules" ,"flushing 0x%lx bytes at %p\n" , (unsigned long ) mod->sz, mod->base); -grub_arch_sync_caches (mod->base, mod->sz); +// grub_arch_sync_caches (mod->base, mod->sz); }/* Load a module from core memory. */
=== modified file 'include/grub/libgcc.h'
grub/libgcc.h +1 -0
@@ -122,4 +122,5 @@void EXPORT_FUNC (__aeabi_uidiv ) (void );void EXPORT_FUNC (__aeabi_uidivmod ) (void );void EXPORT_FUNC (__wrap___clear_cache ) (void *,void *); +void EXPORT_FUNC (__aeabi_ulcmp ) (void );#endif
=== modified file 'include/grub/uboot/api_public.h'
grub/uboot/api_public.h +2 -5
@@ -61,9 +61,6 @@typedef int (*scp_t ) (int ,int *, ...); -typedef grub_uint16_t uint16_t ; -typedef grub_uint32_t uint32_t ; -#define API_SIG_VERSION 1#define API_SIG_MAGIC "UBootAPI"#define API_SIG_MAGLEN 8
@@ -71,8 +68,8 @@struct api_signature {char magic[API_SIG_MAGLEN ];/* magic string */ -uint16_t version;/* API version */ -uint32_t checksum;/* checksum of this sig struct */ +grub_uint16_t version;/* API version */ +grub_uint32_t checksum;/* checksum of this sig struct */ scp_t syscall;/* entry point to the API */ };
=== modified file 'util/grub-mkimagexx.c'
grub-mkimagexx.c +1 -1
@@ -553,7 +553,7 @@case R_ARM_THM_CALL :case R_ARM_THM_JUMP24 : { -grub_util_info (" THM_JUMP24:\ttarget=0x%08x\toffset=(0x%08x)" , (unsigned int ) target, sym_addr); +grub_util_info (" THM_JUMP24:\ttarget=0x%08lx\toffset=(0x%08x)" , (unsigned long ) target, sym_addr); sym_addr -= offset;/* Thumb instructions can be 16-bit aligned */ reloc_thm_call ((grub_uint16_t *) target, sym_addr);
Quoted 4 lines · Vladimir '??-coder/phcoder' Serbinenko
Based on Leif Lindholm's patches I could go to GRUB console on raspberry pi. The biggest problem is that cache flushing is simply skipped. Another problem is that due to different linux image format linux loader doesn't work.
Is this because you're feeding it a uImage?
It is entirely possible to runtime detect the U-Boot signature, and simply skip the header.
Quoted 3 lines
I didn't test grub-install but fed GRUB to uboot using kermit. Is there any advantage in building armv6 binary by default unless user overrides through
TARGET_CFLAGS?
I think it would get messy: the barrier operations supported by ARMv6 are deprecated in ARMv7.
I would suggest an alternative approach, which is to build all of the assembly in "arm" state, and to keep the generic functionality to an ARMv6 subset.
This would then have to be done in multiple files, but as an example, I have implemented this for specifically the cache synchronization, attached to this email.
Quoted 7 lines
Some of the fixes are to make tools work on amd64
=== modified file 'conf/Makefile.common'
Makefile.common line 45
Quoted 8 lines
Makefile.common +1
-2@@ -40,8 +40,7 @@ if COND_arm # Image entry point always in ARM (A32) state - ensure proper functionality if # the rest is built for the Thumb (T32) state. - CFLAGS_PLATFORM += -mthumb-interwork -mno-unaligned-access -mlong-calls - CCASFLAGS_PLATFORM = -Wa,-mimplicit-it=thumb + CFLAGS_PLATFORM += -mthumb-interwork -march=armv6 -mlong-calls LDFLAGS_PLATFORM = -Wl,--wrap=__clear_cache endif
-mno-unaligned-access is required to function on platforms that do not have caches/MMU enabled at this point. They do exist, so please leave it in.
And for reasons stated above, -march= should be set to whatever your target architecture is. Extracted by configure, I suppose?
/
Leif
=== modified file 'conf/Makefile.common'
Makefile.common +1 -0
@@ -41,6 +41,7 @@ # Image entry point always in ARM (A32) state - ensure proper functionality if # the rest is built for the Thumb (T32) state. CFLAGS_PLATFORM += -mthumb-interwork -mno-unaligned-access -mlong-calls + CCASFLAGS_PLATFORM = -marm LDFLAGS_PLATFORM = -Wl,--wrap=__clear_cache endif
=== modified file 'grub-core/kern/arm/cache.S'
kern/arm/cache.S +45 -38
178 lines not on this page · raw message
Quoted 10 lines · Leif Lindholm
Quoted 4 lines · Vladimir '??-coder/phcoder' Serbinenko
Based on Leif Lindholm's patches I could go to GRUB console on raspberry pi. The biggest problem is that cache flushing is simply skipped. Another problem is that due to different linux image format linux loader doesn't work.
Is this because you're feeding it a uImage?
It is entirely possible to runtime detect the U-Boot signature, and simply skip the header.
The kernel shipped with raspbian aren't uImages. they are with some kind of raspberry stuff in it. They have to be loaded at 0 with entry point at 0. u-boot is available for raspberry pi but isn't used by default.
Quoted 7 lines
Quoted 3 lines
I didn't test grub-install but fed GRUB to uboot using kermit. Is there any advantage in building armv6 binary by default unless user overrides through
TARGET_CFLAGS?I think it would get messy: the barrier operations supported by ARMv6 are deprecated in ARMv7.
The questions basically would be how we switch between armv6 and armv7. I see as possibilities:
defining target_cpu of armv6 and armv7, so it will give 4 ports armv[67]-(uboot|efi). Another possibility is to decide on runtime but it's probably more difficult.
Quoted 4 lines
I would suggest an alternative approach, which is to build all of the assembly in "arm" state, and to keep the generic functionality to an ARMv6 subset.
Do we lose anything by not supporting thumb2 for assembly? What armv7 functionality is useful?
Quoted 7 lines
Quoted 7 lines
=== modified file 'conf/Makefile.common'
Makefile.common +0
-0@@ -40,8 +40,7 @@ if COND_arm # Image entry point always in ARM (A32) state - ensure proper functionality if # the rest is built for the Thumb (T32) state.
Quoted 8 lines
Makefile.common line 45
Quoted 5 lines
Makefile.common +1
-2- CFLAGS_PLATFORM += -mthumb-interwork -mno-unaligned-access -mlong-calls - CCASFLAGS_PLATFORM = -Wa,-mimplicit-it=thumb + CFLAGS_PLATFORM += -mthumb-interwork -march=armv6 -mlong-calls LDFLAGS_PLATFORM = -Wl,--wrap=__clear_cache endif-mno-unaligned-access is required to function on platforms that do not have caches/MMU enabled at this point. They do exist, so please leave it in.
My compiler simply doesn't know this option. I suppose it always assumes that no unaligned access is available. Availability of this option must be detected on configure time.
Quoted 3 lines
And for reasons stated above, -march= should be set to whatever your target architecture is. Extracted by configure, I suppose?
Hence --target-cpu=armv[67] proposal.g
Quoted 7 lines · Vladimir '??-coder/phcoder' Serbinenko
Quoted 3 lines
Is this because you're feeding it a uImage?
It is entirely possible to runtime detect the U-Boot signature, and simply skip the header.The kernel shipped with raspbian aren't uImages. they are with some kind of raspberry stuff in it. They have to be loaded at 0 with entry point at 0. u-boot is available for raspberry pi but isn't used by default.
Ah. Yes - I had heard things about the raspi boot mechanism, but must admit I'm not entirely certain about how it would affect things. It could even require a separate loader.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
I didn't test grub-install but fed GRUB to uboot using kermit. Is there any advantage in building armv6 binary by default unless user overrides through
TARGET_CFLAGS?
Quoted 8 lines
Quoted 2 lines
I think it would get messy: the barrier operations supported by ARMv6 are deprecated in ARMv7.
The questions basically would be how we switch between armv6 and armv7. I see as possibilities:
definingtarget_cpuof armv6 and armv7, so it will give 4 ports armv[67]-(uboot|efi). Another possibility is to decide on runtime but it's probably more difficult.
If we want to support ARMv6 targets (keeping in mind that this is akin to implementing i386 support several years after the release of the 486), what we actually end up with is armv6 and v7+ - not a new version for every revision of the architecture (ignoring a 64-bit port for now).
For (U)EFI, I don't think you can find any pre-ARMv7 platforms outside of ARM ltd. early-access development boards (and software models of the same).
For U-Boot, keeping the hand coded assembly to the ARMv6 subset, adding preprocessor macros for the barrier operations and setting suitable CFLAGS would be sufficient to get GRUB working across the available platforms.
Quoted 5 lines
Quoted 3 lines
I would suggest an alternative approach, which is to build all of the assembly in "arm" state, and to keep the generic functionality to an ARMv6 subset.
Do we lose anything by not supporting thumb2 for assembly?
Not much. It was mainly done from a point-of-view of not having to explicitly build the assembler files for a specific instruction set.
For ARMv6 there is no support in the thumb instruction set for system control operations, so in order to support that, assembler files need to be built for the arm instruction set. And if they need to be written as arm instructions anyway, let's just do that by default. I can include that rewrite in my next patchset.
Restricting ourselves to ARMv6 instructions reduces maximum size of immediate loading and loses some more convenient operations like the bitfield-extract ones I modified in my patch.
Quoted 1 line
What armv7 functionality is useful?
As I said, the barrier instructions (required, not just "useful").
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
=== modified file 'conf/Makefile.common'
Makefile.common +0
-0@@ -40,8 +40,7 @@ if COND_arm # Image entry point always in ARM (A32) state - ensure proper functionality if # the rest is built for the Thumb (T32) state.Quoted 8 lines
Makefile.common line 45
Quoted 5 lines
Makefile.common +1
-2- CFLAGS_PLATFORM += -mthumb-interwork -mno-unaligned-access -mlong-calls - CCASFLAGS_PLATFORM = -Wa,-mimplicit-it=thumb + CFLAGS_PLATFORM += -mthumb-interwork -march=armv6 -mlong-calls LDFLAGS_PLATFORM = -Wl,--wrap=__clear_cache endif-mno-unaligned-access is required to function on platforms that do not have caches/MMU enabled at this point. They do exist, so please leave it in.
Quoted 3 lines
My compiler simply doesn't know this option. I suppose it always assumes that no unaligned access is available. Availability of this option must be detected on configure time.
Then I need to add a configure test for this, causing a failure if the option is missing. A toolchain that does not support this option cannot be used to build a reliable bare-metal image for ARM.
FSF GCC 4.7 onwards (and some distribution-patched 4.6) support this flag.
Quoted 4 lines
Quoted 2 lines
And for reasons stated above, -march= should be set to whatever your target architecture is. Extracted by configure, I suppose?
Hence --target-cpu=armv[67] proposal.g
I think it is a bit overkill, since CFLAGS can cover it.
/
Leif
Quoted 7 lines
Then I need to add a configure test for this, causing a failure if the
option is missing. A toolchain that does not support this option cannot be used to build a reliable bare-metal image for ARM.
FSF GCC 4.7 onwards (and some distribution-patched 4.6) support this flag.
Why? According to
http://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=eb04cafba3a6f1eddbdb5ec031d8a7074930d5b9
older version simply have "implicit" -mno-unaligned-access and we support only GCC.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
And for reasons stated above, -march= should be set to whatever your target architecture is. Extracted by configure, I suppose?
Hence --target-cpu=armv[67] proposal.g
I think it is a bit overkill, since CFLAGS can cover it.
The difference is that for all other targets you can compile for the lowest supported CPU and use it for all devices with this target but if I understand correctly on armv7 you need to insert some opcodes which would cause a crash on armv6. Is only cache flushing displays such kind of backward incompatibility?
Another question:
I see that efi/startup.S transitions to thumb but not uboot/startup.S. Was uboot compiled as arm in your port as well or do I miss sth?
Quoted 3 lines
/
Leif
Apologies for long silence, I've been off prototyping runtime services for UEFI on ARMv7 (in order to make EFI grub-install actually _do_ anything), and am really bad at multi-tasking.
I am now focusing 100% on this for the rest of the week.
Quoted 5 lines · Vladimir '??-coder/phcoder' Serbinenko
Quoted 5 lines
Then I need to add a configure test for this, causing a failure if the
option is missing. A toolchain that does not support this option cannot be used to build a reliable bare-metal image for ARM.
Quoted 7 lines
Quoted 2 lines
FSF GCC 4.7 onwards (and some distribution-patched 4.6) support this flag.
Why? According to
http://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=eb04cafba3a6f1eddbdb5ec031d8a7074930d5b9
older version simply have "implicit" -mno-unaligned-access and we support only GCC.
Ok, then it needs to be conditionalised on a configure test.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
And for reasons stated above, -march= should be set to whatever your target architecture is. Extracted by configure, I suppose?
Hence --target-cpu=armv[67] proposal.g
Quoted 8 lines
Quoted 2 lines
I think it is a bit overkill, since CFLAGS can cover it.
The difference is that for all other targets you can compile for the lowest supported CPU and use it for all devices with this target but if I understand correctly on armv7 you need to insert some opcodes which would cause a crash on armv6. Is only cache flushing displays such kind of backward incompatibility?
Only the cache flushing code requires barrier operations. Restricting the .S files to "ARM" instruction set, the barriers can be conditionalised. I will be sending out some patches that to this toda
Quoted 3 lines
Another question:
I see thatefi/startup.Stransitions to thumb but notuboot/startup.S. Was uboot compiled as arm in your port as well or do I miss sth?
Since I was calling it as a "kernel" image (to get machine type and ATAGS/DTB passed on), and the kernel is defined to be called in ARM state, this was the requirement.
This requirement remains regardless of what instruction set uboot is compiled to. If uboot-ELF image support was implemented, you change the protocol, but there would be no strong benefit in changing the entry point code..
/
Leif