inaciose
Posts: 14
Joined: Thu Aug 24, 2017 3:34 pm

Anyone can compile the LdB sample on linux?

Wed Oct 04, 2017 3:03 pm

Anyone can compile the LdB sample on a Rasperry Pi 2/3 ?

https://github.com/LdB-ECM/Raspberry-Pi ... m32_64_USB

Bellow its a description of what I have done and fails with arm-none-eabi-ld: cannot find libc.a.

I have done a Makefile and change the rpi-smartstart.h to rpi-SmartStart.h, and the respective includes (the windows its case insensitive), removed the assert entries from code.

The gcc version
arm-none-eabi-gcc --version
arm-none-eabi-gcc (4.8.4-1+11-1) 4.8.4 20141219 (release)

The error:
arm-none-eabi-ld: cannot find libc.a
Makefile:35: recipe for target 'kernel.bin' failed

The line with the error is:
arm-none-eabi-ld SmartStart32.o rpi-SmartStart.o emb-stdio.o Main.o -L /usr/lib/gcc/arm-none-eabi/4.8/libgcc.a /usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/libc.a /usr/lib/gcc/arm-none-eabi/4.8/../../../arm-none-eabi/lib/libm.a -T rpi32.ld -o kernel.elf

The library file paths translate to (and files exists):
ls /usr/lib/arm-none-eabi/lib/libc.a
ls /usr/lib/arm-none-eabi/lib/libm.a

The Makefile

Code: Select all

ARMGNU ?= arm-none-eabi

COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding -mfpu=vfp -mfloat-abi=hard -march=armv6zk -mtune=arm1176jzf-s -mno-unaligned-access -fno-exceptions -I. -std=c99

LIBGCC = $(shell $(ARMGNU)-gcc -print-libgcc-file-name)
LIBC = $(shell $(ARMGNU)-gcc -print-file-name=libc.a)
LIBM = $(shell $(ARMGNU)-gcc -print-file-name=libm.a)

LIBS = $(LIBGCC) $(LIBC) $(LIBM)

all : kernel.bin

clean :
        rm -f *.o
        rm -f *.bin
        rm -f *.hex
        rm -f *.elf
        rm -f *.list
        rm -f *.img

SmartStart32.o : SmartStart32.S
        #(ARMGNU)-as SmartStart32.S -o SmartStart32.o
        $(ARMGNU)-gcc $(COPS) -c SmartStart32.S -o SmartStart32.o

rpi-SmartStart.o : rpi-SmartStart.c
        $(ARMGNU)-gcc $(COPS) -c rpi-SmartStart.c -o rpi-SmartStart.o

emb-stdio.o : emb-stdio.c
        $(ARMGNU)-gcc $(COPS) -c emb-stdio.c -o emb-stdio.o

Main.o : Main.c
        $(ARMGNU)-gcc $(COPS) -c Main.c -o Main.o

kernel.bin : rpi32.ld SmartStart32.o rpi-SmartStart.o emb-stdio.o Main.o
        $(ARMGNU)-ld SmartStart32.o rpi-SmartStart.o emb-stdio.o Main.o $(LIBS) -T rpi32.ld -o kernel.elf
        $(ARMGNU)-objdump -D kernel.elf > kernel.list


LdB
Posts: 550
Joined: Wed Dec 07, 2016 2:29 pm

Re: Anyone can compile the LdB sample on linux?

Sun Oct 08, 2017 5:56 am

The asserts would have been find you just needed to tell it to use C11 with the flag
std=C11 rather than std=c99 you used
static compile time asserts were added as C standard in C11.
C11 was almost complete from the GCC 4.8 status listing
http://gcc.gnu.org/gcc-4.8/cxx0x_status.html

The problem will old GCC 4.8 will be the I have provided printf (in emb-stdio.c) which will get hung up with the actual system printf.

I can suggest 2 quick solutions depending if you know how to retarget the compiler
1. Replace all references to emb-stdio.c for the proper c standard stdio.c and retarget the compiler
emb-stdio is my version of stdio but it is 64 bit retargettable.
2. Follow my instructions to add 6.3 C compiler alongside you 4.8 on the Pi
https://github.com/LdB-ECM/Docs_and_Ima ... 6_On_Pi.md

As per above retargetting the old 4.8 compiler way won't work on AARCH64 which is why I didn't do it that way.
If I get time tonight I will retarget on the old 4.8 for you.

jahboater
Posts: 1785
Joined: Wed Feb 04, 2015 6:38 pm

Re: Anyone can compile the LdB sample on linux?

Sun Oct 08, 2017 8:34 am

On that latest Raspbian (stretch) the default installed compiler is GCC 6.3.

and the default C language standard for 6.3 is now -std=gnu11 (C11).

LdB
Posts: 550
Joined: Wed Dec 07, 2016 2:29 pm

Re: Anyone can compile the LdB sample on linux?

Sun Oct 08, 2017 8:56 am

Nice I was just doing Raspbian 4.8 and it has the stupid bug for initializers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119

You have to work out how many braces to put around each { 0}, {{0}}, {{{0}}},{{{{0}}}} ... fun fun

Array bound warning bug as well
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124
So you can't run -O3 optimization you have to drop to -O2 on it

An example of reasons to not use real old GCC compilers :-)

Update: Now I got to a problem which needs someone familiar with linux to explain.
Here is my bash script

Code: Select all

#!/bin/sh
gcc -Wall -O2 -std=c11 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv8-a -mtune=cortex-a53 -mno-unaligned-access -nostdlib -nostartfiles -ffreestanding -fno-asynchronous-unwind-tables -fomit-frame-pointer -Wa,-a>list.txt -Wl,-gc-sections -Wl,--build-id=none -Wl,-Bdynamic -Wl,-Map,kernel.map -Wl,-T,rpi32.ld Main.c SmartStart32.S rpi-SmartStart.c emb-stdio.c rpi-USB.c -o kernel.elf -lc -lm -lgcc
objcopy kernel.elf -O binary DiskImg/kernel8-32.img
So it's two lines after the shebang .. now the weird bit
If I cut and paste the lines individually they work. If I run the script the last library instruction fails which as shown is -lgcc but if I reorder so -lc or -lm is last it will be that one that fails. I am wonder if I have a Carriage Return causing a problem since I made it in windows.

I am obviously failing at bash script 101 :-(
Last edited by LdB on Sun Oct 08, 2017 9:47 am, edited 1 time in total.

User avatar
rpdom
Posts: 11529
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Anyone can compile the LdB sample on linux?

Sun Oct 08, 2017 9:46 am

Where are you stating the input/source file in that line? The last argument to gcc should be the name of the source file.

[edit] Ah, found them. Hidden in the middle.

Try putting the "Main.c SmartStart32.S rpi-SmartStart.c emb-stdio.c rpi-USB.c" bits after all the other entries.
Last edited by rpdom on Sun Oct 08, 2017 9:48 am, edited 1 time in total.

LdB
Posts: 550
Joined: Wed Dec 07, 2016 2:29 pm

Re: Anyone can compile the LdB sample on linux?

Sun Oct 08, 2017 9:48 am

Doesn't have to be first it knows the flags all start with "-" sign, it's Main.c scroll across

As I said line works perfectly if I cut and paste .. I am thinking I have a CR from windows. Trying to work out how to remove any CR :-).

Will shuffle them to start but it's compiling just has trouble with linker on last name in list .. which is why I suspect CR issue.

Update: Yep was the CR .. installed fromdos

sudo apt-get install tofrodos

Then ran fromdos on file fixed it up.

Will now add the new stuff to it and upload a new copy with bash scripts :-)

Return to “Bare metal”

Who is online

Users browsing this forum: wh7qq and 3 guests