Posts Stratum 1 NTP server on OpenBSD
Post
Cancel

Stratum 1 NTP server on OpenBSD

This article entitled “OpenBSD with GPS synchronised NTP” from Iain R. Learmonth triggered my interest. Getting stratum 1 time synchronised from GPS on your computer looked so simple on OpenBSD, all you need is to plug into USB port some u-blox GPS module speaking NMEA protocol and add it as nmea source to /etc/ntpd.conf. Sounds cool, let’s do this.

TLDR

  1. get this
  2. plug it to your OpenBSD box
  3. wait until it starts blinking
  4. ldattach nmea /dev/cuaU0
  5. sensor nmea0 weight 5 in /etc/ntpd.conf

The hardware

  • U-Blox M8N GPS module, I bought a few modules from AliExpress, specifically from this link, just wanted to make sure the board includes micro-USB, not only UART
  • Orange Pi Zero arm board (just so happens I had spare one and it’s on OpenBSD supported hardware list)
  • 5V 1A USB output power supply
  • Two USB to micro-USB cables, one for power, another for GPS module (double check these cables are OK, I spent hours chasing ghost bugs because of a poor quality broken cable).

Putting it all together

Installing OpenBSD

Installing OpenBSD on Orange Pi Zero board was quite simple:

  • downloaded cubie armv7 mini install image from OpenBSD CDN
  • dd it to microSD card
  • downloaded u-boot-arm-2020.. package from OpenBSD amd64 packages
  • extracted share/u-boot/orangepi_zero/u-boot-sunxi-with-spl.bin
  • then dd it to microSD card with bs=1k seek=8 conv=sync
  • finally, wired the board’s UART (GND, TX, RX) to my PC serial port (we need serial console to install it), plugged in network cable, powered on, installed OpenBSD and after reboot SSH access was on.

Wiring NEO-M8N module

The module is small, approximately half size of Orange Pi Zero board

GPS module front

Connected the module with micro-USB cable to Orange Pi Zeron, and a new device popped in OpenBSD:

1
2
3
4
umodem0 at uhub3 port 1 configuration 1 interface 0 "u-blox AG - www.u-blox.com u-blox GNSS receiver" rev 1.10/3.01 addr 2
umodem0: data interface 1, has CM over data, has no break
umodem0: status change notification available
ucom0 at umodem0

GPS module wired

The module has one red led labeled D1 PPS which will light up and stay still while module is synchronizing and is trying to lock on satellites. It has a built-in antenna which is soldered directly on the back of the board. The inside room lock on the sats seems to work, but not reliably, moving it close to the outside window helps.

Some output data while module is trying to sync

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
13:32:14 root@zero:~# cu -l /dev/cuaU0    
Connected to /dev/cuaU0 (speed 9600)
$GNTXT,01,01,02,u-blox AG - www.u-blox.com*4E
$GNTXT,01,01,02,HW UBX-M8030 00080000*60
$GNTXT,01,01,02,EXT CORE 3.01 (107900)*33
$GNTXT,01,01,02,ROM BASE 3.01 (107888)*25
$GNTXT,01,01,02,FWVER=SPG 3.01*46
$GNTXT,01,01,02,PROTVER=18.00*11
$GNTXT,01,01,02,MOD=NEO-M8N-0*67
$GNTXT,01,01,02,FIS=0xEF4015 (100111)*58
$GNTXT,01,01,02,GPS;GLO;GAL;BDS*77
$GNTXT,01,01,02,SBAS;IMES;QZSS*49
$GNTXT,01,01,02,GNSS OTP=GPS;GLO*37
$GNTXT,01,01,02,LLC=FFFFFFFF-FFFFFFED-FFFFFFFF-FFFFFFFF-FFFFFF69*23
$GNTXT,01,01,02,ANTSUPERV=AC SD PDoS SR*3E
$GNTXT,01,01,02,ANTSTATUS=OK*25
$GNTXT,01,01,02,PF=3FF*4B
$GNRMC,153216.00,V,,,,,,,280920,,,N*60
$GNVTG,,,,,,,,,N*2E
$GNGGA,153216.00,,,,,0,00,99.99,,,,,,*7A
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E
$GPGSV,1,1,01,02,,,25*7D
$GLGSV,1,1,00*65
$GNGLL,,,,,153216.00,V,N*56
$GNRMC,153217.00,V,,,,,,,280920,,,N*61
$GNVTG,,,,,,,,,N*2E
$GNGGA,153217.00,,,,,0,00,99.99,,,,,,*7B
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E
$GNGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*2E
$GPGSV,1,1,01,02,,,26*7E

When module is locked on sats, the D1 PPS will start blinking => the module is ready.

Using the new GPS sensor

As described in Iain’s article, next step was to use ldattach nmea (as root, of course)

1
ldattach nmea /dev/cuaU0

then confirming we have the new sensor in sysctl hw.sensors

1
2
3
4
5
6
hw.sensors.nmea0.indicator0=On (Signal), OK
hw.sensors.nmea0.timedelta0=-0.002324 secs (GPS autonomous), OK, Sun Sep 27 16:32:19.997
hw.sensors.nmea0.angle0=XX.6073 degrees (Latitude), OK
hw.sensors.nmea0.angle1=X.7834 degrees (Longitude), OK
hw.sensors.nmea0.distance0=XX.300 m (Altitude), OK
hw.sensors.nmea0.velocity0=0.215 m/s (Ground speed), OK

and finally, replacing sensor line in /etc/ntpd.conf with

1
sensor nmea0 refid GPS weight 5

to tell OpenNTPd to use the new GPS sensor with higher weight. After some time clock was synced and ntpctl -sa was telling it runs as stratum 1 NTP server.

GPS module wired

TODO

In no particular order

  • find a box to house both boards
  • if box is put faraway, for better sat signals reception, maybe better to power it via POE
  • mod /etc/ttys to have ldattach started on boot, as described in Iain’s article
  • buy more quality micro-USB cables (really..)

OpenBSD dmesg.boot on Orange Pi Zero

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
OpenBSD 6.8-beta (GENERIC) #334: Thu Sep 24 11:34:20 MDT 2020
    deraadt@armv7.openbsd.org:/usr/src/sys/arch/armv7/compile/GENERIC
real mem  = 443944960 (423MB)
avail mem = 424640512 (404MB)
random: good seed from bootblocks
mainbus0 at root: Xunlong Orange Pi Zero
cpu0 at mainbus0 mpidr 0: ARM Cortex-A7 r0p5
cpu0: 32KB 32b/line 2-way L1 VIPT I-cache, 32KB 64b/line 4-way L1 D-cache
cpu0: 512KB 64b/line 8-way L2 cache
cortex0 at mainbus0
psci0 at mainbus0: PSCI 0.0
simplebus0 at mainbus0: "soc"
sxisid0 at simplebus0
sxiccmu0 at simplebus0
sxipio0 at simplebus0: 94 pins
ampintc0 at simplebus0 nirq 160, ncpu 4: "interrupt-controller"
sxirtc0 at simplebus0
sxiccmu1 at simplebus0
sxipio1 at simplebus0: 12 pins
sxisyscon0 at simplebus0
"clock" at simplebus0 not configured
"mixer" at simplebus0 not configured
"dma-controller" at simplebus0 not configured
"lcd-controller" at simplebus0 not configured
sximmc0 at simplebus0
sdmmc0 at sximmc0: 4-bit, sd high-speed, mmc high-speed, dma
sximmc1 at simplebus0
sdmmc1 at sximmc1: 4-bit, sd high-speed, mmc high-speed, dma
"usb" at simplebus0 not configured
"phy" at simplebus0 not configured
ehci0 at simplebus0
usb0 at ehci0: USB revision 2.0
uhub0 at usb0 configuration 1 interface 0 "Generic EHCI root hub" rev 2.00/1.00 addr 1
ohci0 at simplebus0: version 1.0
ehci1 at simplebus0
usb1 at ehci1: USB revision 2.0
uhub1 at usb1 configuration 1 interface 0 "Generic EHCI root hub" rev 2.00/1.00 addr 1
ohci1 at simplebus0: version 1.0
"timer" at simplebus0 not configured
dwxe0 at simplebus0: address 02:42:f5:2e:94:40
ukphy0 at dwxe0 phy 1: Generic IEEE 802.3u media interface, rev. 0: OUI 0x001105, model 0x0000
"dram-controller" at simplebus0 not configured
sxidog0 at simplebus0
com0 at simplebus0: ns16550, no working fifo
com0: console
"hdmi-phy" at simplebus0 not configured
"codec-analog" at simplebus0 not configured
"deinterlace" at simplebus0 not configured
"video-codec" at simplebus0 not configured
"crypto" at simplebus0 not configured
"gpu" at simplebus0 not configured
sxitemp0 at simplebus0
gpio0 at sxipio0: 32 pins
gpio1 at sxipio0: 32 pins
gpio2 at sxipio0: 32 pins
gpio3 at sxipio0: 32 pins
gpio4 at sxipio0: 32 pins
gpio5 at sxipio0: 32 pins
gpio6 at sxipio0: 32 pins
gpio7 at sxipio1: 32 pins
usb2 at ohci0: USB revision 1.0
uhub2 at usb2 configuration 1 interface 0 "Generic OHCI root hub" rev 1.00/1.00 addr 1
usb3 at ohci1: USB revision 1.0
uhub3 at usb3 configuration 1 interface 0 "Generic OHCI root hub" rev 1.00/1.00 addr 1
agtimer0 at mainbus0: tick rate 24000 KHz
scsibus0 at sdmmc0: 2 targets, initiator 0
sd0 at scsibus0 targ 1 lun 0: <SD/MMC, SC16G, 0080> removable
sd0: 15193MB, 512 bytes/sector, 31116288 sectors
manufacturer 0x0020, product 0x2281 at sdmmc1 function 1 not configured
umodem0 at uhub3 port 1 configuration 1 interface 0 "u-blox AG - www.u-blox.com u-blox GNSS receiver" rev 1.10/3.01 addr 2
umodem0: data interface 1, has CM over data, has no break
umodem0: status change notification available
ucom0 at umodem0
vscsi0 at root
scsibus1 at vscsi0: 256 targets
softraid0 at root
scsibus2 at softraid0: 256 targets
bootfile: sd0a:/bsd
boot device: sd0
root on sd0a (b1debc2f56fad426.a) swap on sd0b dump on sd0b
This post is licensed under CC BY 4.0 by the author.