# Installing FreeBSD on eMMC of Beaglebone



## PVB (Jul 10, 2017)

I have a working copy of the current version of FreeBSD-12 on beaglebone. But this copy is on the SD card. The beagle bone has about 4GB of eMMC space and I want to transfer the image from the SD card to the eMMC. Does anyone know how to do this?


----------



## obsigna (Jul 10, 2017)

You could boot your Beaglebone from the SD card and then use dd(1) to burn the latest Beaglebone FreeBSD 12.0-CURRENT snapshot image to /dev/mmcsd1, by using pretty much the same command which you used for preparing your SD card.

If you want to clone the contents of the working SD card to the internal eMMC, then dd(1) is not that adequate, because most probably the size of the SD card is different from the internal eMMC and in addition dd'ing a live file system is not guaranteed to result in a healthy one on the clone. Therefore, in the case of transferring a live filesystem from the SD card to the internal eMMC, I suggest the following procedure:

1. Convert the Linux partition into a FreeBSD slice using gpart(8)
`gpart show mmcsd1`

This command will show you the current partitioning of the eMMC. My Beaglebone Black got already FreeBSD on the internal eMMC, and therefore the following output is different from the one which above command would output on your Beaglebone:

```
root@CyStat-BBB:~ # gpart show mmcsd1
=>     63  7552961  mmcsd1  MBR  (3.6G)
       63     8129          - free -  (4.0M)
     8192     8192       1  fat32  [active]  (4.0M)
    16384  7536640       2  freebsd  (3.6G)
```
Anyway, the structure should be similar, and you need to identify and delete the partition which contains the Linux OS, which is most probably the one having index 2 -- verify!!! -- the following assumes that it is really 2.

`gpart delete -i 2 mmcsd1`
`gpart add -t freebsd mmcsd1`
`gpart create -s bsd mmcsd1s2`
`gpart add -t freebsd-ufs mmcsd1s2`
`gpart show mmcsd1s2`

```
root@CyStat-BBB:~ # gpart show mmcsd1s2
=>      0  7536640  mmcsd1s2  BSD  (3.6G)
        0  7536640         1  freebsd-ufs  (3.6G)
```

2. Create the file system on the new FreeBSD slice
`newfs -ntEU -L system /dev/mmcsd1s2a`
`tunefs -a enable /dev/mmcsd1s2a`


3. clone(1) the whole FreeBSD 12 installation on the startup volume of your SD card to  /dev/mmcsd1s2a
`pkg install clone`
`mount -o noatime /dev/mmcsd1s2a /mnt`
`clone -c rwoff / /mnt`

Now, don't forget to edit the fstab on the cloned volume:
`nano /mnt/etc/fstab`

```
/dev/ufs/system    /            ufs      rw,noatime            0  1
/dev/label/boot    /boot/msdos  msdosfs  rw,noatime            0  0
tmpfs              /tmp         tmpfs    rw,mode=1777,size=50m 0  0
```
`umount /mnt`


4. Replace the Linux U-Boot image by the FreeBSD one
`mount_msdosfs -o noatime /dev/mmcsd1s1 /mnt`
`rm -r /mnt/*`
`cp -p /boot/msdos/* /mnt/`
`umount /mnt`

`glabel label boot /dev/mmcsd1s1`


----------



## Phishfry (Jul 10, 2017)

The crochet 'copy to emmc' script is designed for this:
https://github.com/freebsd/crochet/blob/master/board/BeagleBone/overlay/root/copy-to-emmc.sh

Right click on the RAW button on the above page. Save this file and do `chmod +x` to it and run the script from the sdcard / directory..

You also need to fix this failsafe:

```
# Remove the following line to make this script actually do something.
exit 1
```


----------



## PVB (Jul 12, 2017)

obsigna said:


> You could boot your Beaglebone from the SD card and then use dd(1) to burn the latest Beaglebone FreeBSD 12.0-CURRENT snapshot image to /dev/mmcsd1, by using pretty much the same command which you used for preparing your SD card.
> 
> If you want to clone the contents of the working SD card to the internal eMMC, then dd(1) is not that adequate, because most probably the size of the SD card is different from the internal eMMC and in addition dd'ing a live file system is not guaranteed to result in a healthy one on the clone. Therefore, I suggest the following procedure:
> 
> ...




Thank you for the information. I was able to just copy the image to the /dev/mmcsd1 using the dd command.


----------



## French Fries (Aug 14, 2017)

I curious about your opinion.

I tried the various scripts above and it failed.
Unfortunately, I don't have a ttl cable, so I am booting "blind" without serial console.

On the converse I booted on the official FreeBSD 11.1 image.
This is BeagleBone revision B with 2GB emmc and 512k memory.
My SD card is 4GB.

First I made an SD card to boot into FreeBSD:
`dd if=FreeBSD-11.1-RELEASE-arm-armv6-BEAGLEBONE.img of=/dev/mysd`

Insert the SD into the Beaglebone and booted on the SD.
You need to click on the little button near USB connector.

For convenience, there are two users:
user: root password:root
user: freebdf password freebsd

When it was done, I connected on the router to fetch Beaglebone IP.
root cannot connect over SSH.

Transfered the installer on the Beagleboard:
`scp FreeBSD-11.1-RELEASE-arm-armv6-BEAGLEBONE.img freebsd@mybeagleboneIP`

Then I simply ssh freebsd@mybeagleboneIP
su to get root and ran:
`dd if=FreeBSD-11.1-RELEASE-arm-armv6-BEAGLEBONE.img of=/dev/mmcsd1`

Upon reboot the partitions grew to fit in the 2GB onboard emmc:
`df -lh
Filesystem                Size    Used   Avail Capacity  Mounted on
/dev/ufs/rootfs           1.7G    906M    718M    56%    /
devfs                     1.0K    1.0K      0B   100%    /dev
/dev/msdosfs/MSDOSBOOT    2.0M    944K    1.1M    47%    /boot/msdos
tmpfs                      50M    4.0K     50M     0%    /tmp`

I am so happy to have a small appliance running FreeBSD.
What is wrong with this installation schema and what should I fix?

Kind regards


----------



## aragats (Aug 14, 2017)

French Fries said:


> What is wrong with this installation schema and what should I fix?


Absolutely nothing is wrong, it's a very good and clean approach.


----------



## pez (Nov 17, 2017)

worked perfectly for me as well, with my Beaglebone Black that has only been collecting dust since receiving it


----------



## aragats (Dec 12, 2017)

Does anybody know why when I run FreeBSD 11.1 form eMMC I get 800 or so lines:
`Card did not respond to voltage select!`?
It looks to be u-boot output, and eventually FreeBSD boots and works properly. The same BBB boots fine from an SD card.

[EDIT] It's not u-boot, but ubldr.bin output. Those warnings start right after jumping to ubldr.bin address.


----------



## Phishfry (Feb 7, 2018)

I see this with FreeBSD 11.1 and 12 with each flashed to eMMC.


----------



## aragats (Feb 7, 2018)

Although FreeBSD has switched to the main line u-boot, I guess, there still are some issues with their interaction.
As I mentioned before and checked again just a week ago, if I use u-boot not from a FreeBSD image, it resets the CPU when jumps to ubldr.bin.
So, one day I'd like to compare u-boot's configurations thoroughly: the source code is the same, but there are so many different variables to be set properly, it's not an hour or two of work. The latest u-boot is capable of loading DTB(O)s, however, I'm not sure whether FreeBSD's kernel can get any advantage out of this. That is really cool, I use it in Linux on BBB: I added a script to u-boot to sources a text file and conditionally load this or that DTB based on possible peripherals connected.


----------



## Phishfry (Feb 7, 2018)

aragats said:


> The latest u-boot is capable of loading DTB(O)s,


I think this is how I got ADC working with dtbo on FreeBSD 11.1. The newer uboot allows overlays.

By default the Ti ADC is enabled but no pins are assigned. So you need the overlay to define the pins.
I have used the /boot/msdos/config.txt facility used on RPi3 with -CURRENT.
First time I have used /boot/loader.conf to enable an overlay.


----------



## nactusberrilli (Jul 31, 2018)

obsigna said:


> `gpart delete 2`



I think this command should read: `gpart delete -i 2 mmcsd1`


----------



## obsigna (Jul 31, 2018)

nactusberrilli said:


> I think this command should read: `gpart delete -i 2 mmcsd1`


Thank you, I corrected the instructions.


----------



## aragats (Jan 10, 2019)

aragats said:


> Does anybody know why when I run FreeBSD 11.1 form eMMC I get 800 or so lines:
> `Card did not respond to voltage select!`?
> It looks to be u-boot output, and eventually FreeBSD boots and works properly. The same BBB boots fine from an SD card.
> 
> [EDIT] It's not u-boot, but ubldr.bin output. Those warnings start right after jumping to ubldr.bin address.


Any ideas regarding that flood of messages?
I measured the clock frequency, it's 50MHz for both external uSD and eMMC. It doesn't look to be related to the hardware.
The message itself comes from the MMC driver of U-Boot (mmc.c). I guess, I can just suppress it in the code as a workaround. Those messages are annoying and significantly increase the boot time of NanoBSD.


----------

