OrangePiPC2

Bormental

New Member


Messages: 16

#1
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
#base dir
#setenv = export
export BASEDIR=/home/bormental/arm64/head_orange_pi_pc2
export MAKEOBJDIRPREFIX=$BASEDIR/obj
#aarch64
export TARGET=arm64
export TARGET_ARCH=aarch64
#42000000
export UBLDR_LOADADDR=0x4a000000
export KERNCONF=ORANGEPIPC2
export IMGFILENAME=OrangePiPC2.img
export SIZEIMGMB=4086
export __MAKE_CONF=/dev/null
export SRCCONF=/dev/null

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

if [ "$1" = "" ];
then
    echo "usage: $0.sh [all|src|mk|dtb|img|boot]"
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 #est project/arm64
fi

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

    if [-f $BASEDIR/src/sys/arm64/conf/$KERNCONF];
    then
        echo 'kernel conf file exists..'
    else
        echo 'kernel conf file is not exists, copy from GENERIC...'
        cp $BASEDIR/src/sys/arm64/conf/GENERIC $BASEDIR/src/sys/arm64/conf/$KERNCONF
    fi

    echo 'clear old obj..'
    rm -rf $BASEDIR/obj
    #for crosscompiles
    echo 'make tool chain..'
    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 > $BASEDIR/buildworld.log #KERNCONF=MYGENERIC TARGET=arm64 TARGET_ARCH=aarch64 UBLDR_LOADADDR=0x42000000 #__MAKE_CONF=/dev/null
    #sobiraem yadro
    echo 'buld kernel..'
    make -j $(sysctl -n hw.ncpu) buildkernel > $BASEDIR/buildkernel.log #KERNCONF=NYGENERIC TARGET=arm64 TARGET_ARCH=aarch64 #__MAKE_CONF=/dev/null
fi

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

    mkdir $BASEDIR/dtb/
    $BASEDIR/src/sys/tools/fdt/make_dtb.sh $BASEDIR/src/sys $BASEDIR/src/sys/gnu/dts/arm64/allwinner/sun50i-h5-orangepi-prime.dts $BASEDIR/dtb/
    $BASEDIR/src/sys/tools/fdt/make_dtb.sh $BASEDIR/src/sys $BASEDIR/src/sys/gnu/dts/arm64/allwinner/sun50i-h5-orangepi-pc2.dts $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

    if ! [ -e "/usr/local/share/u-boot/u-boot-orangepi-pc2/u-boot-sunxi-with-spl.bin" ];
    then
    #pkg install u-boot-orangepi-pc2
    /usr/ports/sysutils/u-boot-orangepi-pc2
    make -DBATCH all install
    fi

    #for 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 32m -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
    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
    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="sun50i-h5-orangepi-pc2.dtb"' >> /mnt/${MEMORYDISK}PiRoot/boot/loader.conf
    mkdir /mnt/${MEMORYDISK}PiRoot/boot/msdos
    #dtb
    cp -f $BASEDIR/dtb/*.dtb /mnt/${MEMORYDISK}PiRoot/boot/dtb/allwinner/
    #fstab
    echo '
/dev/mmcsd0s1           /boot/msdos     msdosfs         rw,noatime              0       0
/dev/mmcsd0s2a          /               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="orangepi"
#ifconfig_awg0="DHCP"
ifconfig_DEFAULT="DHCP"
sshd_enable="YES"
# Nice if you have a network, else annoying.
#ntpd_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

    #delete md disk
    #umount /mnt/${MEMORYDISCK}PiBoot
    #umount /mnt/${MEMORYDISCK}PiRoot
    #mdconfig -d -u $MEMORYDISK`
    #unmount /mnt/efi
    #mdconfig -d -u md100
    #rm ${BASEDIR}/efifat.img

fi
 
Last edited:

Phishfry

Son of Beastie

Thanks: 874
Messages: 2,769

#2
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.
 
OP
OP
Bormental

Bormental

New Member


Messages: 16

#3
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?
 
OP
OP
Bormental

Bormental

New Member


Messages: 16

#5
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).
 
OP
OP
Bormental

Bormental

New Member


Messages: 16

#6
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
 
OP
OP
Bormental

Bormental

New Member


Messages: 16

#8
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
 
OP
OP
Bormental

Bormental

New Member


Messages: 16

#10
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...
 
OP
OP
Bormental

Bormental

New Member


Messages: 16

#11
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....
 

Phishfry

Son of Beastie

Thanks: 874
Messages: 2,769

#14
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.
 
OP
OP
Bormental

Bormental

New Member


Messages: 16

#15
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
 

Phishfry

Son of Beastie

Thanks: 874
Messages: 2,769

#16
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.
 
Top