# Unsure how to Making a SD Card Device Driver for FreeBSD without block device



## jchan21 (Apr 28, 2020)

I want to make a sd card reader for FreeBSD on a RPI3 for a project like a SD card kernal module. I know how SD card works as with Block Device but block device is gone. So, I would like any suggestion on how to build a sd card driver in freebsd for ARM architecture. Thanks! Is there a library already for a FreeBSD SD card driver?


Thanks!


----------



## mark_j (Apr 28, 2020)

FreeBSD already has a CAM driver for SD cards. See umass(4) driver. Also: cam(3).
Apologies if I misunderstood.


----------



## jchan21 (Apr 28, 2020)

mark_j said:


> FreeBSD already has a CAM driver for SD cards. See umass(4) driver. Also: cam(3).
> Apologies if I misunderstood.



Thanks, I will look into those. If you have ever booted FreeBSD on PI with USB, is there a command to see if there is a SD card plug into the pi?


----------



## mark_j (Apr 28, 2020)

No, sorry, I haven't booted from USB as this is a permanent change and I've had trouble in the past with Raspberry Pi 3B. Booting it via USB isn't an option as yet for me (namely if you use an extension cable, FreeBSD takes a very, very long time to sense it) .

I may have steered you in the wrong direction, too. I thought the USB bus controlled all but it doesn't the SD card.

This can be verified with:

`camcontrol identify 0:0`

It will only show the first attached USB device, not the SD, eg:

```
pass0: <SanDisk SSD U100 64GB KM.10.00> ACS-2 ATA SATA 3.x device
pass0: 40.000MB/s transfers

protocol              ACS-2 ATA SATA 3.x
device model          SanDisk SSD U100 64GB
firmware revision     KM.10.00
serial number         0b588f96a
WWN                   5001b40088b56af9
additional product id
cylinders             16383
heads                 16
sectors/track         63
sector size           logical 512, physical 512, offset 0
LBA supported         125045424 sectors
LBA48 supported       125045424 sectors
PIO supported         PIO4
DMA supported         WDMA2 UDMA6
media RPM             non-rotating
Zoned-Device Commands no
```

Well, I guess to see the card you could use many commands. Perhaps `geom disk list`?

Under FreeBSD12.1R0, it shows up as:

```
sdhci_bcm0: <Broadcom 2708 SDHCI controller> mem 0x7e300000-0x7e3000ff irq 50 on simplebus0
mmc0: <MMC/SD bus> on sdhci_bcm0
```

simplebus is just the driver for the flattened device tree: fdt(4)
Some links:









						freebsd-src/bcm2835_sdhci.c at master · freebsd/freebsd-src
					

FreeBSD src tree (read-only mirror). Contribute to freebsd/freebsd-src development by creating an account on GitHub.




					github.com
				



(note in the source some of the tuneables available to debug it)






						RPI BCM2708 Parameters - eLinux.org
					






					elinux.org


----------



## jchan21 (Apr 28, 2020)

mark_j said:


> No, sorry, I haven't booted from USB as this is a permanent change and I've had trouble in the past with Raspberry Pi 3B. Booting it via USB isn't an option as yet for me (namely if you use an extension cable, FreeBSD takes a very, very long time to sense it) .
> 
> I may have steered you in the wrong direction, too. I thought the USB bus controlled all but it doesn't the SD card.
> 
> ...



That was helpful. Last question, so my SD CARD does show up . The file PATH is /dev/msdosfs/CANAKIT. I have a folder inside the SD CARD. Is there a way to access that. Because the CANAKIT shows up as not a directory. I am bad at this. Thank you so much.

Name is  mmcsd0  when i do geom disk list


I actually figure how mount the SD card with mount -t msdosfs -o rw /dev/mmcsd0s1 /mnt/
and see the files.
Thanks for all the help.

Now I guess i need to have the ethernet or internet set up on the FreeBSD in PI. Any suggestions on that?


----------



## mark_j (Apr 28, 2020)

What raspberry Pi are you using?
It occurred to me that last I read, FreeBSD can boot from the USB via UEFI on Raspberry Pi 4. Previous versions are impossible to boot that way unless you modify it permanently:








						Raspberry Pi Documentation - Raspberry Pi hardware
					

The official documentation for Raspberry Pi computers and microcontrollers



					www.raspberrypi.org
				




Internet setup? What image are you using? It should do it for you - even if you build the image yourself using crochet.


----------



## jchan21 (Apr 29, 2020)

Raspberry Pi 3B, i booted 12.1 release on it with USB drive.


----------



## mark_j (Apr 29, 2020)

Assuming you used the aarch64 build:


			https://download.freebsd.org/ftp/releases/arm64/aarch64/ISO-IMAGES/12.1/FreeBSD-12.1-RELEASE-arm64-aarch64-RPI3.img.xz
		

Then the network is set up for you via DHCP. The first few entries in your /etc/rc.conf will be:

```
ifconfig_DEFAULT="DHCP"
sshd_enable="YES"
```
If you have no network, then you will have to connect a keyboard and monitor to it and set it up that way.


----------

