Commit 5f59e30a authored by Alessandro Rubini's avatar Alessandro Rubini

Makefile, README: freestanding build doesn't work.

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent d6208d73
......@@ -9,9 +9,9 @@ STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
# Differentiate between freestanding compilazion (one with no libc)
# Differentiate between freestanding compilation (one with no libc)
# from a complete one. This way, arm and x86 are identified as hosted,
# while zpu or other minimal processors are identifed as freestanding.
# while zpu or other minimal processors are identified as freestanding.
# A hosted processor depends in LINUX being set. To allow forcing
# freestanding arm compilations, use a local script to define this
# (if you set PTPD_FREESTANDING=y you force freestanding compile)
......@@ -20,6 +20,7 @@ PTPD_FREESTANDING ?= $(shell ./check-freestanding $(CC))
ifeq ($(PTPD_FREESTANDING), y)
SAY := $(shell echo "CPU is freestanding" > /dev/tty)
SAY := $(shell echo "WARNING: this does not build" > /dev/stderr; sleep 3)
CFLAGS = -ffreestanding -DPTPD_FREESTANDING -ffunction-sections -fdata-sections -Os -DWRPC_EXTRA_SLIM $(EXTRA_CFLAGS)
TARGETS := ptpd-freestanding
else
......@@ -74,7 +75,6 @@ POSIX_OBJS += $D/ptpd.o
# This is a replacement for startup in the freestanding version
FREE_OBJS = libposix/freestanding-startup.o
FREE_OBJS += libposix/freestanding-display.o
# When running freestanding, we have no libraries, so hack this
FREE_OBJS += libposix/wr_nolibs.o
......
IMPORTANT NOTE: This README is mostly obsolete. It's up to date as of
end of May 2011, as a blindly-ported present to hardware people that
_later_ made it really work.
This package is slowly being phased out.
We have no up to date documentation, and what we had here was obsolete
(was up to date as of end-of-may 2011).
This is a version of wr_ptpd somewhat ported to ZPU or other embedded
processors. The core program is ported, but external functions
(hardware access) are still missing). The program still compiles and
works in a "normal" ARM926 GNU/Linux environment.
Currently the package can't be compliled in freestanding mode from
this directory, but only from ../wrpc-sw . If built under a Linux
system, it behaves as wr-ptpd.
I imported in this git tree an unmodified copy of version 916 for the
svn repository (white-rabbit/trunl/software/), and started working on
that. After that, Tomasz allowed me to commit some reindented files,
so version 918 is now the one to diff against if you need it.
I planned to change the Makefiles to have no external dependencies (like
../../Makedefs), but I finally chose to write a new top-level Makefile
and use that instead. Other Makefiles have been removed, as unused.
WARNING: The is no dependencies support, so if you touch headers you should
"make clean" and again "make".
Configuration of the package, for use witht he top-level Makefile, is
with environment variables. You should set the following two at this
point:
CROSS_COMPILE (the compilation prefix, may be a full path)
LINUX (the main directory of the kernel sources)
For example, I do like this in my own systems:
export CROSS_COMPILE=/opt/eldk-4.2-arm/usr/bin/arm-linux-
export LINUX=/usr/src/wrs-kernel
or
export CROSS_COMPILE=$HOME/zpugcc-install/bin/zpu-elf-
The zpu compilation is not complete, as support functions are missing.
The compilation steps
---------------------
The package (which only exists to make ptpd a freestanding thing
with a goal of short-term maintainability) is designed as follows:
* All objects from ptpd are linked into ptpd.o . This is where
I look for undefined symbols that must be dealt with. Missing
symbols in this file are added later using different strategies
for hosted and freestanding compilation.
Please note that you can force freestanding compilation on ARM
(or whatever "hosted" cpu) by passing "PTPD_FREESTANDING=y~.
Final steps in hosted compilation
.................................
For hosted compilation, the following files are added, which
are called CORELIBS and POSIX_OBJS, to make ./ptpd (the final program)
libwripc.a (libwripc/wr_ipc.o libwripc/helper_arm.o)
libptpnetif.a (libptpnetif/hal_client.o libptpnetif/ptpd_netif.o)
PTPWRd/dep/startup.o
Then, the default libc is used as well.
Final steps in freestanding compilation
.......................................
For freestanding, two steps are taken. First ptpd-freestanding.o
is build adding the following object files to the ptp.o object:
libposix/freestanding-startup.o
libposix/wr_nolibs.o
libposix/freestanding-wrapper.o
These three are called FREE_OBJS in the Makefile.
Finally, the ptp-freestanding executable is built by a simple
compile step with no special options. This is where your default
libc gets linked (and you can change it if needed).
To summarize, you have these files:
ptp.o the code with all its unresolved symbols
ptpd-freestanding.o same, with added the fake libraries
ptpd-freestanding the final executable
To complete this port you'll need to look for undefined symbols in
ptpd-freestanding.o and add them in the libposix/ files as neeeded.
Looking for them is much easier in the object file than it is
in the compile error, but pleae remember some of these will be
resolved by the default libc:
${CROSS_COMPILE}nm ptpd-freestanding.o | grep -w U
The last step takes this ptpd-freestanding.o to buld your
ptpd-freestanding final exectuable. You can change libc or whatever
in this final step.
How portability is accomplished
-------------------------------
The command-line of $(CROSS_COMPILE)gcc has the option
-include libposix/ptpd-wrappers.h
The header does all the magic by adding missing pieces for
freestanding compilation (actually, it's not much). Two shell scripts
are used by Make to select freestanding or hosted compilation, and
detect endianness (on zpu we have no <endian.h>).
If the compilation is not freestanding, the header includes headers that
can't be included otherwise (because they are missing in the zpu
installation, and probably in other freestanding implementation).
If the compilation is freestanding, what is missing is defined or
declared.
Freestanding compilation is selected if you either miss a dynamic
library (e.g: zpu) or if you select PTPD_FREESTANDING=y as a make
variable (environment or command line).
In this way, the original sources are minimally affected and I hope to
fill the missing bits easily. In any case, I removed the inclusion of
system headers where they were not needed, and sometimes I added
"#ifdeffed" inclusions when headers were only needed in one place
(to avoid including it in ptpd-wrappers if it's too specific).
Since there was a constants_dep.h file, I added a stanza there for
freestanding compilation where a pair of symbols that were defined in
that file are defined for zpu or otherwise. All other fixes have been
made in the ptpd-wrappers.h header file.
You can force freestanding compilation (for example, in your ARM
or x86 environment) by calling
make PTPD_FREESTANDING=y
(this is accomplished by a Makefile conditional and an external script)
List of issues I am facing
--------------------------
* This binary is horribly big.
tornado$ ${CROSS_COMPILE}size ptpd-freestanding.o
text data bss dec hex filename
60603 280 132 61015 ee57 ptpd-freestanding.o
(this is the zpu version with all externals unresolved -- including the
strcpy and so on that the default library offers).
The split up is as follows (sorted by size):
text data bss dec hex filename
100 0 0 100 64 ./PTPWRd/dep/servo.o
547 244 0 791 317 ./PTPWRd/ptpd.o
1590 4 128 1722 6ba ./PTPWRd/dep/sys.o
1683 24 0 1707 6ab ./PTPWRd/dep/timer.o
2088 0 0 2088 828 ./PTPWRd/dep/net.o
2726 0 0 2726 aa6 ./PTPWRd/arith.o
5035 0 0 5035 13ab ./PTPWRd/wr_protocol.o
6588 0 0 6588 19bc ./PTPWRd/bmc.o
8814 0 0 8814 226e ./PTPWRd/dep/msg.o
12427 8 4 12439 3097 ./PTPWRd/dep/wr_servo.o
18892 0 0 18892 49cc ./PTPWRd/protocol.o
* Data is horribly big.
The init code used to allocate, it is now statically compiled
but it is now 60kB of bss stuff in ./libposix/freestanding-startup.o .
The thing depends on MAX_PORT_NUMBER (16) and
DEFAULT_MAX_FOREIGN_RECORDS (5). So things will get better by reducing
those values. I prefer to leave them untouched by now.
* Some floating point is there. I removed some but there is more:
arith.c has some float calculations (Tom will fix)
PTPWRd/dep/wr_servo.c has a lot of that (Tow will make fixed point)
* Use of the options is at least questionable
While the rtOpts function is being passed to several functions, maybe
a set of static variables would decrease the size a while (as some
can be defined as "const" in freestanding mode, so to avoid them
and the associated code altogether.
I'm currently not doing anything on that, I only changed the startup
file to avoid parsing the command line.
* There are a number of still undefined functions, to be filled:
I use this command to count what the default library doesn't provide:
make 2>&1 | grep undefined | tr -d \'\` | \
awk '{print $NF}' | sort | uniq -c | sort -k 2
1 ZPU_ID
4 gettimeofday
1 halexp_get_port_state
5 halexp_pps_cmd
2 ptpd_netif_calibrating_disable
3 ptpd_netif_calibrating_enable
2 ptpd_netif_calibrating_poll
2 ptpd_netif_calibration_pattern_disable
3 ptpd_netif_calibration_pattern_enable
1 ptpd_netif_create_socket
1 ptpd_netif_get_hw_addr
1 ptpd_netif_get_ifName
1 ptpd_netif_get_port_state
1 ptpd_netif_init
1 ptpd_netif_locking_disable
2 ptpd_netif_locking_enable
1 ptpd_netif_locking_poll
1 ptpd_netif_recvfrom
1 ptpd_netif_select
3 ptpd_netif_sendto
1 settimeofday
1 usleep
The same command, on freestanding arm, gives less undefined symbols becase
some are in the library.
make PTPD_FREESTANDING=y 2>&1 | grep undefined | tr -d \'\` | \
awk '{print $NF}' | sort | uniq -c | sort -k 2
1 halexp_get_port_state
5 halexp_pps_cmd
1 ptpdShutdown
1 ptpdStartup
2 ptpd_netif_calibrating_disable
3 ptpd_netif_calibrating_enable
2 ptpd_netif_calibrating_poll
2 ptpd_netif_calibration_pattern_disable
3 ptpd_netif_calibration_pattern_enable
1 ptpd_netif_create_socket
1 ptpd_netif_get_hw_addr
1 ptpd_netif_get_ifName
1 ptpd_netif_get_port_state
1 ptpd_netif_init
1 ptpd_netif_locking_disable
2 ptpd_netif_locking_enable
1 ptpd_netif_locking_poll
1 ptpd_netif_recvfrom
1 ptpd_netif_select
3 ptpd_netif_sendto
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment