Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 29 Nov 2019 22:36:07 +0000
From:      James Shuriff <james@opentech.cc>
To:        Peter Jeremy <peter@rulingia.com>
Cc:        Ian Lepore <ian@freebsd.org>, "freebsd-arm@freebsd.org" <freebsd-arm@freebsd.org>
Subject:   RE: rpi3 clock drift
Message-ID:  <MWHPR06MB313459626ADCE36F829ABDABAA460@MWHPR06MB3134.namprd06.prod.outlook.com>
In-Reply-To: <20191129220311.GD37113@server.rulingia.com>
References:  <MWHPR06MB3134EC22EC3148DA800B2B7DAA440@MWHPR06MB3134.namprd06.prod.outlook.com> <alpine.BSF.2.21.99999.352.1911272214050.28592@autopsy.pc.athabascau.ca> <20191129052800.GA37113@server.rulingia.com> <alpine.BSF.2.21.99999.352.1911282333250.90234@autopsy.pc.athabascau.ca> <65be6d3628a8d35084f7c98266582090f59b18be.camel@freebsd.org> <alpine.BSF.2.21.99999.352.1911291053140.17959@autopsy.pc.athabascau.ca> <MWHPR06MB313445553D73F019FEEAF50EAA460@MWHPR06MB3134.namprd06.prod.outlook.com> <731a9e57ba62d5a6ede74fdde3fd82543484813b.camel@freebsd.org> <MWHPR06MB3134455800AD75C949D86D8FAA460@MWHPR06MB3134.namprd06.prod.outlook.com> <MWHPR06MB3134E3913675771F14E3C4B3AA460@MWHPR06MB3134.namprd06.prod.outlook.com> <20191129220311.GD37113@server.rulingia.com>

index | next in thread | previous in thread | raw e-mail

[-- Attachment #1 --]
I was looking at the generic_timer.c code and it probes for "arm,armv8-timer" or "arm,armv7-timer". I was thinking of trying to add clock-frequency directly into "timer". ARM MPCore Timecounter is generic_timer.c. That was my next idea, to try copying over some of the binaries from FreeBSD's RPI3 image one at a time to try identifying where the issue is.

My latest build is U-Boot from the git repo with the v2019.10 tag using rpi_3_defconfig with OF_EMBED=n and OF_BOARD=y the former telling U-Boot not to embed the FDT into the binary and the latter informs U-Boot that the FDT will be provided by the board at runtime (start.elf looks for " bcm%d-rpi-%s.dtb"). I get config.txt from /usr/ports/sysutils/rpi-firmware/files/config_rpi3.txt. I build U-Boot with the Clang and ld.lld (which was no small effort!). The binary blobs I get from the Raspberry Pi repository. I build PSCI Monitor from its repo. I get the overlays from the output of my FreeBSD build. I've attached the script I use to build the FAT partition, if you're curious.

- James Shuriff

-----Original Message-----
From: Peter Jeremy <peter@rulingia.com>
Sent: Friday, November 29, 2019 5:03 PM
To: James Shuriff <james@opentech.cc>
Cc: Ian Lepore <ian@freebsd.org>; freebsd-arm@freebsd.org
Subject: Re: rpi3 clock drift

On 2019-Nov-29 20:37:36 +0000, James Shuriff <james@opentech.cc> wrote:
>I dumped the FDT from the system I built from source and I cannot find
>any reference to 0x337F980 (54 MHz). I looked at the FreeBSD source
>file generic_timer.c and it looks like it's grabbing the frequency from
>FDT but I cannot figure out where it's getting the 54 MHz from. clk_osc
>in the FDT is still showing 0x124f800 (19.2 MHz) on the system with the
>bad clock.

I've been rummaging around on my (early) RPi2.  The timer code seems to be the same, even if the SoC is different (I have armv7, RPi3 is armv8).

In my FDT, I have:
        timer {

                compatible = "arm,armv7-timer";
                interrupt-parent = <0x3>;
                interrupts = <0x0 0x1 0x3 0x2>;
                always-on;
        };
There's no clock-frequency clause there and no (obvious) link to:
        clocks {
                compatible = "simple-bus";
                #address-cells = <0x1>;
                #size-cells = <0x0>;
                clock@3 {
                        compatible = "fixed-clock";
                        reg = <0x3>;
                        #clock-cells = <0x0>;
                        clock-output-names = "osc";
                        clock-frequency = <0x124f800>;
                        phandle = <0x4>;
                };
...
        };

The relevant dmesg should look like:
generic_timer0: <ARMv7 Generic Timer> irq 0,1,2,3 on ofwbus0 Timecounter "ARM MPCore Timecounter" frequency 19200000 Hz quality 1000 Event timer "ARM MPCore Eventtimer" frequency 19200000 Hz quality 1000

At least on my RPi2, I have:
Using DTB provided by EFI at 0x7ff8000.
and

FreeBSD/arm EFI loader, Revision 1.1
   Command line arguments: l
   EFI version: 2.70
   EFI Firmware: Das U-Boot (rev 8216.2304)
   Console: efi (0)
   Load Path: /\efi\boot\bootarm.efi

Are you building a 32-bit or 64-bit FreeBSD?
Where are you getting your boot code from?
Have you tried using the boot code from the FreeBSD RPi3 image with your kernel?

--
Peter Jeremy
________________________________
 DISCLAIMER: This message and any attachments are intended solely for the use of the recipient and may contain confidential information. If you have received this message in error please delete it and promptly notify the sender, James Shuriff (james@opentech.cc<mailto:james@opentech.cc>).

[-- Attachment #2 --]
#/bin/tcsh

if (`uname -m` == arm64) then
 set BOOTFS=/boot/firmware/

 set UEFI_LOADER_PATH = /boot/loader_lua.efi
 set DTB_AW_PATH=/boot/dtb/allwinner/
 set DTB_OL_PATH=/boot/dtb/overlays/
else
 set BOOTFS=/mnt/bootfs/

 set MAKEOBJDIRPREFIX=/usr/obj
 set SRCDIR="/usr/src.head"
 set KERNCONF=OTCC

 set UEFI_LOADER_PATH = $MAKEOBJDIRPREFIX/$SRCDIR/arm64.aarch64/stand/efi/loader_lua/loader_lua.efi
 set DTB_AW_PATH=$MAKEOBJDIRPREFIX/$SRCDIR/arm64.aarch64/sys/$KERNCONF/modules/$SRCDIR/sys/modules/dtb/allwinner/
 set DTB_OL_PATH=$MAKEOBJDIRPREFIX/$SRCDIR/arm64.aarch64/sys/$KERNCONF/modules/$SRCDIR/sys/modules/dtb/allwinner/
endif

set FIRMWARE_REPO_PATH = /root/rpi/firmware/boot/
set UBOOT_BIN_PATH=/root/src/u-boot/u-boot.bin
set PSCI_MON_PATH = /root/rpi/rpi3-psci-monitor/armstub8.bin
set FIRMWARE_CONFIG_PATH = /usr/ports/sysutils/rpi-firmware/files/config_rpi3.txt

# End of Config

set DTB_AW_FILES = (sun50i-a64-nanopi-a64.dtb sun50i-a64-olinuxino.dtb sun50i-a64-pine64-plus.dtb sun50i-a64-pine64.dtb sun50i-a64-sopine-baseboard.dtb sun50i-h5-orangepi-pc2.dtb)
set DTB_OL_FILES = (sun50i-a64-sid.dtbo sun50i-a64-ths.dtbo sun50i-a64-timer.dtbo)

set FIRMWARE_REPO_FILES = (LICENCE.broadcom bootcode.bin fixup.dat fixup_cd.dat fixup_db.dat fixup_x.dat start.elf start_cd.elf start_db.elf start_x.elf bcm2710-rpi-3-b.dtb)
#set FIRMWARE_CUSTOM_FILES = (/root/rpi/bcm2710-rpi-3-b.dtb)

# i2c-rtc is for optional I2C RTC. Config.txt must be modified to support it.
set FIRMWARE_OL_PATH = $FIRMWARE_REPO_PATH/overlays
set FIRMWARE_OL_FILES = (mmc.dtbo pi3-disable-bt.dtbo pwm.dtbo i2c-rtc.dtbo)

# /
foreach x ($FIRMWARE_REPO_FILES)
	cp $FIRMWARE_REPO_PATH/$x $BOOTFS
end
#foreach x ($FIRMWARE_CUSTOM_FILES)
#	cp $FIRMWARE_CUSTOM_FILES $BOOTFS
#end
cp $PSCI_MON_PATH $UBOOT_BIN_PATH $BOOTFS
cp $FIRMWARE_CONFIG_PATH $BOOTFS/config.txt

# /overlays
mkdir -p $BOOTFS/overlays
foreach x ($FIRMWARE_OL_FILES)
	cp $FIRMWARE_OL_PATH/$x $BOOTFS/overlays/
end

# DTB
mkdir -p $BOOTFS/dtb/allwinner $BOOTFS/dtb/overlays
foreach x ($DTB_AW_FILES)
	cp $DTB_AW_PATH/$x $BOOTFS/dtb/allwinner/
end
foreach x ($DTB_OL_FILES)
	cp $DTB_OL_PATH/$x $BOOTFS/dtb/overlays/
end

# EFI
# loader_lua.efi is a hard link with loader.efi
mkdir -p $BOOTFS/EFI/BOOT
cp $UEFI_LOADER_PATH $BOOTFS/EFI/BOOT/bootaa64.efi
help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?MWHPR06MB313459626ADCE36F829ABDABAA460>