Solved OrangePiPC2

Hello. how to build ubldr for arm64 from freebsd 12 sources? I'm trying to build an image for orange pi pc2. Created two partitions, fat and ufs. Recorded uboot withspl, made installworld installkernel all successful. It is not clear what files need to do for the fat partition.
thanks.

a draft of the script
Code:
#!/bin/sh
export HOSTNAME=rpc-opipc2
#sun50i-h5-orangepi-prime
export DTBFILE=sun50i-h5-orangepi-pc2.dtb
export DTSFILE=sun50i-h5-orangepi-pc2.dts
#base dir
#setenv = export
export BASEDIR=/home/bormental/arm64/head_orange_pi_pc2
#kyda kladem skompilennoe
export MAKEOBJDIRPREFIX=$BASEDIR/obj
#aarch64
export TARGET=arm64
export TARGET_ARCH=aarch64
export MACHINE=arm64
#42000000
export UBLDR_LOADADDR=0x4a000000
export KERNCONF=SOC
export IMGFILENAME=OrangePiPC2.img
export SIZEIMGMB=2048
export __MAKE_CONF=/dev/null
export SRCCONF=/dev/null

export UBOOTBIN=/usr/local/share/u-boot/u-boot-orangepi-pc2/u-boot-sunxi-with-spl.bin
export UBOOTPORTS=/usr/ports/sysutils/u-boot-orangepi-pc2

export IP=192.168.0.100
export IPMASK=/24
export DNS=192.168.0.1
export GATE=192.168.0.1
#export IP=DHCP
#export IPMASK=
#export DNS=
#export GATE=

#export CPUTYPE=armv6 #for cortex-a53 sun50i aarch64
#poluchim ishodniki freebsd
cd $BASEDIR

if [ "$1" = "" ];
then
    echo "usage: $0.sh [all|src|mkworld|mkkernel|dtb|img]"
fi

if [ "$1" = "all" ] || [ "$1" = "src" ];
then
    if [ ! -d $BASEDIR/src/.git ]
    then
        rm -rf $BASEDIR/src
        git clone git://github.com/freebsd/freebsd.git src
    else
        cd $BASEDIR/src
        git fetch git://github.com/freebsd/freebsd.git
    fi
    cd $BASEDIR/src
    git checkout master #project/arm64
fi

if [ "$1" = "all" ] || [ "$1" = "mkworld" ];
then
    cd $BASEDIR/src

    echo 'clear old obj..'
    rm -rf $BASEDIR/obj
    echo 'make tool chain for crossbuild..'
    make -j $(sysctl -n hw.ncpu) kernel-toolchain > $BASEDIR/maketoolchain.log #TARGET=arm64 TARGET_ARCH=aarch64
    echo 'build world with fdt files for SoC...'
    make -j $(sysctl -n hw.ncpu) buildworld -DWITH_FDT > $BASEDIR/buildworld.log #KERNCONF=MYGENERIC TARGET=arm64 TARGET_ARCH=aarch64 UBLDR_LOADADDR=0x42000000 #__MAKE_CONF=/dev/null
    echo 'next step make mkkernel...'
fi

if [ "$1" = "all" ] || [ "$1" = "mkkernel" ];
then
    cd $BASEDIR/src

    if [ -f $BASEDIR/src/sys/arm64/conf/$KERNCONF ];
    then
        echo "${KERNCONF} kernel conf file exists, overrite.."
    fi
    echo 'create kernel conf file '${KERNCONF}
    #create my kernconf
    #for emb dev no suppurt loader use FDT_DTB_STATIC
    #/usr/home/bormental/arm64/head_orange_pi_pc2/src/sys/gnu/dts/arm64/allwinner/
    echo '
include         GENERIC-NODEBUG
ident           '$KERNCONF'
#for embedded kernel dtb
#makeoptions    FDT_DTS_FILE='${BASEDIR}'/src/sys/gnu/dts/arm64/allwinner/'${DTSFILE}'
#options                FDT_DTB_STATIC
    ' > $BASEDIR/src/sys/arm64/conf/$KERNCONF
    #cp $BASEDIR/src/sys/arm64/conf/GENERIC-NODEBUG $BASEDIR/src/sys/arm64/conf/$KERNCONF

    echo 'buld kernel..'
    make -j $(sysctl -n hw.ncpu) buildkernel > $BASEDIR/buildkernel.log #KERNCONF=NYGENERIC TARGET=arm64 TARGET_ARCH=aarch64 #__MAKE_CONF=/dev/null
    echo 'next step make img...'
fi

if [ "$1" = "all" ] || [ "$1" = "dtb" ];
then
    cd $BASEDIR/src

    mkdir $BASEDIR/dtb/
    rm -rf $BASEDIR/dtb/*
    $BASEDIR/src/sys/tools/fdt/make_dtb.sh $BASEDIR/src/sys $BASEDIR/src/sys/gnu/dts/arm64/allwinner/${DTSFILE} $BASEDIR/dtb/

fi

if [ "$1" = "all" ] || [ "$1" = "img" ];
then
    echo 'build image disk...'
    cd $BASEDIR
    dd if=/dev/zero of=$BASEDIR/$IMGFILENAME bs=1M count=$SIZEIMGMB

    #perenesti v mk?
    if ! [ -e ${UBOOTBIN} ];
    then
    #pkg install u-boot-orangepi-pc2
    cd ${UBOOTPORTS}
    make -DBATCH all install
    fi

    #dlya pi pc2 spl i u-boot v odnom file
    dd if=/usr/local/share/u-boot/u-boot-orangepi-pc2/u-boot-sunxi-with-spl.bin of=$BASEDIR/$IMGFILENAME bs=1K seek=8 conv=sync,notrunc #count=$SIZEIMGMB

    MEMORYDISK=`mdconfig -a -t vnode -f $BASEDIR/$IMGFILENAME` #-x 63 -y 255`  #-x -y from crochet.sh smisl ih poka ne ponyaten
    #md lists real hdd - > sysctl kern.disks
    mdconfig -l
    echo $MEMORYDISK

    gpart create -s MBR $MEMORYDISK #GPT MBR gpart destroy md0

    #start block 1024k = -b 1m for allwinner
    #gpart add -a 63 -b 1m -s 32m -t '!12' $MEMORYDISK # !12 - w95 fat32 -a 63 = 63*512
    BOOT_PART=`gpart add -b 1m -s 100m -t fat16 $MEMORYDISK | sed -e 's/ .*//'` #gpart delete -i 1 md0 # efi not added  tyt esli efi to slice staavit p a ne s -t efi
    #GPT BOOT_PART=`gpart add -b 1m -s 100m -t efi $MEMORYDISK | sed -e 's/ .*//'`
    echo "BOOT_PART ${BOOT_PART}"
    #dd if=$BASEDIR/obj/usr/home/bormental/arm64/head_orange_pi_pc2/src/arm64.aarch64/stand/efi/boot1/boot1.efifat of=/dev/${EFI_PART} bs=1M conv=notrunc count=32
    #gpart bootcode -p $BASEDIR/obj/usr/home/bormental/arm64/head_orange_pi_pc2/src/arm64.aarch64/stand/efi/boot1/boot1.efifat -i 1 $MEMORYDISK
    gpart set -a active -i 1 $MEMORYDISK # ne obyazatelno
    newfs_msdos -L boot -F 16 /dev/${BOOT_PART} # v 1i razdel dobafim fat32
    #if not use gpart bootcode -p
    #newfs_msdos -L boot -F 32 -c 1 /dev/${MEMORYDISK}s1 # v 1i razdel dobafim fat16
    mkdir /mnt/${MEMORYDISK}PiBoot
    mount -t msdosfs /dev/${BOOT_PART} /mnt/${MEMORYDISK}PiBoot #for GPT p1 for MBR s1
    mkimg -s mbr -p efi:=${BASEDIR}/obj/usr${BASEDIR}/src/arm64.aarch64/stand/efi/boot1/boot1.efifat -o ${BASEDIR}/efifat.img
    mdconfig -a -t vnode -f ${BASEDIR}/efifat.img -u md100
    mkdir /mnt/efi
    mount -t msdosfs /dev/md100s1 /mnt/efi
    cp -r /mnt/efi/ /mnt/${MEMORYDISK}PiBoot

    #view structure boot list
    find /mnt/${MEMORYDISK}PiBoot/.

    UFS_P=`gpart add -t freebsd -a 512k ${MEMORYDISK} | sed -e 's/ .*//'` #s2
    echo "UFS_P ${UFS_P}"
    gpart create -s BSD ${UFS_P}
    UFS_PART=`gpart add -t freebsd-ufs -a 64k  ${UFS_P} | sed -e 's/ .*//'` #s2
    #UFS_PART=`gpart add -t freebsd-ufs -a 64k  ${MEMORYDISK} | sed -e 's/ .*//'`

    echo "UFS_PART ${UFS_PART}"
    newfs /dev/${UFS_PART}              #${MEMORYDISK}s2a
    #tunefs -t enable /dev/${UFS_PART}          #trim for ssd
    tunefs -N enable /dev/${UFS_PART}           #${MEMORYDISK}s2a # upgrade ufs system for acl list
    tunefs -n enable /dev/${UFS_PART}           #${MEMORYDISK}s2a # soft updates
    tunefs -j enable -S 4194304 /dev/${UFS_PART}                #${MEMORYDISK}s2a # size journal min 4M

    mkdir /mnt/${MEMORYDISK}PiRoot
    mount /dev/${UFS_PART} /mnt/${MEMORYDISK}PiRoot

    gpart show ${MEMORYDISK}
    df -h /dev/${BOOT_PART} /dev/${UFS_PART}

    #add u-boot and ubldr files

    cd $BASEDIR/src
    pw groupadd ntpd
    pw useradd -n ntpd -g ntpd -c "ntpd unprivileged user" -d /var/empty -s /usr/sbin/nologin

    echo 'installworld...'
    make -DWITH_FDT -DWITHOUT_DEBUG_FILES -DWITHOUT_TESTS -DWITHOUT_GAMES DESTDIR=/mnt/${MEMORYDISK}PiRoot installworld > $BASEDIR/installworld.log
    #var etc usr
    echo 'distrib-dirs'
    make DESTDIR=/mnt/${MEMORYDISK}PiRoot distrib-dirs > $BASEDIR/distrib-dirs.log
    echo 'distribution...'
    make DESTDIR=/mnt/${MEMORYDISK}PiRoot distribution > $BASEDIR/distribution.log
    echo 'installkernel...'
    make DESTDIR=/mnt/${MEMORYDISK}PiRoot installkernel > $BASEDIR/installkernel.log

    #add rc.conf loader.conf fstab
    #loader.conf or KERNEL options https://wiki.freebsd.org/FlattenedDeviceTree#Build_FDT-enabled_world
    #options FDT\n makeoptions FDT_DTS_FILE=sheevaplug.dts\noptions  FDT_DTB_STATIC
    #echo 'fdt_file="/boot/'${DTBFILE}'"' >> /mnt/${MEMORYDISK}PiRoot/boot/loader.conf
    echo '
autoboot_delay="3"
dtb_load="YES"
dtb_name="'${DTBFILE}'"
dtb_type="dtb"
    ' >> /mnt/${MEMORYDISK}PiRoot/boot/loader.conf
    mkdir /mnt/${MEMORYDISK}PiRoot/boot/msdos
    #dtb
    #cp -f ${BASEDIR}/obj/usr/${BASEDIR}/src/arm64.aarch64/sys/${KERNCONF}/modules/usr/${BASEDIR}/src/sys/modules/dtb/allwinner/${DTBFILE} /mnt/${MEMORYDISK}PiRoot/boot/dtb/
    cp -f $BASEDIR/dtb/*.dtb /mnt/${MEMORYDISK}PiRoot/boot/dtb/
    #fstab
    echo '
/dev/mmcsd0s1           /boot/msdos     msdosfs         rw,noatime              0       0
/dev/mmcsd0s2a          /               ufs             rw,noatime              1       1
#/dev/mmcsd0p1          /boot/msdos     msdosfs         rw,noatime              0       0
#/dev/mmcsd0p2a         /               ufs             rw,noatime              1       1
#md                     /tmp            mfs             rw,noatime,-s30m        0       0
#md                     /var/log        mfs             rw,noatime,-s15m        0       0
#md                     /var/tmp        mfs             rw,noatime,-s12m        0       0
    '> /mnt/${MEMORYDISK}PiRoot/etc/fstab
    echo '
hostname="'${HOSTNAME}'"
ifconfig_awg0="'${IP}${IPMASK}'"
defaultrouter="'${GATE}'"
sshd_enable="YES"
dumpdev="NO"
# Nice if you have a network, else annoying.
#ntpd_enable="YES"
#ntpdate_enable="YES"
ntpd_sync_on_start="YES"
# Uncomment to disable common services (more memory)
#cron_enable="NO"
#syslogd_enable="NO"
sendmail_enable="NONE"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"
    '  > /mnt/${MEMORYDISK}PiRoot/etc/rc.conf
    echo 'nameserver '${DNS}'' > /mnt/${MEMORYDISK}PiRoot/etc/resolv.conf
    echo ${IP}' no.found.dns.domain '${HOSTNAME} > /mnt/${MEMORYDISK}PiRoot/etc/hosts
    cp -iv /mnt/${MEMORYDISK}PiRoot/usr/share/zoneinfo/Europe/Moscow /mnt/${MEMORYDISK}PiRoot/etc/localtime
    #allow root from ssh
    echo '===========================================
    If you want login root from ssh without password
Edit /mnt/etc/ssh/sshd_config, go to line 44, and change
#PermitRootLogin no to PermitRootLogin yes
Either add your public ssh key to /mnt/root/.ssh/authorized_keys:
mkdir -m 0700 /mnt/root/.ssh
cat ~/.ssh/id_rsa.pub >>/mnt/root/.ssh/authorized_keys
chmod 0600 /mnt/root/.ssh/authorized_keys
login: ssh root@192.168.0.100
run: passwd

Or local login root and run
#passwd
and add wheel or other users
#adduser
Resize disk: /boot/msdos/resizedisk.sh

pkg: for 12 current
    #env ABI=freebsd:11:aarch64 pkg bootstrap
    and
    add /usr/local/etc/pkg.conf: ABI = "FreeBSD:11:aarch64";
    !!!not run pkg-static install -f pkg => corrupt pk from FreeBsd:11:aarch64 version

    If you want to build your own ports or packages on stable/11 you need
    to install the aarch64-binutils package and link /usr/bin/ld to /usr/local/bin/aarch64-freebsd-ld:
    # pkg install aarch64-binutils
    # ln /usr/local/bin/aarch64-freebsd-ld /usr/bin/ld
==========================================='

    echo '#!/bin/sh
gpart show
sysctl kern.geom.debugflags=16
gpart resize -i 2 mmcsd0
gpart show mmcsd0s2
gpart resize -i 1 mmcsd0s2
gpart show
growfs -y /dev/mmcsd0s2a
#tunefs -t enable /dev/mmcsd0s2a
shutdown -r now
    ' >  /mnt/${MEMORYDISK}PiBoot/resizedisk.sh
    #delete md disk
    #umount /mnt/${MEMORYDISCK}PiBoot
    #umount /mnt/${MEMORYDISCK}PiRoot
    #mdconfig -d -u $MEMORYDISK`
    unmount /mnt/efi
    mdconfig -d -u md100
    rm -rf ${BASEDIR}/efifat.img

fi
 
Last edited:
You need to compile with DWITH_FDT for starters.
https://forums.freebsd.org/threads/cross-compiling-beaglebone-on-amd64.64718/

The source for a supported arm64 board is helpful. See usr/src/release/release.conf
chroot_arm_build_release()

You have the critical pieces with the uboot address.
I would suggest you try and build initially on the sdcard unless you are comfortable formatting a memory disk.
Making an image just adds a layer of complexity.
For the BBB I knew it worked.
For your platform you might need to tweak things some, then when you get it booting make your image.

In my quest I used a separate mount point for the two partitions. That is not required. I just like to keep things separated.
 
You need to compile with DWITH_FDT for starters.
... In my quest I used a separate mount point for the two partitions. That is not required. I just like to keep things separated.
Thanks for the response, about DWITH_FDT will consider. Recently found the script release.sh but I am not sure that it will work correctly for orange pi pс2. Also found information that for arm64 ubldr is not used, instead of it efi is necessary. Which makes it even more confusing...

there is a script arm64_build.sh he also collects with efi. But then the question remains on UBLDR_LOADADDR does it need to be set when compiling the world?
 
Yes notice my applicable buildworld settings.
make buildworld UBLDR_LOADADDR=0x88000000 -DWITH_FDT
I see that. but you have a ARM, and they need ubldr, and I have ARM64, and it works through EFI...

this https://wiki.freebsd.org/arm64 find arm64_build.sh

https://wiki.freebsd.org/UEFI

The boot process proceeds as follows:
  1. UEFI firmware runs at power up and searches for an OS loader in the EFI system partition. The path to the loader may be set by an EFI environment variable, with a default of /EFI/BOOT/BOOTX64.EFI.
    • For FreeBSD, boot1.efi is installed as /EFI/BOOT/BOOTX64.EFI.
    • boot1.efifat is an image of such a FAT filesystem for use by bsdinstall
  2. boot1.efi locates the first partition with a type of freebsd-ufs, and from it loads loader.efi. (This may be a different disk than the one holding the EFI system partition.)
  3. loader.efi loads and boots the kernel, as described in loader(8).
 
Yes notice my applicable buildworld settings.
make buildworld UBLDR_LOADADDR=0x88000000 -DWITH_FDT

The problem is that under arm64 there is a loader.efi, what should I move to the fat partition? and how to configure configuration files in it? where find any description of the structure?

UBLDR_LOADADDR=0x42000000 I got it from crochet. all orangepi his address is the same....
need set UBLDR_LOADADDR=0x4a000000 such address in u-boot for pi pc2
 
The RPi3 board uses aarch64 too and crochet does this:
Code:
# Build & install loader.efi. 
strategy_add $PHASE_BUILD_OTHER freebsd_loader_efi_build 
strategy_add $PHASE_BOOT_INSTALL freebsd_loader_efi_copy EFI/BOOT/bootaa64.efi
https://github.com/freebsd/crochet/blob/master/board/RaspberryPi3/setup.sh
So chase down what the strategy does and you have your answer.

I tried it, without results. the u-boot preloader needs to make a configuration file in the fat section where you specify fatload and go. but I can't find descriptions of what file the preloader is looking for by name. also the preloader should load u-boot.img from the fat partition or from ubldr or boot1.efi? (as I understand it ubldr and boot1.efi they perform the exact same role just the implementation is different) and they are already looking for the ufs partition and kernel....

ordered UART TTL... I'll try to find out what's missing
 
The RPi3 board uses aarch64 too and crochet does this:
...
.
You have never seen material about the successful launch of freebsd on Orange PC2? u-boot port is, dts - > dtb file is, but nowhere is written how to build a working image...
 
the efi partition can only be done with gpt. put gpt recorded an image of u-boot-with-spl.bin made a fat section from efifat.the LEDs didn't light up. came to the conclusion that we need to see a working image of Linux and to take the preloader and load him boot1.efi. such plan...
 

updated the script in the top. on him get

gpart show
=> 33 8368095 md0 MBR (4.0G)
33 2015 - free - (1.0M)
2048 65536 1 fat16 [active] (32M)
67584 8300544 2 freebsd (4.0G)

=> 0 8300544 md0s2 BSD (4.0G)
0 8300544 1 freebsd-ufs (4.0G)


bormental@vpc-desktopbsd:/mnt# mount -l
/dev/md0s1 on /mnt/md0PiBoot (msdosfs, local)
/dev/md0s2a on /mnt/md0PiRoot (ufs, local, journaled soft-updates, nfsv4acls)


structure boot fat
bormental@vpc-desktopbsd:/usr/home/bormental/arm64# find //mnt/md0PiBoot/. | sed -e 's/\/mnt\/md0PiBoot\/\.//'
/
//efi
//efi/boot
//efi/boot/BOOTaa64.efi
//efi/boot/startup.nsh


bormental@vpc-desktopbsd:/usr/home/bormental/arm64# df -h
Filesystem Size Used Avail Capacity Mounted on
/dev/md0s1 32M 404K 32M 1% /mnt/md0PiBoot
/dev/md0s2a 3.8G 1.2G 2.3G 34% /mnt/md0PiRoot


it remains to link the preloader from the first 1024K and /efi/boot/Bootx64.efi . it is not clear how. is used in the RPI3 config.txt, will it be the same for PC2? and where to take the second part of u-boot for the fat partition? in. /usr/local/share/u-boot / u-boot-orangepi-pc2 there is nothing but u-boot-with-spl....
 
A real good place to ask questions is IRC on EFnet in the bsdmips channel.(For embedded questions)
You can get instant answers if you ask at the right time of day.
Mainly US timezones 8am-5pm you see a large group online who are actual developers and helpers.
 
A real good place to ask questions is IRC on EFnet in the bsdmips channel.(For embedded questions)
You can get instant answers if you ask at the right time of day.
Mainly US timezones 8am-5pm you see a large group online who are actual developers and helpers.
IMG_20181021_194601.jpg

Hi, do not believe it but the script is working. the image he collected started... There is an assumption that with OrangePi Prime will also work. it remains to put in order things such as root password, users and so on will be the working script.... thanks again for your advice.

PS only the usb keyboard does not work... usb may not work
 
It looks like you are using the GENERIC kernel as well. For CURRENT you might want to use GENERIC-NODEBUG kernconf instead. Disk throughtput takes a hit with debugging options enabled.
 
It looks like you are using the GENERIC kernel as well. For CURRENT you might want to use GENERIC-NODEBUG kernconf instead. Disk throughtput takes a hit with debugging options enabled.

Not help. When the usb keyboard is connected not the Board is loaded, if without the keyboard then loaded. If you disconnect or connect the keyboard then goes to reboot...

as I understand it the problem is in dts ...
https://forums.freebsd.org/threads/cross-compiling-beaglebone-on-amd64.64718/#post-378014
fdt_file option not exist in man loader.conf . where is this?
 
It probably is a dts setting problem.
Have you studied what crochet is doing? Usually FreeBSD Arm uses the GNU dts and just a small tweak here and there.
But I noticed on the OrangePi they exclude one DTS from the GNU directory.
 
It probably is a dts setting problem.
Have you studied what crochet is doing? Usually FreeBSD Arm uses the GNU dts and just a small tweak here and there.
But I noticed on the OrangePi they exclude one DTS from the GNU directory.

crochet uses uenv.txt or config.txt file for the preloader where fdt_file is specified, but not in efi... you have in topic fdt_file say occasionally why the in /boot/loader.conf but man loader.conf says Nothing about the fdt_file option

I don't understand where to tell the kernel to use dtb file

absolutely emergency option of course to use options FDT_DTM_STATIC but it if there is no other solution
 
I seem to remember config.txt being instrumental with dtbs' and overlays for Pi3. Have you tried that approach?
Things change so rapidly on Arm that I am not sure that is still the proper method.
 
I seem to remember config.txt being instrumental with dtbs' and overlays for Pi3. Have you tried that approach?
Things change so rapidly on Arm that I am not sure that is still the proper method.

in my opinion config.txt и uEnv.txt only for not efi loader...
Today I'll try loader.conf mechanism. module_load="YES" module_name=" module.dtb "module_type= "dtb". this is equivalent to load -t module.dtb on the loader command line
 
updated the script draft at the top. it works, did not check only loading of dtb through the loader. I'll check. the same script is suitable for any Board. only with u-boot and dtb to change data
 
I seem to remember config.txt being instrumental with dtbs' and overlays for Pi3. Have you tried that approach?
Things change so rapidly on Arm that I am not sure that is still the proper method.

Well, that earned the ports and LEDs!!! so my assumption about module_load was correct. Now I would like to find out with overlays...
Ура)))скрипт рабочий на апельсин 64битный)))
 
I seem to remember config.txt being instrumental with dtbs' and overlays for Pi3. Have you tried that approach?
Things change so rapidly on Arm that I am not sure that is still the proper method.
found out one more feature while on hdmi nothing is connected the board does not start... brewed
 
Back
Top