How to boot FreeBSD installed on the sd card on the Khadas Edge-V instead of Android

If you can get this u-boot going the custom port you created also makes the SPI files for flashing u-boot right to SPI Flash rom.
Then all FreeBSD goes right on whatever medium you want.No offsets. NVMe/SATA/USB.
You do have to deal with u-boot separately at upgrade time anyway much like EFI bootloader needs manual intervention.
 
# dd if=/dev/sdk | hexdump -C | more
# dd if=/dev/sdj | hexdump -C | grep RK

I have a lot of evidences. Hard to find the correct ones.

Also be aware you should have HDMI output available. Have you checked that with Ubuntu or FreeBSD microSD images? How about your custom port u-boot disk with HDMI? It is enabled.

I don't know because I never been able to boot FreeBSD. It is simply always skipped for booting Android.
 
You already know what's my plan. Try to boot FreeBSD using the boot.src script of Ubuntu. Because it's inside there that there is the secret to skip the booting from the internal EMMC. So this is what I did until now :

1) created a disk that has MBR instead of GPT :

Code:
# dd if=FreeBSD-14.3-RELEASE-arm-armv7-GENERICSD.img | pv | dd of=/dev/sdj
10485760+0 records inMiB/s] [                                <=>                                                                      ]
10485760+0 records out
5368709120 bytes (5.4 GB, 5.0 GiB) copied, 919.505 s, 5.8 MB/s
5.00GiB 0:15:19 [5.57MiB/s] [                                  <=>                                                                    ]
10485760+0 records in
10485760+0 records out
5368709120 bytes (5.4 GB, 5.0 GiB) copied, 921.807 s, 5.8 MB/s

# fdisk -l
Disk /dev/sdj: 29.72 GiB, 31914983424 bytes, 62333952 sectors
Disk model: MassStorageClass
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Dispositivo Avvio  Start     Fine  Settori Size Id Tipo
/dev/sdj1   *       2048   104447   102400  50M  c W95 FAT32 (LBA)
/dev/sdj2         104448 10485759 10381312   5G a5 FreeBSD

2) identified the real root partition :

Code:
# ls /dev/sdj*
/dev/sdj  /dev/sdj1  /dev/sdj2  /dev/sdj5

3) and mounted it :

Code:
# mount -t ufs -o ufstype=ufs2 /dev/sdj5 /mnt/sdj5
mount: /mnt/sdj5: WARNING: source write-protected, mounted read-only.

4) determined the UUID number of the root partition :

Code:
# blkid | grep sdj5
/dev/sdj5: LABEL="rootfs" UUID="6842abb3c4fca891" BLOCK_SIZE="4096" TYPE="ufs"

5) just because it is needed here :

# nano env.txt

Code:
#############################DO NOT TOUCH THIS OPTION#############################
rootdev=UUID=6842abb3c4fca891
#e5167dcc-5e89-402b-913a-ced587267ba7
#############################DO NOT TOUCH THIS OPTION#############################

# MIPI LCD control
# true  - enable MIPI LCD
# false - disable MIPI LCD
mipi_lcd_enabled=false

# Cooling FAN mode
# auto -  auto schedule the FAN speed depend on the CPU temperature
# low  -  FAN low speed
# mid  -  FAN middle speed
# high -  FAN high speed
fan_mode=auto

# DMA coherent_pool size
# Don't touch unless you know what you are doing
dma_size=2M

# Specify the initial console log level (0~8)
loglevel=7

Unfortunately FreeBSD still does not boot directly. I'm sure that something is still wrong inside this script and it should be adapted.

# nano rk3399_autoscript.cmd

Code:
echo "Run Khadas boot script"

# Constant
setenv BOARD_TYPE_NONE        0
setenv BOARD_TYPE_EDGE        1
setenv BOARD_TYPE_EDGE_V    2
setenv BOARD_TYPE_CAPTAIN    3

# Detect board type
kbi boarddetect

if test ${board_type} = ${BOARD_TYPE_NONE}; then
    echo "Unsupported board detected! Stop here. Reboot...";
    sleep 5;
    reset;
fi

setenv emmc_root_part        7
setenv emmc_boot_part        7
setenv emmc_mbr_root_part    2
setenv emmc_mbr_boot_part    1
setenv sd_root_part            2
setenv sd_boot_part            1

if test ${devnum} = 0; then
    echo "Uboot loaded from eMMC.";
    if test -e mmc ${devnum}:${emmc_root_part} zImage; then
        setenv imagetype "EMMC";
        setenv boot_env_part ${emmc_boot_part};
        setenv root_part ${emmc_root_part};
        setenv mark_prefix "boot/";
    else
        setenv imagetype "EMMC_MBR";
        setenv boot_env_part ${emmc_mbr_boot_part};
        setenv root_part ${emmc_mbr_root_part};
        setenv mark_prefix "";
    fi;

    if test -e mmc ${devnum}:${boot_env_part} ${mark_prefix}.next; then
        setenv default_rootdev "/dev/mmcblk2p${root_part}"
    else
        setenv default_rootdev "/dev/mmcblk1p${root_part}"
    fi
else if test ${devnum} = 1; then
    echo "Uboot loaded from SD.";
    setenv boot_env_part ${sd_boot_part};
    setenv root_part ${sd_root_part}
    setenv mark_prefix ""
    if test -e mmc ${devnum}:${boot_env_part} ${mark_prefix}.next; then
        setenv default_rootdev "/dev/mmcblk1p${sd_root_part}"
    else
        setenv default_rootdev "/dev/mmcblk0p${sd_root_part}"
    fi
    setenv imagetype "SD-USB";
fi;fi;

# Import environment from env.txt
if load ${devtype} ${devnum}:${boot_env_part} ${ramdisk_addr_r} /boot/env.txt || load ${devtype} ${devnum}:${boot_env_part} ${ramdisk_addr_r} env.txt; then
    echo "Import env.txt";
    env import -t ${ramdisk_addr_r} ${filesize}
fi

# Check root part filesystem UUID
fsuuid ${devtype} ${devnum}:${root_part} root_uuid
if test "UUID=${root_uuid}" != "${rootdev}"; then
    echo "Rootfs UUID mismatch! Set rootfs part to default: ${default_rootdev}"
    setenv rootdev ${default_rootdev}
fi

# Check MIPI
if test "${mipi_lcd_enabled}" = "true"; then
    setenv dtb_suffix "-mipi";
else
    setenv dtb_suffix "";
fi

if test -e mmc ${devnum}:${boot_env_part} ${mark_prefix}.next; then
    if test ${board_type} = ${BOARD_TYPE_EDGE}; then
        setenv boot_dtb "rk3399-khadas-edge.dtb";
    else if test ${board_type} = ${BOARD_TYPE_EDGE_V}; then
        setenv boot_dtb "rk3399-khadas-edge-v.dtb";
    else if test ${board_type} = ${BOARD_TYPE_CAPTAIN}; then
        setenv boot_dtb "rk3399-khadas-edge-captain.dtb";
    fi;fi;fi
else
    if test ${board_type} = ${BOARD_TYPE_EDGE}; then
        setenv boot_dtb "rk3399-khadas-edge-linux.dtb";
    else if test ${board_type} = ${BOARD_TYPE_EDGE_V}; then
        setenv boot_dtb "rk3399-khadas-edgev${dtb_suffix}-linux.dtb";
    else if test ${board_type} = ${BOARD_TYPE_CAPTAIN}; then
        setenv boot_dtb "rk3399-khadas-captain${dtb_suffix}-linux.dtb";
    fi;fi;fi
fi

if test ${devnum} = 0; then
    if test -e mmc ${devnum}:${boot_env_part} ${mark_prefix}.next; then
        if test ${imagetype} = EMMC_MBR; then
            setenv dtb_prefix "/dtb/rockchip/";
        else
            setenv dtb_prefix "/boot/dtb/rockchip/";
        fi
    else
        if test ${imagetype} = EMMC_MBR; then
            setenv dtb_prefix "/dtb/";
        else
            setenv dtb_prefix "/boot/dtb/";
        fi
    fi
else if test ${devnum} = 1; then
    if test -e mmc ${devnum}:${boot_env_part} ${mark_prefix}.next; then
        setenv dtb_prefix "/dtb/rockchip/";
    else
        setenv dtb_prefix "/dtb/";
    fi
fi;fi;

echo DTB: ${dtb_prefix}${boot_dtb}

if test -e mmc ${devnum}:${boot_env_part} ${mark_prefix}.next; then
    setenv condev "earlyprintk console=ttyS2,1500000n8 console=tty0"
else
    setenv condev "earlyprintk console=ttyFIQ0,1500000n8 console=tty0"
fi

setenv boot_start booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}

part uuid mmc ${devnum}:1 ubootpartuuid;
if test "X${ubootpartuuid}" = "X"; then
    echo "Can not get u-boot part UUID, set to NULL";
    setenv ubootpartuuid "NULL";
fi;

kbi ethmac
if test -e ${custom_ethmac}; then
    echo "Found custom ethmac: ${custom_ethmac}, overwrite eth_mac!";
    setenv eth_mac ${custom_ethmac}
fi

if test "X${eth_mac}" = "X" || test "X${eth_mac}" = "X00:00:00:00:00:00"; then
    echo "Set default mac address to ethaddr: ${ethaddr}!";
    setenv eth_mac ${ethaddr};
    setenv saveethmac "save_ethmac=yes";
fi;

if test -e ${loglevel}; then
    setenv log "loglevel=${loglevel}"
fi

setenv bootargs "${bootargs} ${condev} ${log} rw root=${rootdev} rootfstype=ext4 init=/sbin/init rootwait ubootpart=${ubootpartuuid} board_type=${board_type} board_type_name=${board_type_name} khadas_board=${board_type_name} fan=${fan_mode} mac=${eth_mac} androidboot.mac=${eth_mac} ${saveethmac} coherent_pool=${dma_size} imagetype=${imagetype}"

for distro_bootpart in ${devplist}; do
    echo "Scanning ${devtype} ${devnum}:${distro_bootpart}..."

    if load ${devtype} ${devnum}:${distro_bootpart} ${ramdisk_addr_r} uInitrd; then
        if load ${devtype} ${devnum}:${distro_bootpart} ${kernel_addr_r} zImage; then
            if load ${devtype} ${devnum}:${distro_bootpart} ${fdt_addr_r} ${dtb_prefix}${boot_dtb}; then
                run boot_start;
            fi;
        fi;
    fi;

done

# Rebuilt
# mkimage -A arm64 -O linux -T script -C none -a 0 -e 0 -n "rk3399 autoscript" -d /boot/rk3399_autoscript.cmd /boot/boot.scr

maybe setenv sd_root_part 5
maybe ${devnum} is always 0 instead of 1...
maybe I can try to show at video the values of some relevant variables...
maybe I can stop the execution of the script with a nice exit at some point...

so many things to try...

:)
 
Ok,I did the first experiment,adding a sleep 999 parameter as soon as the script starts,like this :

Code:
echo "Run Khadas boot script"
sleep 999

and I've realized that the script does not start at all because it does not sleep but Android boots.
 
kbi boarddetect
I had to look that one up.
Oh boy another layer of junk added to u-boot. Yea

Kinda reminds me of Odroid-M1 w/rk3568. They ship with a bootloader called PetiteBoot. Just wipe it and install u-boot. That's what I did. They seem to be dumbing it down for users.
 
---> Why have you not zeroed that pig yet?

What should I zero out ?

---> You can boot off SD card with Ubuntu

I can't boot the sd card with Ubuntu if the boot.scr script is not on the fat32 partition or if it is damaged.

---> There are images to re-flash Android too.

oh you mean to zero out Android because you hope that without it,FreeBSD will boot as default ?
Never tried but I'm not sure that it will work.
 
What should I zero out ?
Lets start right there. So can you enter a u-boot console by pressing space key repeatedly at bootup? Using Khadis u-boot on microSD/Ubuntu.
There is sometimes a countdown timer to help you get into the u-boot console.. U-boot console will allow you to delete MMC contents. Also SPI.
 
Lets start right there. So can you enter a u-boot console by pressing space key repeatedly at bootup? Using Khadis u-boot on microSD/Ubuntu. There is sometimes a countdown timer to help you get into the u-boot console.. U-boot console will allow you to delete MMC contents. Also SPI.

I tried. I'm not able to stop the booting of Android. I can't enter in the u-boot console. Space does not work,the buttons don't work. But I can use Ubuntu to zero out the EMMC.
 
I don't know what happened bro,I didn't touch any button,but Ubuntu has been able to boot from the sd card in serial mode
Repeat this and erase MMC from ubuntu.

lsblk and find device. dd zero it. Check /dev for SPI Flash.

I do this from Armbian alot.
 
Well when the worlds #1 Arm Operating System does not work there is a reason. No vendor support.
So you bought a lemon.
 
Disagree. It is cumbersome. Armbian will boot after having erased the EMMC. Support is not of the highest quality,but he is helping me.
 
Maybe not a lemon but like Odroid M1. A layer of kruft that must be stripped off.

Deleting SPI Flash from a MicroSD uboot was what I had to do to on several Rock4 platforms..(Bitcoin Miners re-purposed)

Some devices u-boot don't have the space bar enabled to defeat you. Also saveenv is not available.

With saveenv you could single line feed the boot.scr script to u-boot environment and save it. If saveenv command is installed in u-boot.
 
With this being a difficult board you might wanna hold off on deleting MMC or flash and start investigating..
No working u-boot from official sources and Armibian does not boot.
Knockout punches 1&2

I will skip on that brand.
 
Looking at instructions:
Hit any keys at the moment of bootup to stop autoboot. This step will let Edge boot into U-Boot Mode.
Serial Mode (For Developers):
The command prompt they show as:
kedge#

This is their u-boot prompt. Instead of 'run update' you need to explore contents. Run mmc command to see disk layout.
help command will show all commands built in.

You may not be able to use official u-boot and need to build Khadis u-boot. You need to do some reading.
There have been many Khadis boards over the years and somebody must have some insight.
 
What you can do is 'capture' the u-boot from FreeBSD 13.0 image flashed to microSD and re-use it on newer FreeBSD.
So you use dd to make a file from the microSD that contains the bootloader. You are capturing the first 16M.

Once you do that you can use your captured u-boot to burn back to microSD. You can then boot to u-boot and from USB run the FreeBSD aarch64 installer memstick and install FreeBSD onto eMMC.


To copy first 16MB data you do dd if=/dev/da0 of=uboot.img bs=512 count=32768
So you are making a copy of u-boot from a USB based / microSD here with the filename u-boot.img.
You can then re-use this file. It will contain a partition table but that is not a concern. It is a starting point. No offset required for flashing in dd.
 
Back
Top