Re: Nanobsd for RPI4

Guido Falsi <[email protected]>
Newsgroups gmane.os.freebsd.devel.arm
Message-ID <[email protected]>
On 16/01/24 11:34, Andrew Hankinson wrote:
> 
>> On 16 Jan 2024, at 10:46, Guido Falsi <[email protected]> wrote:
>>
>> On 16/01/24 10:30, Andrew Hankinson wrote:
>>>> On 16 Jan 2024, at 10:03, Guido Falsi <[email protected]> wrote:
>>>>
>>>> On 16/01/24 09:52, Andrew Hankinson wrote:
>>>>> Hello,
>>>>> I saw a recent posting to this list about nanobsd for RPI3:
>>>>> Re: Nanobsd builds for rpi3 out of embedded blow up during build <https://lists.freebsd.org/archives/freebsd-arm/2024-January/003509html>
>>>>> lists.freebsd.org <https://lists.freebsd.org/archives/freebsd-arm/2024-January/003509.html>
>>>>> favicon.ico <https://lists.freebsd.org/archives/freebsd-arm/2024-January/003509.html>
>>>>> <https://lists.freebsdorg/archives/freebsd-arm/2024-January/003509.html>
>>>>> I just wanted to chime in to say I am seeing the exact same thing for a RPI4 build with both 14.0 release and 15.0 current. I asked about it on the forums, but there didn’t seem to be any solution.
>>>>> Has anyone here managed to get a nanobsd build working?
>>>>
>>>> I am using nanobsd with RPi3. Never tried RPi4. I did some customization to the nanobsd scripts and configuration to get it working though.
>>>>
>>>> Last time I rebuilt my image was in mid december. I'm going to build a new image in the next pair of weeks.
>>>>
>>>> Is the problem limited to the boot code?
>>> I haven't been able to get past the boot code bit, but up until this point it works OK. I've simply copied the RPI3.cfg file and changed a few variables.
>>> My build stops with the following logs:
>>> # cat /usr/embedded/rpi4/_.cust.dos_boot_part
>>> + dos_boot_part
>>> + local 'd=/usr/local/share/u-boot/u-boot-rpi4'
>>> + local 'f=/usr/embedded/rpi4/_.fat'
>>> + rm -rf /usr/embedded/rpi4/_.fat
>>> + mkdir /usr/embedded/rpi4/_.fat
>>> + chdir /usr/embedded/rpi4/_.fat
>>> + cp /usr/local/share/u-boot/u-boot-rpi4/README /usr/local/share/u-boot/u-boot-rpi4/metadata /usr/local/share/u-boot/u-boot-rpi4/u-boot.bin .
>>> + touch uEnv.txt
>>> + cp '/usr/embedded/rpi4/_.w/boot/dtb/*.dtb' .
>>> cp: /usr/embedded/rpi4/_.w/boot/dtb/*.dtb: No such file or directory
>>> This seems to be a problem with the dos_boot_part() function in /usr/src/tools/tools/nanobsd/embedded/common.
>>> Your code seems to bypass this and uses the rpi-firmware package dtbo files.
>>
>> I was seeing problems simlar to what you are describing, so I wrote my own function.
>>
>>> So I guess my questions are:
>>> 1. What changed that the .dtb files are no longer created in the regular build?
>>> 2. Should the dos_boot_part() function be changed to take the files from the rpi-firmware pkg instead?
>>> Not being familiar with the nanobsd building process, I'm not really sure what is the best way to go.
>>
>> I wrote this code some time ago and I don't remember the details, anyway my code does take the files from the pkg.
>>
>> I took idea from the release scripts for aarch64 from:
>>
>> src/release/release.sh
>> src/release/arm64/aarch64.conf
>> src/release/tools/arm.subr
>>
>> which have more current code.
> 
> Would you be willing to share your full nanobsd config file? Or is that the only custom part you needed to get it working?

I have some more custom parts, but most are unrelated to RPi3.

Actually mine is a configuration I used with a PCEngine APU2 board, I 
converted to RPi3.

The only other relevant configuration is this part:

calculate_partitioning ( ) (
)

create_code_slice ( ) (
     pprint 2 "build code slice"
     pprint 3 "log: ${NANO_OBJ}/_.cs"

     (
     IMG=${NANO_DISKIMGDIR}/_.disk.image
     MNT=${NANO_OBJ}/_.mnt
     mkdir -p ${MNT}
     CODE_SIZE=${NANO_SLICE_CODE_SIZE}

     if [ "${NANO_MD_BACKING}" = "swap" ] ; then
         MD=`mdconfig -a -t swap -s ${CODE_SIZE} -x ${NANO_SECTS} \
             -y ${NANO_HEADS}`
     else
         echo "Creating md backing file..."
         rm -f ${IMG}
         dd if=/dev/zero of=${IMG} seek=${CODE_SIZE} count=0
         MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \
             -y ${NANO_HEADS}`
     fi

     trap "echo 'Running exit trap code' ; df -i ${MNT} ; umount ${MNT} 
|| true ; mdconfig -d -u $MD" 1 2 15 EXIT

     gpart create -s bsd ${MD}
     gpart add -t freebsd-ufs -a 64k -b 64k ${MD}
     #gpart bootcode -b ${NANO_WORLDDIR}/boot/boot ${MD}

     # Create first image
     populate_slice /dev/${MD}${NANO_PARTITION_ROOT} ${NANO_WORLDDIR} 
${MNT} "${NANO_ROOT}"
     mount /dev/${MD}${NANO_PARTITION_ROOT} ${MNT}
     echo "Generating mtree..."
     ( cd ${MNT} && mtree -c ) > ${NANO_OBJ}/_.mtree
     ( cd ${MNT} && du -k ) > ${NANO_OBJ}/_.du
     nano_umount ${MNT}

     if [ "${NANO_MD_BACKING}" = "swap" ] ; then
         echo "Writing out _.disk.image..."
         dd conv=sparse if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.image 
bs=64k
     fi
     mdconfig -d -u $MD

     trap - 1 2 15 EXIT

     ) > ${NANO_OBJ}/_.cs 2>&1
)

# Custom disk image command, from common embedded image
create_diskimage ( ) (
     pprint 2 "build diskimage"
     pprint 3 "log: ${NANO_LOG}/_.di"

     (

     IMG=${NANO_DISKIMGDIR}/${NANO_IMGNAME}
     MNT=${NANO_OBJ}/_.mnt
     mkdir -p ${MNT}

     if [ "${NANO_MD_BACKING}" = "swap" ] ; then
         MD=`mdconfig -a -t swap -s ${NANO_MEDIASIZE} -x ${NANO_SECTS} \
             -y ${NANO_HEADS}`
     else
         echo "Creating md backing file..."
         rm -f ${IMG}
         dd if=/dev/zero of=${IMG} seek=${NANO_MEDIASIZE} count=0
         MD=`mdconfig -a -t vnode -f ${IMG} -x ${NANO_SECTS} \
             -y ${NANO_HEADS}`
     fi

     trap "echo 'Running exit trap code' ; df -i ${MNT} ; nano_umount 
${MNT} || true ; mdconfig -d -u $MD" 1 2 15 EXIT

     gpart create -s MBR ${MD}
     gpart add -t '!12' -a 512k -s ${NANO_SLICE_EFI_SIZE} ${MD}
     gpart set -a active -i 1 ${MD}
     newfs_msdos -L efi -F 16 /dev/${MD}${NANO_SLICE_EFI}
     gpart add -t freebsd -s ${NANO_SLICE_CFG_SIZE} ${MD}
     gpart add -t freebsd -s ${NANO_SLICE_CODE_SIZE} ${MD}
     gpart add -t freebsd -s ${NANO_SLICE_CODE_SIZE} ${MD}

     mount_msdosfs /dev/${MD}${NANO_SLICE_EFI} ${MNT}
     populate_boot_part ${MNT}
     umount ${MNT}

     echo "Writing code image..."
     dd conv=sparse if=${NANO_DISKIMGDIR}/_.disk.image 
of=/dev/${MD}${NANO_SLICE_ROOT} bs=64k

     # Create Config slice
     populate_cfg_slice /dev/${MD}${NANO_SLICE_CFG} "${NANO_CFGDIR}" 
${MNT} "${NANO_SLICE_CFG}"

     if [ "${NANO_MD_BACKING}" = "swap" ] ; then
         if [ ${NANO_IMAGE_MBRONLY} ]; then
             echo "Writing out _.disk.mbr..."
             dd if=/dev/${MD} of=${NANO_DISKIMGDIR}/_.disk.mbr bs=512 
count=1
         else
             echo "Writing out ${NANO_IMGNAME}..."
             dd if=/dev/${MD} of=${IMG} bs=64k
         fi

         echo "Writing out ${NANO_IMGNAME}..."
         dd conv=sparse if=/dev/${MD} of=${IMG} bs=64k
     fi

     mdconfig -d -u ${MD}

     trap - 1 2 15 EXIT

     ) > ${NANO_LOG}/_.di 2>&1
)

> 
>>
>> -- 
>> Guido Falsi <[email protected]>
>>
> 
> 

-- 
Guido Falsi <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.