Cross-Compiling to ARM64 & .IMG

I am having trouble creating a .img file for a. RPI3 on BSD version 13, source code I acquired from Github.

I have successfully compiled AMD64 while creating a .img for AMD64-based architectures, but seem to be having trouble with creating a .img for another system architecture type.

Code:
make TARGET_ARCH=aarch64 buildworld
make TARGET_ARCH=aarch64 builkernel

Both compiled successfully, now it's time to create an arm64 based .img and I am looking for recommendations on what the best approach might be as I have tried using the "make-memstick.sh" in arm64 directory, but failed.

Thank you for any advice.
 
When Running Crochet: I can't seem to get the pkg I need.
Code:
pkg: No packages available to install matching 'u-boot-rpi3' have been found in the repositories.


I used Github and compiled the latest code (version 13). https://wiki.freebsd.org/arm/Build_image_using_release_building_infrastructure looks like a great source, but I am not sure how i should edit the file based on the fact I am running on a AMD64, while trying to build a .img for code I already compiled for arm64.

Without doing additional research at the moment, I think I can use the configuration example provided in that link. Could I please get a better example for RPI3.conf?

I saw u-boot-rpi3 on Github, but wasn't sure where I should clone it, maybe in "sysutils/"
Code:
EMBEDDEDPORTS="sysutils/u-boot-bananapi" --> EMBEDDEDPORTS="sysutils/u-boot-orangepi-pc"




Another Attempt, using another method using make-memstick.sh in the arm64 directory (/usr/src/release/arm64)

sh make-memstick.sh /usr/src /usr/BSDpi

Code:
set -e

PATH=/bin:/usr/bin:/sbin:/usr/sbin
export PATH

if [ $# -ne 2 ]; then
        echo "make-memstick.sh /path/to/directory /path/to/image/file"
        exit 1
fi

if [ ! -d ${1} ]; then
        echo "${1} must be a directory"
        exit 1
fi

if [ -e ${2} ]; then
        echo "won't overwrite ${2}"
        exit 1
fi

echo '/dev/ufs/FreeBSD_Install / ufs ro,noatime 1 1' > ${1}/etc/fstab
echo 'root_rw_mount="NO"' > ${1}/etc/rc.conf.local
makefs -B little -o label=FreeBSD_Install -o version=2 ${2}.part ${1}
rm ${1}/etc/fstab
rm ${1}/etc/rc.conf.local

mkimg -s gpt \
    -p efi:=${1}/boot/boot1.efifat \
    -p freebsd:=${2}.part \
    -o ${2}
rm ${2}.part

Failed:
Code:
:/usr/src/release/arm64 # sh make-memstick.sh /usr/src /usr/BSDpi
Calculated size of `/usr/BSDpi.part': 3465150464 bytes, 85496 inodes
Extent size set to 32768
/usr/BSDpi.part: 3304.6MB (6767872 sectors) block size 32768, fragment size 4096
        using 5 cylinder groups of 823.50MB, 26352 blks, 23424 inodes.
super-block backups (for fsck -b #) at:
     192, 1686720, 3373248, 5059776, 6746304,
Populating `/usr/BSDpi.part'
Image `/usr/BSDpi.part' complete
mkimg: partition 1: No such file or directory
 
I have tried that already, and this is what I get:

/usr/src/release # sh release.sh -c arm64/RPI3.conf

Code:
Illegal instruction (core dumped)
umount: /scratch/dev: statfs: No such file or directory
umount: /scratch/dev: unknown file system

I did not modify anything in RPI3.conf, mayby I need to?
 
Uhm... Illegal instruction usually occurs if you have a binary that uses instructions not supported by your CPU.
One slightly annoying issue with the release script is that it doesn't exit cleanly if it fails so you need to remove /scratch manually and possibly active mountpoints. I usually just reboot because of the latter otherwise it'll fail after a while..
 
I was hoping you weren't going to say that, but that's what I thought too after a little research. That script makes more sense to me now after reviewing the material you shared. I'll report back the VPS results later.


**UPDATE**
/usr/src/release
make memstick

I now have a AMD64 memstick.img that I made on MY server after recomiling everything for AMD64. I am still waiting for the VPS to finish cross-compiling to aarch64 and then I will run /usr/src/release # sh release.sh -c arm64/RPI3.conf



**VPS RESULTS**
make TARGET_ARCH=aarch64 buildkernel


Code:
--- modules-all ---
--- allwinner/sun50i-a64-nanopi-a64.dtb ---
Generating allwinner/sun50i-a64-nanopi-a64.dtb from /usr/src/sys/gnu/dts/arm64/allwinner/sun50i-a64-nanopi-a64.dts
sh: /usr/src/sys/tools/fdt/make_dtb.sh: Permission denied
*** [allwinner/sun50i-a64-nanopi-a64.dtb] Error code 126

make[4]: stopped in /usr/src/sys/modules/dtb/allwinner
1 error

make[4]: stopped in /usr/src/sys/modules/dtb/allwinner
*** [all_subdir_dtb/allwinner] Error code 2

make[3]: stopped in /usr/src/sys/modules
--- vfs_cluster.o ---
ctfconvert -L VERSION -g vfs_cluster.o
--- vfs_cache.o ---
ctfconvert -L VERSION -g vfs_cache.o
--- vfs_bio.o ---
ctfconvert -L VERSION -g vfs_bio.o
--- modules-all ---
--- all_subdir_dc ---
ctfconvert -L VERSION -g if_dc.o
A failure has been detected in another branch of the parallel make

make[4]: stopped in /usr/src/sys/modules/dc
*** [all_subdir_dc] Error code 2

make[3]: stopped in /usr/src/sys/modules
--- all_subdir_cxgbe ---
ctfconvert -L VERSION -g t4_hw.o
A failure has been detected in another branch of the parallel make

make[5]: stopped in /usr/src/sys/modules/cxgbe/if_cxgbe
*** [all_subdir_cxgbe/if_cxgbe] Error code 2

make[4]: stopped in /usr/src/sys/modules/cxgbe
1 error

make[4]: stopped in /usr/src/sys/modules/cxgbe
*** [all_subdir_cxgbe] Error code 2

make[3]: stopped in /usr/src/sys/modules
3 errors

make[3]: stopped in /usr/src/sys/modules
*** [modules-all] Error code 2

make[2]: stopped in /usr/obj/usr/src/arm64.aarch64/sys/GENERIC
1 error

make[2]: stopped in /usr/obj/usr/src/arm64.aarch64/sys/GENERIC
*** [buildkernel] Error code 2

make[1]: stopped in /usr/src
1 error

make[1]: stopped in /usr/src
*** [buildkernel] Error code 2

make: stopped in /usr/src
1 error

make: stopped in /usr/src

I was hoping for better results, but after buildworld I am failing at building the kernel at the moment, even though the same source compiled fine on my local server.
 
Not that I am aware of, but the VPS OS image must have something preset, that my local server does not. I have all source files dumped into /usr/src and buildworld executes/compiles fine, it's just the kernel compilation process that gets this permissions denied error.

I literally tried chmod 777, and touch in all directories, and this is being executed as root user, and this still gets denied. This compilation of the kernel would succeed if it were not for this permission error.

Any suggestions?
 
I started up a new VPS running Freebsd 12.1 x64 ufs and I ran the following command and I return no results.

mount | grep /usr/src ?

*UPDATE*
Upon deploying this OS image on the VPS the source files for compiling were already in /usr/src, and I avoided GitHub's code, which shouldn't matter. It's also a different system image than before as I am using another filesystem type, so my previous deployment had different preset settings/configurations. That's on the provider of the VPS, not me.

Anyways....I compiled the kernel and OS for arm64, and I am now running the shell script in release.
sh release.sh -c arm64/RPI3.conf

Waiting for it to finish at the moment, but so far all appears to be well.
 
I received this error:
Code:
===> usr.sbin/wpa/ndis_events (installconfig)
ELF ldconfig path: /lib /usr/lib /usr/lib/compat
32-bit compatibility ldconfig path: /usr/lib32
[Creating objdir /usr/obj/usr/src/amd64.amd64/release...]
===>  Deinstalling for u-boot-rpi3
/bin/sh: /usr/local/sbin/pkg-static: not found
===>   u-boot-rpi3 not installed, skipping
===>  License GPLv2 accepted by the user
===>   u-boot-rpi3-2020.07 depends on file: /usr/local/sbin/pkg - not found
===>  License BSD2CLAUSE accepted by the user
=> freebsd-pkg-1.14.6_GH0.tar.gz doesn't seem to exist in /tmp/distfiles/.
=> Attempting to fetch https://codeload.github.com/freebsd/pkg/tar.gz/1.14.6?dummy=/freebsd-pkg-1.14.6_GH0.tar.gz
freebsd-pkg-1.14.6_GH0.tar.gz                 Bad system call (core dumped)
=> Attempting to fetch http://distcache.FreeBSD.org/ports-distfiles/freebsd-pkg-1.14.6_GH0.tar.gz
freebsd-pkg-1.14.6_GH0.tar.gz                 Bad system call (core dumped)
=> Couldn't fetch it - please try to retrieve this
=> port manually into /tmp/distfiles/ and try again.
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/ports-mgmt/pkg
*** Error code 1

Stop.
make: stopped in /usr/ports/sysutils/u-boot-rpi3
I tried installing it, but it is not fetching it. I installed u-boot-rpi3 though and re-tried, and still nothing of course until I get that other package.
 
I received this error:
Code:
===> usr.sbin/wpa/ndis_events (installconfig)
ELF ldconfig path: /lib /usr/lib /usr/lib/compat
32-bit compatibility ldconfig path: /usr/lib32
[Creating objdir /usr/obj/usr/src/amd64.amd64/release...]
===>  Deinstalling for u-boot-rpi3
/bin/sh: /usr/local/sbin/pkg-static: not found
===>   u-boot-rpi3 not installed, skipping
===>  License GPLv2 accepted by the user
===>   u-boot-rpi3-2020.07 depends on file: /usr/local/sbin/pkg - not found
===>  License BSD2CLAUSE accepted by the user
=> freebsd-pkg-1.14.6_GH0.tar.gz doesn't seem to exist in /tmp/distfiles/.
=> Attempting to fetch https://codeload.github.com/freebsd/pkg/tar.gz/1.14.6?dummy=/freebsd-pkg-1.14.6_GH0.tar.gz
freebsd-pkg-1.14.6_GH0.tar.gz                 Bad system call (core dumped)
=> Attempting to fetch http://distcache.FreeBSD.org/ports-distfiles/freebsd-pkg-1.14.6_GH0.tar.gz
freebsd-pkg-1.14.6_GH0.tar.gz                 Bad system call (core dumped)
=> Couldn't fetch it - please try to retrieve this
=> port manually into /tmp/distfiles/ and try again.
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/ports-mgmt/pkg
*** Error code 1

Stop.
make: stopped in /usr/ports/sysutils/u-boot-rpi3
I tried installing it, but it is not fetching it. I installed u-boot-rpi3 though and re-tried, and still nothing of course until I get that other package.
Are you possibly trying to build -HEAD on a box that runs 12.1/-STABLE?
 
I found this in release.sh
Code:
# The default svn checkout server, and svn branches for src/, doc/,
        # and ports/.
        SVNROOT="svn://svn.FreeBSD.org/"
        SRCBRANCH="src/head@rHEAD"
        DOCBRANCH="doc/head@rHEAD"
        PORTBRANCH="ports/head@rHEAD"

I also made a copy of release.conf.sample, now since I am running this sh release.sh -c arm64/RPI3.conf , wouldn't I just edit the release.sh file, instead of release.conf or both?

release.conf
Code:
## Set the directory within which the release will be built.
CHROOTDIR="/scratch"

## Set the svn host.
SVNROOT="svn://svn.FreeBSD.org/"

## Set the src/, ports/, and doc/ branches or tags.
SRCBRANCH="base/stable/12@rHEAD"
DOCBRANCH="doc/head@rHEAD"
PORTBRANCH="ports/head@rHEAD"

## Run svn co --force for src checkout.
#SRC_FORCE_CHECKOUT=yes

UPDATE:
This resource was helpful, but I am still wondering what I need to change the default sources above to? In the beginning I just went to /usr/src and completed a buildworld for arm64, that was it.
 
Last edited:
That attempt last night failed with the same error, so i am now using Crochet

Code:
/usr/crochet # sh crochet.sh -b RaspberryPi3
Starting at Sun Jul 26 14:09:29 UTC 2020
Board: RaspberryPi3
Source version is: unknown
Building FreeBSD version: 12.1
Image name is:
    /usr/crochet/work/FreeBSD-aarch64-12-GENERIC-RaspberryPi3.img
Building FreeBSD version: 12.1
Object files are at: /usr/crochet/work/obj/usr/src
Found suitable FreeBSD source tree in:
    /usr/src
Found U-Boot port in:
    /usr/local/share/u-boot/u-boot-rpi3
Found firmware port in:
    /usr/local/share/rpi-firmware
Building FreeBSD aarch64 world at Sun Jul 26 14:09:29 UTC 2020
    (Logging to /usr/crochet/work/_.buildworld.aarch64.log)

It's rebuilding everything, hopefully it works...o_O
 
Code:
DONE.
Completed disk image is in: /usr/crochet/work/FreeBSD-aarch64-12-GENERIC-RaspberryPi3.img

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

That was easy, but I am just wondering why I could not get my other method to work? 🤔
 
Back
Top