Raspberry Pi based Stratum 1 NTP Server Notes
The Raspberry Pi is a low cost ARM7 based singleboard linux computer. The most useful feature of the Raspberry Pi is the built in GPIO that functions very similar to a PIC micro controller.
Parts
- Newark
- Adafruit
- Digikey
- 1c2c
- Need information from Phil on this for the micro USB right angle cables and POE splitters
Total: $?
Wiring Guide
-
P1-01 (+3.3V power)
to VIN (supply voltage)
-
P1-06 (Ground)
to GND
-
P1-08 (UART0_TXD)
to RX (serial data in)
-
P1-10 (UART0_RXD)
to TX (serial data out)
-
P1-12 (GPIO18)
to PPS (pulse-per-second output)
Hardware Setup
- Using a dremel, cut off the standoff in the enclosure closest to the hinge
- Drill a hole on the top side large enough to show the 'in' port on the POE splitter (don't leave enough room to show the POE voltage switch, if someone switches it to anything other than 5v, it will destroy the raspberry pi)
- Drill a hole beside the POE splitter for the antenna to connect
- Adhere the POE splitter next to it's hole with double sided tape
- Attach the antenna SMA to uFL adaptor to the enclosure
- Crimp an ethernet cable that is about 6" long, the connector must be as small as possible
- Cut the included POE power cable in half and strip the wires
- Cut the Standard A end off of the right-angle micro usb cable, strip the wires (cut off the white and green wires, those are for data and we don't need them)
- Splice the POE power cable onto the USB cable by soldering the wires together, use heat shrink to seal the wire
- On the POE power cable, the wire with the long block stripe is
positive
- Assemble the raspberry pi into the enclosure (on the side closest to the hinge) adhering it with double sided tape
Software Setup
This is for very early versions, for newer (2018) setups see:
http://www.unixwiz.net/techtips/raspberry-pi3-gps-time.html however remember to reboot after modifying /boot/config.txt and check for newer versions of gpsd if compiling from src.
Old notes where:
- Perform Initial Setup
- Image the SD card with the latest version of raspbian - See the wiki for more information
- Raspbian can be found at raspberrypi.org, the latest version as of this page being written is 2013-09-25-wheezy
- If using a unit that already has our custom image on it, the cscf-adm account will still need to be added as of March 2014 (it was forgotten)
- Connect the SD card, power, network and a keyboard to the raspberry pi
- Configure the raspberry pi on the configuration screen
- Select Advanced Options -> Update to update the tool
- Select Expand Filesystem to increase the partition size from 2Gb to the size of your SD card
- Select Change User Password and enter a temporary password (this account will be deleted later)
- Select Finish
- Reboot
sudo reboot
- The MAC address isn't labelled on the machine itself, to retrieve it run
ifconfig
and look for HWaddr associated with eth0
- Setup network
- Assign an IP address to the machine in E&I using the previously obtained MAC address, DHCP should automatically assign the correct address on startup
- Change the hostname
sudo nano /etc/hostname
- Update the hosts file with the previously chosen hostname to point to localhost
sudo nano /etc/hosts
- Setup user accounts
- By default, the only user on the raspbian image is the user "pi" with the password "raspberry"
- Add both the cscf-adm and cscf-op accounts
sudo adduser cscf-adm
- Use the current appropriate passwords. If unsure, get the current password from the safe or ask Phil.
- Edit /etc/group and add both the cscf-adm and cscf-op accounts to the same groups as the "pi" user (excluding the pi group)
sudo nano /etc/group
- Ensure that both are added to the adm and sudo groups
- Logout of "pi" and login as either cscf-op and cscf-adm
- Remove the user "pi"
sudo userdel pi
- Delete the "pi" home directory
sudo rm -rf /home/pi
- Setup Advanced Packaging Tool and update
- Become root
sudo -s
- Edit /etc/apt/sources.list and add
deb-src http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
to the last line of the file so that later on we can recompile the NTP sources
- Update the raspberry pi
apt-get update
apt-get upgrade
apt-get dist-upgrade
apt-get autoclean
- Configure hostname under
/etc/hostname
and /etc/hosts
- Disable the serial console
- Recompile the kernel
- In order to tell the Raspberry Pi where to receive the PPS signal, we need to recompile the kernel with some changes. Since compiling it on the Pi takes about 8 hours, we will be using a Thinkpad T420s running Ubuntu 12.04 LTS and cross compiling it for the Pi.
- Under the rpi folder in the CORE Asimov share, there is a kernel that was compiled November 2013, this can be used but it is highly recommended that the kernel be recompiled from scratch using the latest version
- Create a directory called 'pi-compile' under your home directory of the machine you are using to compile. The name and location don't really matter, this is just to keep everything in one place
- Install the appropriate packages for compiling the kernel
sudo apt-get install gcc-arm-linux-gnueabi make ncurses-dev
- Get the kernel sources (ensure that your current directory is your working directory we just made)
wget 'https://github.com/raspberrypi/linux/archive/rpi-3.6.y.tar.gz'
tar xvzf rpi-3.6.y.tar.gz
mv linux-rpi-3.6.y linux
- Ensure that the kernel source is clean (no configuration)
make mrproper
- On the raspberry pi, copy the kernel configuration and send it to the 'compile machine'
gunzip -c /proc/config.gz >config
scp config cscf-op@192.168.1.209:/home/cscf-op/pi-compile
- Replace the destination path, user and address to the appropriate information for your compile machine
- On the compile machine, copy the config file to .config at the top directory of the 'linux' folder (note the leading dot)
- Configure Cross-Development Toolchain and Apply Configuration
- To figure out the common prefix for the build programs run
which arm-linux-gnueabi-gcc
- Set the environment variable CCPREFIX to the proper path we found out previously
- Apply the configuration we stole from the raspberry pi (ensure you are in the top directory of the kernel source)
make ARCH=arm CROSS_COMPILE=${CCPREFIX} oldconfig
- Make Changes to the Kernel Configuration
- To start the menu-based config editor, run
make ARCH=arm CROSS_COMPILE=${CCPREFIX} menuconfig
- Under Device Drivers -> PPS Support, highlight PPS Support and hit M to configure it as a module
- Scroll down and hit M on PPS client using GPIO to configure it as well
- To exit the menu, hit the right arrow key to highlight exit and hit enter
- Exit the menu. When asked, save the configuration
- Configure PPS Support
- At this point, you must decide what GPIO pin that will be used for the PPS signal, in this case we will be using GPIO #18
- Edit arch/arm/mach-bcm2708/bcm2708.c to make 3 changes
- Include the header linux/pps-gpio.h under the line "#include "
#include <linux/delay.h>
#include <linux/pps-gpio.h>
- Under "#endif" at the end of the headers, add the following information to specify what GPIO pin we are using
/* PPS-GPIO platform data */
static struct pps_gpio_platform_data pps_gpio_info = {
.assert_falling_edge = false,
.capture_clear= false,
.gpio_pin=18,
.gpio_label="PPS",
};
static struct platform_device pps_gpio_device = {
.name = "pps-gpio",
.id = -1,
.dev = { .platform_data = &pps_gpio_info },
};
- You can modify .gpio_pin=18 to the pin that you choose, as long as it is a GPIO input/output pin it shouldn't matter
- Call bcm_register_device(&pps_gpio_device); under "bcm_register_device(&bcm2708_gpio_device);" (near the end of the file) to register the PPS signal as a device
bcm_register_device(&bcm2708_dmaman_device);
bcm_register_device(&bcm2708_vcio_device);
#ifdef CONFIG_BCM2708_GPIO
bcm_register_device(&bcm2708_gpio_device);
bcm_register_device(&pps_gpio_device);
#endif
- Return to the top level of the kernel source folder and build the kernel
make ARCH=arm CROSS_COMPILE=${CCPREFIX} -j5
- Install Modules and Update GPU Firmware/Libraries
- Download the GPU firmware/libraries and extract them, run this while in your working directory
wget 'https://github.com/raspberrypi/firmware/archive/next.tar.gz'
tar xvzf next.tar.gz
- Move up a directory and SCP the files back over to the Pi (Replacing the correct information for the Pi)
scp -r pi-compile cscf-op@192.168.1.114:/home/cscf-op/
- Apply the updates
- Copy
linux/arch/arm/boot/zImage
to /boot/kernel.img
- Copy
temp_modules/lib/modules/3.6.11
to /lib/modules/3.6.11
- Copy
temp_modules/lib/firmware
to /lib/firmware
- Copy boot loader files
-
firmware-next/boot/bootcode.bin
to /boot/bootcode.bin
-
firmware-next/boot/fixup.dat
to /boot/fixup.dat
-
firmware-next/boot/start.elf
to /boot/start.elf
-
firmware-next/hardfp/opt/vc
to /opt/vc
- Run
sync
twice
- Reboot
- Add
pps-gpio
to the end of /etc/modules
- Reboot
- Confirm that the pps modules are loaded by running
lsmod
- pps_gpio and pps_core should appear
- Change the cpu_scaling and the serial latency
-
echo "performance" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
-
setserial /dev/ttyAMA0 low_latency
- Install and Configure NTP
- Remove the default NTP installation
apt-get remove ntp --purge
- Copy the
ntp-compile
installation folder from the rpi folder under Asimov's CORE share.
- Normally when compiling this (retrieving the source from apt-get source ntp) it's just a matter of adding
--with-ATOM
but the source isn't downloading the config folder anymore, the last main version change for ntp was in 2012 so having a precompiled version shouldn't make much of a difference
- Install the modified NTP
dpkg -i ntp_4.2.6.p5+dfsg-3~pps1_armhf.deb
- If using DHCP, remove
ntp-servers
from the request
line in /etc/dhcp/dhclient.conf
- Remove
/var/lib/ntp/ntp.conf.dhcp
if present
- Edit
/etc/init.d/ntp
and change if [ -e /var/lib/ntp/ntp.conf.dhcp ]; then
to if [ -e /etc/ntp.conf ]; then
NTPD_OPTS="$NTPD_OPTS -c /etc/ntp.conf"
elif [ -e /var/lib/ntp/ntp.conf.dhcp ]; then
- Replace the current
/etc/ntp.conf
with the version in the rpi folder on the CORE Asimov share.
- Restart NTP
service ntp restart
- Verify configuration
- You can run
ntpq -p
to check any peers and ntpq -c rl
and ntpq -c rv
to check the status of the server (such as stratum level)
References