cross compile to riscv

649 views
Skip to first unread message

grace wilder

unread,
Jan 10, 2018, 1:15:55 AM1/10/18
to RISC-V SW Dev
 hi,
I am new to riscv and i need to cross compile my coremark code to riscv. i made some changes in core_portme.mak but it's giving some error.
my code
#File: core_portme.mak

# Flag: OUTFLAG
#    Use this flag to define how to to get an executable (e.g -o)
OUTFLAG= -o
# Flag: CC
#    Use this flag to define compiler to use
CC = riscv64-unknown-elf-gcc
# Flag: CFLAGS
#    Use this flag to define compiler options. Note, you can add compiler options from the command line using XCFLAGS="other flags"
PORT_CFLAGS = -O2
FLAGS_STR = "$(PORT_CFLAGS) $(XCFLAGS) $(XLFLAGS) $(LFLAGS_END)"
CFLAGS = $(PORT_CFLAGS) -I$(PORT_DIR) -I. -DFLAGS_STR=\"$(FLAGS_STR)\"
#Flag: LFLAGS_END
#    Define any libraries needed for linking or other flags that should come at the end of the link line (e.g. linker scripts).
#    Note: On certain platforms, the default clock_gettime implementation is supported but requires linking of librt.
LFLAGS_END += -lrt
# Flag: PORT_SRCS
# Port specific source files can be added here
PORT_SRCS = $(PORT_DIR)/core_portme.c
# Flag: LOAD
#    Define this flag if you need to load to a target, as in a cross compile environment.

# Flag: RUN
#    Define this flag if running does not consist of simple invocation of the binary.
#    In a cross compile environment, you need to define this.

#For flashing and using a tera term macro, you could use
#LOAD = flash ADDR
#RUN =  ttpmacro coremark.ttl

#For copying to target and executing via SSH connection, you could use
#LOAD = scp $(OUTFILE)  user@target:~
#RUN = ssh user@target -c 

#For native compilation and execution
LOAD = echo loading
RUN = spike pk

OEXT = .o
EXE = .exe

# Flag: SEPARATE_COMPILE
# Define if you need to separate compilation from link stage.
# In this case, you also need to define below how to create an object file, and how to link.
ifdef SEPARATE_COMPILE

LD        = riscv64-unknown-elf-gcc
OBJOUT     = -o
LFLAGS     = -l
OFLAG     = -o
COUT     = -c
# Flag: PORT_OBJS
# Port specific object files can be added here
PORT_OBJS = $(PORT_DIR)/core_portme$(OEXT)
PORT_CLEAN = *$(OEXT)

$(OPATH)%$(OEXT) : %.c
    $(CC) $(CFLAGS) $(XCFLAGS) $(COUT) $< $(OBJOUT) $@
   
endif

# Target: port_prebuild
# Generate any files that are needed before actual build starts.
# E.g. generate profile guidance files. Sample PGO generation for gcc enabled with PGO=1
#  - First, check if PGO was defined on the command line, if so, need to add -fprofile-use to compile line.
#  - Second, if PGO reference has not yet been generated, add a step to the prebuild that will build a profile-generate version and run it.
#  Note - Using REBUILD=1
#
# Use make PGO=1 to invoke this sample processing.

ifdef PGO
 ifeq (,$(findstring $(PGO),gen))
  PGO_STAGE=build_pgo_gcc
  CFLAGS+=-fprofile-use
 endif
 PORT_CLEAN+=*.gcda *.gcno gmon.out
endif

.PHONY: port_prebuild
port_prebuild: $(PGO_STAGE)

.PHONY: build_pgo_gcc
build_pgo_gcc:
    $(MAKE) PGO=gen XCFLAGS="$(XCFLAGS) -fprofile-generate -DTOTAL_DATA_SIZE=1200" ITERATIONS=10 gen_pgo_data REBUILD=1
   
# Target: port_postbuild
# Generate any files that are needed after actual build end.
# E.g. change format to srec, bin, zip in order to be able to load into flash
.PHONY: port_postbuild
port_postbuild:

# Target: port_postrun
#     Do platform specific after run stuff.
#    E.g. reset the board, backup the logfiles etc.
.PHONY: port_postrun
port_postrun:

# Target: port_prerun
#     Do platform specific after run stuff.
#    E.g. reset the board, backup the logfiles etc.
.PHONY: port_prerun
port_prerun:

# Target: port_postload
#     Do platform specific after load stuff.
#    E.g. reset the reset power to the flash eraser
.PHONY: port_postload
port_postload:

# Target: port_preload
#     Do platform specific before load stuff.
#    E.g. reset the reset power to the flash eraser
.PHONY: port_preload
port_preload:

# FLAG: OPATH
# Path to the output folder. Default - current folder.
OPATH = ./
MKDIR = mkdir -p riscv

# FLAG: PERL
# Define perl executable to calculate the geomean if running separate.
PERL=/usr/bin/perl

-------------------------------------------------------------------
there are other 2 files also(.h and .c files)...
but its givin me following error

/home/pearl/Desktop/coremark_v1.0/riscv/lib/gcc/riscv64-unknown-elf/7.2.0/../../../../riscv64-unknown-elf/bin/ld: cannot find -lrt
collect2: error: ld returned 1 exit status
Makefile:88: recipe for target 'compile' failed
make[2]: *** [compile] Error 1
make[2]: Leaving directory '/home/pearl/Desktop/coremark_v1.0'
Makefile:95: recipe for target 'coremark.exe' failed
make[1]: *** [coremark.exe] Error 2
make[1]: Leaving directory '/home/pearl/Desktop/coremark_v1.0'
Makefile:101: recipe for target 'rerun' failed
make: *** [rerun] Error 2
...................................................................................
what am i doing wrong?




Sadullah Canakci

unread,
Jan 10, 2018, 1:21:20 AM1/10/18
to grace wilder, RISC-V SW Dev
cannot find -lrt states that it could not find librt. You should help your compiler to show its path, also it is entirely possible that there is no librt compiled for riscv in your case. There should be either librt.so or librt.a for dynamic and static compilation respectively. 

--
You received this message because you are subscribed to the Google Groups "RISC-V SW Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sw-dev+un...@groups.riscv.org.
To post to this group, send email to sw-...@groups.riscv.org.
Visit this group at https://groups.google.com/a/groups.riscv.org/group/sw-dev/.
To view this discussion on the web visit https://groups.google.com/a/groups.riscv.org/d/msgid/sw-dev/3933d66a-b41f-4368-ada9-1b99850353d8%40groups.riscv.org.
--
SadullahCanakci

Stefan O'Rear

unread,
Jan 10, 2018, 1:36:08 AM1/10/18
to grace wilder, RISC-V SW Dev
On Tue, Jan 9, 2018 at 10:15 PM, grace wilder <wilder...@gmail.com> wrote:
> hi,
> I am new to riscv and i need to cross compile my coremark code to riscv. i
> made some changes in core_portme.mak but it's giving some error.
> my code
> #File: core_portme.mak

> # Note: On certain platforms, the default clock_gettime implementation is
> supported but requires linking of librt.
> LFLAGS_END += -lrt

> #For native compilation and execution
> LOAD = echo loading
> RUN = spike pk

> LD = riscv64-unknown-elf-gcc

newlib, which is used by the -elf- toolchain, does not provide a
librt. Remove it from LFLAGS_END and then fix any errors related to
timers.

-s

grace wilder

unread,
Jan 10, 2018, 4:13:57 AM1/10/18
to RISC-V SW Dev, wilder...@gmail.com

i tried it... but it is giving some other issue.. its showing syntax error in coremark.exe


loading done ./coremark.exe
make port_postload
make[2]: Entering directory '/home/pearl/Desktop/coremark_v1.0'
make[2]: Nothing to be done for 'port_postload'.

make[2]: Leaving directory '/home/pearl/Desktop/coremark_v1.0'
make port_prerun
make[2]: Entering directory '/home/pearl/Desktop/coremark_v1.0'
make[2]: Nothing to be done for 'port_prerun'.

make[2]: Leaving directory '/home/pearl/Desktop/coremark_v1.0'
./coremark.exe  0x3415 0x3415 0x66 0 7 1 2000  > ./run2.log
./coremark.exe: 7: ./coremark.exe: Syntax error: ")" unexpected
Makefile:114: recipe for target 'run2.log' failed
make[1]: *** [run2.log] Error 2

make[1]: Leaving directory '/home/pearl/Desktop/coremark_v1.0'
Makefile:102: recipe for target 'rerun' failed

make: *** [rerun] Error 2
.................................................
how to solve this issue?

Stefan O'Rear

unread,
Jan 10, 2018, 4:26:58 AM1/10/18
to grace wilder, RISC-V SW Dev
On Wed, Jan 10, 2018 at 1:13 AM, grace wilder <wilder...@gmail.com> wrote:
> ./coremark.exe 0x3415 0x3415 0x66 0 7 1 2000 > ./run2.log
> ./coremark.exe: 7: ./coremark.exe: Syntax error: ")" unexpected

>> > LOAD = echo loading
>> > RUN = spike pk

Since I don't have a copy of coremark I can be of only limited
assistance but it seems to not be honoring $(RUN) properly so you
could look into why it tried to run coremark without $(RUN).

-s
Reply all
Reply to author
Forward
0 new messages