# RPi3 12.0-CURRENT Kernel Build



## vchan (Sep 9, 2017)

I'm having an issue building my kernel, and I'm not sure what is causing it. This is what I am getting:

```
linking kernel.full
unknown emulation: aarch64elf
line 19: : expected, but got (
  PROVIDE (etext = .);
          ^
*** Error code 1

Stop.
make[2]: stopped in /usr/obj/usr/src/sys/MYKERNEL
*** Error code 1

Stop.
make[1]: stopped in /usr/src
*** Error code 1

Stop.
make: stopped in /usr/src
```
Any advice would be greatly appreciated.


----------



## Phishfry (Sep 9, 2017)

Have you tried using Crochet to build an image? It is quite easy.
https://github.com/freebsd/crochet

`pkg install u-boot-rpi3 aarch64-binutils`
`git clone https://github.com/freebsd/crochet /crochet`
`cd /crochet`
`./crochet.sh -b RaspberryPi3`

After completion image name will be shown. Your image may have a different name.

`cd /crochet/work`
`dd if=FreeBSD-aarch64-12-GENERIC-UP.img of=/dev/da0 bs=10240 conv=sync`


----------



## vchan (Sep 9, 2017)

I'm just trying to compile a new kernel on my RPi3 itself. I shouldn't need crochet to do a simple make buildkernel KERNCONF=MYKERNEL I have also tried with adding TARGET=arm64


----------



## vchan (Sep 9, 2017)

I don't understand your meaning.


----------



## Phishfry (Sep 9, 2017)

I wrote something ignorant and deleted it.
My point is why fight it. I am presenting the easiest method. Use it and study the results. Then try to build your own.
For instance: RPi3 is probably the hardest of all Arm builds. Have you built any well supported devices like RPi2?
Crossbuilding for Arm is not easy. I would rate it complex.


----------



## vchan (Sep 9, 2017)

Yes RPi3 is very hard to build. I tried using Crochet to build my image, but I wasn't able to get it working right. I found the image I'm currently useing from http://www.raspbsd.org/. So right now I'm just wanting to update my kernel. I've tried building a generic kernel as well as a custom one, but I keep getting the error I posted in my initial post no matter the configuration.


----------



## Phishfry (Sep 9, 2017)

You do realize that swapping kernels is not really the way to upgrade FreeBSD.
Swapping/upgrading kernels is used more for adding devices or services which are not supported.
You really need to build the whole world. Swapping in a kernel from a different source tree sounds like a disaster.

I just used my instructions for Crochet after I just downloaded the newest source with svnlite co .
I am using my instructions exactly on a fresh build box. What part of Crochet did not work for you?


vchan said:


> unknown emulation: aarch64elf


I am pretty sure this is a problem. Are you sure your setenv is correctly set to aarch64?

What is the kernconf you are using for building your kernel? There is no RPI3 kernconf in source. Are you using -GENERIC on ARM64?


----------



## Phishfry (Sep 9, 2017)

OK Just finished. All compiled fine. Updated the source on my 11.1 Build box.
`svnlite co https://svn.freebsd.org/base/head /usr/src/`
`pkg install u-boot-rpi3 aarch64-binutils git`

```
root@gigabyte:~ #  git clone https://github.com/freebsd/crochet /crochet
Cloning into '/crochet'...
remote: Counting objects: 5233, done.
remote: Total 5233 (delta 0), reused 0 (delta 0), pack-reused 5233
Receiving objects: 100% (5233/5233), 8.14 MiB | 13.56 MiB/s, done.
Resolving deltas: 100% (2715/2715), done.
root@gigabyte:~ # cd /crochet
root@gigabyte:/crochet #  ./crochet.sh -b RaspberryPi3
Starting at Sat Sep 9 18:17:33 EDT 2017
Board: RaspberryPi3
Source version is: 323380M
Building FreeBSD version: 11.1
Image name is:
    /crochet/work/FreeBSD-aarch64-11.1-GENERIC-323380M-RaspberryPi3.img
Building FreeBSD version: 11.1
Object files are at: /crochet/work/obj/arm64.aarch64/usr/src
Found suitable FreeBSD source tree in:
    /usr/src
Found U-Boot port in:
    /usr/local/share/u-boot/u-boot-rpi3
Building FreeBSD aarch64 world at Sat Sep 9 18:17:34 EDT 2017
    (Logging to /crochet/work/_.buildworld.aarch64.log)
Building FreeBSD aarch64-GENERIC kernel at Sat Sep 9 18:49:15 EDT 2017
    (Logging to /crochet/work/_.buildkernel.aarch64-GENERIC.log)
Building FreeBSD aarch64-GENERIC efi at Sat Sep 9 18:50:58 EDT 2017
    (Logging to /crochet/work/efi-aarch64-GENERIC/_.efi.aarch64-GENERIC.build.log)
Creating a 2000MB raw disk image in:
    /crochet/work/FreeBSD-aarch64-11.1-GENERIC-323380M-RaspberryPi3.img
Partitioning the raw disk image with MBR at Sat Sep 9 18:51:02 EDT 2017
gpart create -s MBR md0
md0 created
Creating a 50m FAT partition at Sat Sep 9 18:51:02 EDT 2017 with start block 63 and label BOOT
active set on md0s1
Creating an auto-sized UFS partition at Sat Sep 9 18:51:02 EDT 2017
md0s2 created
/dev/md0s2a: 1856.4MB (3801984 sectors) block size 32768, fragment size 4096
   using 4 cylinder groups of 464.12MB, 14852 blks, 59520 inodes.
super-block backups (for fsck_ffs -b #) at:
 192, 950720, 1901248, 2851776
tunefs: soft updates set
Using inode 4 in cg 0 for 4194304 byte journal
tunefs: soft updates journaling set
tunefs: NFSv4 ACLs set
Mounting all file systems:
Mounting FAT partition 1 at /crochet/work/_.mount.boot
Mounting UFS partition 1 at /crochet/work/_.mount.freebsd
bcm2710-rpi-3-b.dtb                           100% of   17 kB 1328 kBps 00m00s
overlays/mmc.dtbo                             100% of 1099  B   18 MBps 00m00s
overlays/pi3-disable-bt.dtbo                  100% of  818  B   15 MBps 00m00s
Installing boot1.efi in aarch64
Installing FreeBSD world at Sat Sep 9 18:51:04 EDT 2017
    Destination: /crochet/work/_.mount.freebsd
Overlaying board-specific files from /crochet/board/RaspberryPi3/overlay
2 blocks
Installing FreeBSD kernel at Sat Sep 9 18:51:52 EDT 2017
    Destination: /crochet/work/_.mount.freebsd
Unmounting /crochet/work/_.mount.boot
Unmounting /crochet/work/_.mount.freebsd
Releasing md0
DONE.
Completed disk image is in: /crochet/work/FreeBSD-aarch64-11.1-GENERIC-323380M-RaspberryPi3.img

Copy to a suitable memory card using a command such as:
dd if=/crochet/work/FreeBSD-aarch64-11.1-GENERIC-323380M-RaspberryPi3.img of=/dev/da0 bs=1m
(Replace /dev/da0 with the appropriate path for your card reader.)

Finished at Sat Sep 9 18:51:58 EDT 2017
```


----------



## vchan (Sep 10, 2017)

I tried the generic kernel conf, but this is my config:

```
#
# GENERIC -- Generic kernel configuration file for FreeBSD/arm64
#
# For more information on this file, please read the config(5) manual page,
# and/or the handbook section on Kernel Configuration Files:
#
#    http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-config.html
#
# The handbook is also available locally in /usr/share/doc/handbook
# if you've installed the doc distribution, otherwise always see the
# FreeBSD World Wide Web server (http://www.FreeBSD.org/) for the
# latest information.
#
# An exhaustive list of options and more detailed explanations of the
# device lines is also present in the ../../conf/NOTES and NOTES files.
# If you are in doubt as to the purpose or necessity of a line, check first
# in NOTES.
#
# $FreeBSD: head/sys/arm64/conf/GENERIC 321942 2017-08-02 20:19:19Z manu $

cpu       ARM64
ident       GENERIC

makeoptions   DEBUG=-g       # Build kernel with gdb(1) debug symbols
makeoptions   WITH_CTF=1       # Run ctfconvert(1) for DTrace support

options    SCHED_ULE       # ULE scheduler
options    PREEMPTION       # Enable kernel thread preemption
options    INET           # InterNETworking
options    INET6           # IPv6 communications protocols
options    IPSEC           # IP (v4/v6) security
options    TCP_HHOOK       # hhook(9) framework for TCP
options    TCP_OFFLOAD       # TCP offload
options    SCTP           # Stream Control Transmission Protocol
options    FFS           # Berkeley Fast Filesystem
options    SOFTUPDATES       # Enable FFS soft updates support
options    UFS_ACL           # Support for access control lists
options    UFS_DIRHASH       # Improve performance on big directories
options    UFS_GJOURNAL       # Enable gjournal-based UFS journaling
options    QUOTA           # Enable disk quotas for UFS
options    MD_ROOT           # MD is a potential root device
options    NFSCL           # Network Filesystem Client
options    NFSD           # Network Filesystem Server
options    NFSLOCKD       # Network Lock Manager
options    NFS_ROOT       # NFS usable as /, requires NFSCL
#options    MSDOSFS           # MSDOS Filesystem
#options    CD9660           # ISO 9660 Filesystem
options    PROCFS           # Process filesystem (requires PSEUDOFS)
options    PSEUDOFS       # Pseudo-filesystem framework
options    GEOM_PART_GPT       # GUID Partition Tables.
#options    GEOM_RAID       # Soft RAID functionality.
options    GEOM_LABEL       # Provides labelization
options    COMPAT_FREEBSD11   # Compatible with FreeBSD11
options    SCSI_DELAY=5000       # Delay (in ms) before probing SCSI
options    KTRACE           # ktrace(1) support
options    STACK           # stack(9) support
options    SYSVSHM           # SYSV-style shared memory
options    SYSVMSG           # SYSV-style message queues
options    SYSVSEM           # SYSV-style semaphores
options    _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time extensions
options    PRINTF_BUFR_SIZE=128   # Prevent printf output being interspersed.
options    KBD_INSTALL_CDEV   # install a CDEV entry in /dev
options    HWPMC_HOOKS       # Necessary kernel hooks for hwpmc(4)
options    AUDIT           # Security event auditing
options    CAPABILITY_MODE       # Capsicum capability mode
options    CAPABILITIES       # Capsicum capabilities
options    MAC           # TrustedBSD MAC Framework
options    KDTRACE_FRAME       # Ensure frames are compiled in
options    KDTRACE_HOOKS       # Kernel DTrace hooks
options    VFP           # Floating-point support
options    RACCT           # Resource accounting framework
options    RACCT_DEFAULT_TO_DISABLED # Set kern.racct.enable=0 by default
options    RCTL           # Resource limits
options    SMP
options    INTRNG

# Debugging support.  Always need this:
options    KDB           # Enable kernel debugger support.
options    KDB_TRACE       # Print a stack trace for a panic.
# For full debugger support use (turn off in stable branch):
#options    DDB           # Support DDB.
#options    GDB           # Support remote GDB.
#options    DEADLKRES       # Enable the deadlock resolver
#options    INVARIANTS       # Enable calls of extra sanity checking
#options    INVARIANT_SUPPORT   # Extra sanity checks of internal structures, required by INVARIANTS
#options    WITNESS           # Enable checks to detect deadlocks and cycles
#options    WITNESS_SKIPSPIN   # Don't run witness on spinlocks for speed
#options    MALLOC_DEBUG_MAXZONES=8   # Separate malloc(9) zones

# SoC support
#options    SOC_ALLWINNER_A64
#options    SOC_ALLWINNER_H5
#options    SOC_CAVM_THUNDERX
#options    SOC_HISI_HI6220
#options    SOC_BRCM_BCM2837

# Annapurna Alpine drivers
#device       al_ccu           # Alpine Cache Coherency Unit
#device       al_nb_service       # Alpine North Bridge Service
#device       al_iofic       # I/O Fabric Interrupt Controller
#device       al_serdes       # Serializer/Deserializer
#device       al_udma           # Universal DMA

# VirtIO support
#device       virtio
#device       virtio_pci
#device       virtio_mmio
#device       virtio_blk
#device       vtnet

# CPU frequency control
device       cpufreq

# Bus drivers
#device       pci
#device       al_pci       # Annapurna Alpine PCI-E
#options    PCI_HP           # PCI-Express native HotPlug
#options    PCI_IOV       # PCI SR-IOV support

# Ethernet NICs
#device       mii
#device       miibus       # MII bus support
#device       awg       # Allwinner EMAC Gigabit Ethernet
#device       axgbe       # AMD Opteron A1100 integrated NIC
#device       em       # Intel PRO/1000 Gigabit Ethernet Family
#device       ix       # Intel 10Gb Ethernet Family
#device       msk       # Marvell/SysKonnect Yukon II Gigabit Ethernet
device      smc       # SMSC LAN91C111
#device       vnic       # Cavium ThunderX NIC
#device       al_eth       # Annapurna Alpine Ethernet NIC

# Block devices
device       ahci
device       scbus
device       da

# ATA/SCSI peripherals
device       pass       # Passthrough device (direct ATA/SCSI access)

# MMC/SD/SDIO Card slot support
device       sdhci
#device       aw_mmc           # Allwinner SD/MMC controller
device       mmc           # mmc/sd bus
device       mmcsd           # mmc/sd flash cards
#device       dwmmc

# Serial (COM) ports
device       uart       # Generic UART driver
#device       uart_ns8250   # ns8250-type UART driver
#device       uart_snps
#device       pl011

# USB support
options    USB_DEBUG       # enable debug msgs
#device       aw_ehci           # Allwinner EHCI USB interface (USB 2.0)
#device       aw_usbphy       # Allwinner USB PHY
device       dwcotg           # DWC OTG controller
#device       ohci           # OHCI USB interface
#device       ehci           # EHCI USB interface (USB 2.0)
#device       xhci           # XHCI PCI->USB interface (USB 3.0)
device       usb           # USB Bus (required)
device       ukbd           # Keyboard
device       umass           # Disks/Mass storage - Requires scbus and da

# USB ethernet support
device       smcphy
device       smsc

# GPIO
#device       aw_gpio       # Allwinner GPIO controller
device       gpio
device       gpioled
#device       fdt_pinctrl

# I2C
#device       aw_rsb       # Allwinner Reduced Serial Bus
device       bcm2835_bsc   # Broadcom BCM283x I2C bus
device       iicbus
device       iic
#device       twsi       # Allwinner I2C controller

# Clock and reset controllers
#device       aw_ccu       # Allwinner clock controller

# Interrupt controllers
#device       aw_nmi       # Allwinner NMI support

# Real-time clock support
#device       aw_rtc       # Allwinner Real-time Clock

# Watchdog controllers
#device       aw_wdog       # Allwinner Watchdog

# Power management controllers
#device       axp81x       # X-Powers AXP81x PMIC

# EFUSE
#device       aw_sid       # Allwinner Secure ID EFUSE

# Thermal sensors
#device       aw_thermal   # Allwinner Thermal Sensor Controller

# SPI
device       spibus
device       bcm2835_spi   # Broadcom BCM283x SPI bus

# Console
device       vt
device       kbdmux

# Pseudo devices.
device       loop       # Network loopback
device       random       # Entropy device
device       ether       # Ethernet support
device       vlan       # 802.1Q VLAN support
device       tun       # Packet tunnel.
device       md       # Memory "disks"
device       gif       # IPv6 and IPv4 tunneling
device       firmware   # firmware assist module
device       psci       # Support for ARM PSCI

# EXT_RESOURCES pseudo devices
options    EXT_RESOURCES
device       clk
device       phy
device       hwreset
device       regulator

# The `bpf' device enables the Berkeley Packet Filter.
# Be aware of the administrative consequences of enabling this!
# Note that 'bpf' is required for DHCP.
device       bpf       # Berkeley packet filter

# Chip-specific errata
options    THUNDERX_PASS_1_1_ERRATA

options    FDT
device       acpi

# The crypto framework is required by IPSEC
device       crypto           # Required by IPSEC
```

I also realize that you generally buildworld as well, and I plan to do that. One problem at a time I figure.

Also I did get Crochet to build an img, but I was never able to get it to boot.


----------



## Phishfry (Sep 10, 2017)

I just got back and realized I built that on FreeBSD 11.1. Even with -CURRENT source it won't work. I am checking now.
You must use crochet on FreeBSD -CURRENT for RPi3.
The RaspBSD image is created with Crochet.


----------



## Phishfry (Sep 10, 2017)

Yes that image from 11.1 won't boot. I am updating my FreeBSD -CURRENT box now. I will let you know how it works when complete.


----------



## vchan (Sep 10, 2017)

Looks like I'm not the only one with this issue. https://github.com/freebsd/crochet/issues/193


----------



## Phishfry (Sep 11, 2017)

Mine didn't boot either but I think I know where the real problem is- u-boot. It has been through some recent changes. 
That is where my money is. Find an older version of the u-boot-rpi3 port and I bet it works..
I say that because u-boot is the first thing to load and it does not. My image from March -CURRENT does.
It is possible the crochet board file might need updating for the new u-boot work.
I didn't see any FreeBSD Arm mailing lists mentioning any rpi3 problems.


----------



## vchan (Sep 14, 2017)

I don't think the FreeBSD Arm mailing list is working properly. I sent an email about my problem, and never got anything back.


----------



## Phishfry (Sep 14, 2017)

Looking here I don't see your question:

https://lists.freebsd.org/pipermail/freebsd-arm/2017-September/thread.html

No one will email you back, it is a list and you must check it for answers.


----------



## Phishfry (Sep 14, 2017)

Another avenue is the bsd-mips IRC chat room. It is full of FreeBSD developers.


----------

