Commit 96343426 authored by José Luis  Gutiérrez's avatar José Luis Gutiérrez

moved to submodule branch ppsi:jlgutierrez-hsr-p2p-150506

parent e1cabc91
[submodule "ppsi"]
path = ppsi
url = git@ohwr.org:white-rabbit/ppsi.git
ppsi @ 408fccb7
Subproject commit 408fccb7879c17ee5aff37b69e8deaca9ca27454
*.map*
*.o
*.a
ppsi.bin
*.patch
*~
/ppsi
*.cmd
*.o
.tmp_*
.config
.config.old
include/config
include/generated
The authors (or people who mostly developed the code) are specified inside each
file which compose the PPSi source.
Where no otherways specified, the authors are:
Alessandro Rubini for CERN, 2011 -- GNU LGPL v2.1 or later
Aurelio Colosimo for CERN, 2011 -- GNU LGPL v2.1 or later
The whiterabbit extension is based on wrspec-pc/ptpnoposix project, internally
developed by CERN.
Many source files (mostly those regarding the algorithm itself) are based on the
PTPd project, v.2.1.0 (see http://ptpd.sourceforge.net/), with was used
according to the following copyright notice:
--- COPYRIGHT of PTPd v. 2.1.0 ---
The following copyright notice applies to all files which compose the
PTPd. This notice applies as if the text was explicitly included each
file.
Copyright (c) 2009-2010 George V. Neville-Neil, Steven Kreuzer,
Gael Mace, Alexandre Van Kempen
Copyright (c) 2005-2008 Kendall Correll, Aidan Williams
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---
This diff is collapsed.
This diff is collapsed.
mainmenu "PPSi configuration"
choice
prompt "Architecture to build for"
config ARCH_UNIX
bool "Unix (Linux and likely other systems)"
help
ARCH=unix supports standard Unix system calls, although
the code most likely includes some Linux dependencies.
Choose this architecture if you build for a Linux PC
or embedded system
config ARCH_BARE_I386
bool "Bare i386"
help
This architecture builds a Linux-i386 executable that
does not rely on the standard C library, but makes
system calls directly. This architecture is a test case
to ensure the code can run in freestanding environments
(microcontrollers or other contexts with no operating system)
config ARCH_BARE_X86_64
bool "Bare x86-64"
help
This architecture builds a Linux-x86-64 executable that
does not rely on the standard C library, but makes
system calls directly. This architecture is a test case
to ensure the code can run in freestanding environments
(microcontrollers or other contexts with no operating system)
config ARCH_WRPC
bool "White Rabbit PTP Core (WR Node)"
select CONFIG_EXT_WR
help
Build PPSi for use in the WRPC environment (SPEC card or similar
one). This is a freestanding build, without operating system.
The configuration selects the "White Rabbit" protocol extension.
config ARCH_WRS
bool "White Rabbit Switch"
select CONFIG_EXT_WR
help
Build PPSi for use in the WR switch. The computer is a standard
ARM-Linux host with hardware timestamping and internal PLLs
needed to achieve sub-ns synchronization.
The configuration selects the "White Rabbit" protocol extension.
config ARCH_SIMULATOR
bool "PPSi Simulator (hosted on Linux)"
help
Build a PPSi simulator. It's almost a unix full running slave,
with a simulated master stimulating it for test purposes. This
avoids to wait a long time to see how PPSi behaves.
This architecture uses standard Unix system calls, but the
code includes some Linux dependencies.
endchoice
config ARCH
string
default "unix" if ARCH_UNIX
default "bare-i386" if ARCH_BARE_I386
default "bare-x86-64" if ARCH_BARE_X86_64
default "wrpc" if ARCH_WRPC
default "wrs" if ARCH_WRS
default "sim" if ARCH_SIMULATOR
choice EXTENSION
prompt "Protocol Extension"
config EXT_WR
bool "White Rabbit" if ARCH_WRS || ARCH_WRPC
help
Build WR-PTP (which is able to works as a standard PTP agent,
when the peer is not WR-aware).
config EXT_NONE
bool "None"
default y
help
Select not protocol extension (build standard PTP-V2 daemon).
endchoice
config EXTENSION
string
default "whiterabbit" if EXT_WR
default "" if EXT_NONE
config CROSS_COMPILE
string "Cross compiler prefix"
default "/opt/gcc-lm32/bin/lm32-elf-" if ARCH_WRPC
default "/opt/arm-wrswitch/bin/arm-linux-" if ARCH_WRS
default ""
config ARCH_CFLAGS
string
default "-m32" if ARCH_BARE_I386
default "-m64" if ARCH_BARE_X86_64
default ""
config ARCH_LDFLAGS
string
default "-m elf_i386" if ARCH_BARE_I386
default "-m elf_x86_64" if ARCH_BARE_X86_64
default ""
config WRPCSW_ROOT
string "Source location of wrpc-sw"
depends on ARCH_WRPC
default "../wrpc-sw"
#!/bin/sh
# A trivial script to build with all known configurations
# (please add a configs/ file to test your special case)
# Prevent random user setup to invalidate building for all.
unset CROSS_COMPILE
unset ARCH
# Backup previous .config file, if present
rm -f .config.backup 2> /dev/null
cp -a .config .config.backup 2> /dev/null
# make some temporary files for logs
C=$(mktemp /tmp/ppsi-config.XXXXXX)
remove_tmp_c=true
B=$(mktemp /tmp/ppsi-build.XXXXXX)
remove_tmp_b=true
# loop on default .config files, building for all architectures
configs=$(ls configs)
for c in $configs; do
echo "##### Building with '$c'"
echo "##### Building with '$c'" >> $B
echo "##### Configuring for '$c'" >> $C
# make config and log
if ! make -s $c 2>&1 >> $C; then
echo "Error in configuration (see $C)"
remove_tmp_c=false
fi
make -s clean
# build binaries and log
if ! make -j5 2>&1 >> $B; then
echo "Build error (see $B)"
remove_tmp_b=false
fi
# print sizes
test -f ppsi.o && size ppsi.o
test -f ppsi && size ppsi | tail -n 1
done
make -s clean
# clean logs if succesful
if $remove_tmp_c; then rm $C; fi
if $remove_tmp_b; then rm $B; fi
# restore previous .config file if needed, otherwise just clean.
rm -f .config 2> /dev/null
mv -f .config.backup .config 2> /dev/null
#
# Alessandro Rubini for CERN, 2011,2013 -- public domain
#
# We are now Kconfig-based
-include $(CURDIR)/.config
# We still accept command-line choices like we used to do.
# Also, we must remove the quotes from these Kconfig values
PROTO_EXT ?= $(patsubst "%",%,$(CONFIG_EXTENSION))
ARCH ?= $(patsubst "%",%,$(CONFIG_ARCH))
CROSS_COMPILE ?= $(patsubst "%",%,$(CONFIG_CROSS_COMPILE))
WRPCSW_ROOT ?= $(patsubst "%",%,$(CONFIG_WRPCSW_ROOT))
# For "make config" to work, we need a valid ARCH
ifeq ($(ARCH),)
ARCH = unix
endif
#### In theory, users should not change stuff below this line (but please read)
# classic cross-compilation tool-set
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
# To cross-build bare stuff (x86-64 under i386 and vice versa). We need this:
LD := $(LD) $(shell echo $(CONFIG_ARCH_LDFLAGS))
CC := $(CC) $(shell echo $(CONFIG_ARCH_CFLAGS))
# (I apologize, but I couldn't find another way to remove quotes)
# Instead of repeating "ppsi" over and over, bless it TARGET
TARGET = ppsi
# we should use linux/scripts/setlocalversion instead...
VERSION = $(shell git describe --always --dirty)
# The main target is the big object file.
all: $(TARGET).o
# CFLAGS to use. Both this Makefile (later) and app-makefile may grow CFLAGS
CFLAGS = $(USER_CFLAGS)
CFLAGS += -Wall -O2 -ggdb -Iinclude -fno-common
CFLAGS += -DPPSI_VERSION=\"$(VERSION)\"
# to avoid ifdef as much as possible, I use the kernel trick for OBJ variables
OBJ-y := fsm.o diag.o
# Include arch code. Each arch chooses its own time directory..
include arch-$(ARCH)/Makefile
# include pp_printf code, by default the "full" version. Please
# set CONFIG_PRINTF_NONE or CONFIG_PRINTF_XINT if needed.
ifndef CONFIG_NO_PRINTF
OBJ-y += pp_printf/pp-printf.o
pp_printf/pp-printf.o: $(wildcard pp_printf/*.[ch])
$(MAKE) -C pp_printf pp-printf.o CC="$(CC)" LD="$(LD)"
endif
# We need this -I so <arch/arch.h> can be found
CFLAGS += -Iarch-$(ARCH)/include
# proto-standard is always included, as it provides default function
# so the extension can avoid duplication of code.
ifneq ($(PROTO_EXT),)
include proto-ext-$(PROTO_EXT)/Makefile
endif
include proto-standard/Makefile
# ...and the TIME choice sets the default operations
CFLAGS += -DDEFAULT_TIME_OPS=$(TIME)_time_ops
CFLAGS += -DDEFAULT_NET_OPS=$(TIME)_net_ops
export CFLAGS
# And this is the rule to build our target.o file. The architecture may
# build more stuff. Please note that ./MAKEALL looks for $(TARGET)
# (i.e., the ELF which is either the output or the input to objcopy -O binary)
#
# The object only depends on OBJ-y because each subdirs added needed
# libraries: see proto-standard/Makefile as an example.
$(TARGET).o: $(OBJ-y)
$(LD) -Map $(TARGET).map1 -r -o $@ $(PPSI_O_LDFLAGS) \
--start-group $(OBJ-y) --end-group
$(OBJ-y): .config $(wildcard include/ppsi/*.h)
# Finally, "make clean" is expected to work
clean:
rm -f $$(find . -name '*.[oa]' ! -path './scripts/kconfig/*') *.bin $(TARGET) *~ $(TARGET).map*
# following targets from Makefile.kconfig
silentoldconfig:
@mkdir -p include/config
$(MAKE) -f Makefile.kconfig $@
%config:
$(MAKE) -f Makefile.kconfig $@
defconfig:
@echo "Using unix_defconfig"
@$(MAKE) -f Makefile.kconfig unix_defconfig
.config: silentoldconfig
VERSION = $(shell git describe --always --dirty)
export VERSION
# Do not:
# o use make's built-in rules and variables
# (this increases performance and avoids hard-to-debug behaviour);
# o print "Entering directory ...";
MAKEFLAGS += -rR --no-print-directory
# To put more focus on warnings, be less verbose as default
# Use 'make V=1' to see the full commands
ifdef V
ifeq ("$(origin V)", "command line")
KBUILD_VERBOSE = $(V)
endif
endif
ifndef KBUILD_VERBOSE
KBUILD_VERBOSE = 0
endif
# Cancel implicit rules on top Makefile
$(CURDIR)/Makefile Makefile: ;
# That's our default target when none is given on the command line
PHONY := _all
_all:
# SHELL used by kbuild
CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
else if [ -x /bin/bash ]; then echo /bin/bash; \
else echo sh; fi ; fi)
# Make variables (CC, etc...)
HOSTCC = gcc
HOSTCXX = g++
HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
HOSTCXXFLAGS = -O2
export HOSTCC HOSTCXX HOSTCFLAGS HOSTCXXFLAGS
KBUILD_KCONFIG = $(CURDIR)/Kconfig
export KBUILD_KCONFIG
srctree := $(CURDIR)
objtree := $(CURDIR)
src := $(srctree)
obj := $(objtree)
export srctree objtree
# We need some generic definitions (do not try to remake the file).
$(srctree)/scripts/Kbuild.include: ;
include $(srctree)/scripts/Kbuild.include
# Basic helpers built in scripts/
PHONY += scripts_basic
scripts_basic:
$(Q)$(MAKE) $(build)=scripts/basic
config: scripts_basic FORCE
$(Q)mkdir -p include/linux include/config
$(Q)$(MAKE) $(build)=scripts/kconfig $@
%config: scripts_basic FORCE
$(Q)$(MAKE) $(build)=scripts/kconfig $@
clean:
@find . $(RCS_FIND_IGNORE) \
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
-o -name 'Module.markers' -o -name '.tmp_*.o.*' \) \
-type f -print | xargs rm -f -v
PHONY += FORCE
FORCE:
# Declare the contents of the .PHONY variable as phony. We keep that
# information in a variable so we can use it in if_changed and friends.
.PHONY: $(PHONY)
PPSi implementation for HSR
CFLAGS += -ffreestanding -Os -fno-stack-protector -Itools
ARCH_LDFLAGS = -nostdlib -static -T $A/$(ARCH).lds
# We need to undefine _FORTIFY_SOURCE, to prevent picking up external
# symbols in the inline versions of strcpy etc. This is documented in
# "man gcc" in the Ubuntu version.
CFLAGS += -U_FORTIFY_SOURCE
# All files are under A (short for ARCH) or L (short for lib): I'm lazy
A := arch-$(ARCH)
L := lib-bare
CFLAGS += -Ilib-bare
OBJ-y += $A/crt0.o \
$L/bare-startup.o \
$L/main-loop.o \
$L/bare-io.o \
$A/syscalls.o \
lib/libc-functions.o \
lib/dump-funcs.o \
lib/cmdline.o \
lib/div64.o
# We only support "bare" time operations
TIME := bare
include time-bare/Makefile
all: $(TARGET)
# to build the target, we need -lstd again, in case we call functions that
# were not selected yet (e.g., pp_init_globals() ).
$(TARGET): $(TARGET).o
$(CC) -Wl,-Map,$(TARGET).map2 $(ARCH_LDFLAGS) -o $@ $(TARGET).o
OUTPUT_FORMAT("elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(_ppsi_start)
SECTIONS
{
. = 0x10000000; /* A random address, non-standard by choice*/
.text : {
_ppsi_start = .;
*(.boot)
*(.text)
}
.rodata : { *(.rodata) }
.data : { *(.data) }
.bss : {
. = ALIGN(16);
__bss_start = .;
*(.bss);
. = ALIGN(16);
__bss_end = .;
}
}
/*
* A stupid crt0.S for "freestanding" stuff on gnu/linux
*
* Copyright (C) 2011 CERN (www.cern.ch)
* Author: Alessandro Rubini
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
.section .boot, "ax"
.extern ppsi_main
call ppsi_clear_bss /* In C, lazy me */
/* inspired from uClib */
popl %ecx /* Store argc into %ecx */
movl %esp,%ebx /* Store argv into ebx */
movl %esp,%eax /* Store argv into eax as well*/
movl %ecx,%edx /* Stick argc into %edx so we can do some math in a sec */
leal 4(%eax,%edx,4),%eax
pushl %eax /* Environment pointer */
pushl %ebx /* Argument pointer */
pushl %ecx /* And the argument count */
call ppsi_main
.end
\ No newline at end of file
#ifndef __ARCH_H__
#define __ARCH_H__
/* Architecture-specific defines, included by top-level stuff */
/* please note that these have multiple evaluation of the argument */
#define htons(x) __bswap_16(x)
#define __bswap_16(x) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
#define htonl(x) __bswap_32(x)
#define __bswap_32(x) ( \
(((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
(((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \
(((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \
(((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24))
#define ntohs htons
#define ntohl htonl
#define abs(x) ((x >= 0) ? x : -x)
#endif /* __ARCH_H__ */
#ifndef __PPSI_ARCH_CONSTANTS_H__
#define __PPSI_ARCH_CONSTANTS_H__
#ifndef __PPSI_CONSTANTS_H__
#Warning "Please include <ppsi/constants.h> before <arch/constants.h>"
#endif
#undef PP_DEFAULT_PROTO
#define PP_DEFAULT_PROTO PPSI_PROTO_RAW /* We only use raw ethernet */
#endif /* __PPSI_ARCH_CONSTANTS_H__ */
/*
* Copyright (C) 2011 CERN (www.cern.ch)
* Author: Alessandro Rubini
*
* Released to the public domain
*/
#include <linux/unistd.h>
#include <ppsi/ppsi.h>
#include "bare-linux.h"
#include "syscalls.h"
int bare_errno;
struct sel_arg_struct {
unsigned long n;
void *inp, *outp, *exp;
void *tvp;
};
/*
* The following lines use defines from Torvalds (linux-2.4.0: see syscalls.h)
*/
_syscall3(int, write, int, fd, const void *, buf, int, count)
_syscall1(int, exit, int, exitcode)
_syscall1(int, time, void *, tz)
_syscall3(int, ioctl, int, fd, int, cmd, void *, arg)
_syscall1(int, select, struct sel_arg_struct *, as)
static _syscall2(int, socketcall, int, call, unsigned long *, args)
_syscall2(int, gettimeofday, void *, tv, void *, z);
_syscall2(int, settimeofday, void *, tv, void *, z);
_syscall1(int, adjtimex, void *, tv);
_syscall2(int, clock_gettime, int, clock, void *, t);
_syscall1(int, close, int, fd);
/*
* In the bare arch I'd better use sys_ prefixed names
*/
int sys_write(int fd, const void *buf, int count)
__attribute__((alias("write")));
void sys_exit(int exitval)
__attribute__((alias("exit")));
int sys_time(int tz)
__attribute__((alias("time")));
int sys_ioctl(int fd, int cmd, void *arg)
__attribute__((alias("ioctl")));
int sys_close(int fd)
__attribute__((alias("close")));
static struct sel_arg_struct as; /* declared as local, it won't work */
int sys_select(int max, void *in, void *out, void *exc, void *tout)
{
as.n = max;
as.inp = in;
as.outp = out;
as.exp = exc;
as.tvp = tout;
return select(&as);
}
int sys_gettimeofday(void *tv, void *z)
{
return gettimeofday(tv, z);
}
int sys_settimeofday(void *tv, void *z)
{
return settimeofday(tv, z);
}
int sys_adjtimex(void *tv)
{
return adjtimex(tv);
}
int sys_clock_gettime(int clock, void *t)
{
return clock_gettime(clock, t);
}