I think I spotted an error in imesdhc.c. This is not related to the issue
of being unable to write (install) on SD cards. Still working on that.

What I think is an error is marked below. If imxesdhc_card_detect returns
true (i.e. a card is detected) then the return value should be what ever is
returned by imxgpio_get_bit()

For BOARD_ID_IMX6_SABRESD (case 3) and BOARD_ID_IMX6_NOVENA (case 2) a
value of 1 is returned without calling imxgpio_set_dir() and
imxgpio_get_bit(). This seems incorrect - no other cases in that nested
switch return 1 without calling those two functions

--- imxesdhc.c imxesdhc_card_detect(...) -------
case BOARD_ID_IMX6_SABRESD:
switch (sc->unit) {
case 1:
gpio = 1*32 + 2;
break;
case 2:
gpio = 1*32 + 0;
break;
case 3:
return 1; - ERROR?
default:
                DPRINTF(0,("HRIDBG imxesdhc_card_detect() 0\n"));
return 0;
}
imxgpio_set_dir(gpio, IMXGPIO_DIR_IN);
return imxgpio_get_bit(gpio) ? 0 : 1;
<snip>

case BOARD_ID_IMX6_NOVENA:
switch (sc->unit) {
case 1:
gpio = 0*32 + 4;
break;
/* no card detect */
case 2:
return 1; -- ERROR ?
default:
return 0;
}
imxgpio_set_dir(gpio, IMXGPIO_DIR_IN);
return imxgpio_get_bit(gpio) ? 0 : 1;
--- imxesdhc.c imxesdhc_card_detect(...) -------

perhaps these two cases should just return 0?

Someone with more expertise in SD card drivers can correct me.

Thanks
Hrishi


On Wed, Jun 3, 2015 at 11:35 PM, Patrick Wildt <[email protected]>
wrote:

> Hi,
>
>
> > Am 03.06.2015 um 17:29 schrieb Hrishikesh Murukkathampoondi <
> [email protected]>:
> >
> > Hello Bitrig Tech
> >
> > Bitrig install on a Freescale iMX6 SABRE Smart Devices board fails with:
> >
> > ---
> > Creating a ext2fs partition and an OpenBSD partition for rest of
> sd0...done.
> > disklabel: ioctl DIOCWDINFO: Input/output error
> > newfs_ext2fs: /dev/rsd0i: open for read: Device not configured
> > ---
> >
> > Patrick mentioned that the SD driver needs to be fixed for the iMX6
> based devices.
> >
> > Is this the driver in /sys/dev/sdmmc or does the installer use a
> different driver?
> >
> > Or is it arch/armv7/imx/imxesdhc.c - the first comment there says
> > /* i.MX SD/MMC support derived from /sys/dev/sdmmc/sdhc.c */
> >
>
> The broken driver is arch/armv7/imx/imxesdhc.c. It was, as the comment
> said, derived from dev/sdmmc/sdhc.c and was modified to "work" for
> i.MX6. I think omap/ommmc.c was also used as a resource for that driver.
>
> Anyway, the issue is in imxesdhc.c. That driver needs to be revisited
> and fixed up. Apparently FreeBSD has a working driver, which is not
> similar to ours, but does a good enough job explaining the quirks of
> that specific controller.
>
> The last few weeks I have backported quite a few changes to sdhc/sdmmc
> from NetBSD. Their sdhc(4) driver, the other one mentioned, can support
> a variety of controllers using flags passed by the attachment driver.
> Thus one does not need to write another completely new sdhc driver like
> imxesdhc, but instead can use what already is in sdhc(4).
>
> NetBSD already supported the Freescale eSDHC (flag enhanced), but it
> looks like not the uSDHC. Another viable option, instead of fixing
> imxesdhc, would be to make imxesdhc compatible to sdhc(4) and implement
> uSDHC specific quirks in sdhc(4).
>
> >
> > The reason I ask is because there is a GSoC project for OpenBSD trying
> to implement simple versions of this driver in libsa. That project is
> intended to enable boot loaders access SD and it appears unfeasible to use
> a "full" driver at boot. I presume there will be two such drivers in Bitrig
> also - a stripped down one for boot/install and another when the OS is up
> and running.
> >
>
> Yes, there is. That project is doing the right thing by implementing a
> bootloader that can be put onto some boot partition and is able to boot
> a kernel loaded from a FFS partition.
>
> It will be interesting to see what techniques will be used to have it
> work with all the very different supported boards.
>
> > Would the section on I/O system (drivers) in the book The Design and
> Implementation of the FreeBSD Operating System 2/e be relevant for Bitrig?
> As a way to learn how drivers work/should be written in BSD.
> >
>
> No idea, sorry. Trying to read and understand sdhc(4)/imxesdhc should be
> another good way to learn how it works.
>
> > I am going to try my hand at getting a driver working for the iMX6
> board. Do let me know if I am barking up the wrong tree. Any pointers on
> what to read etc would be welcome.
> >
> > Thank you
> > Hrishi
>
> Hope it helps, feel free to ask!
> Patrick
>

Reply via email to