From b6534c26153e021cec244bedcad2ea5368c7e554 Mon Sep 17 00:00:00 2001 From: Romain Dolbeau Date: Sun, 21 Mar 2021 11:12:30 -0400 Subject: [PATCH] FAT now mount RO, to be tested more thoroughly --- .../9.0/usr/src/sys/dev/sbus/rdfpga_sdcard.c | 142 +++++++++++++++++- README.md | 4 +- 2 files changed, 137 insertions(+), 9 deletions(-) diff --git a/NetBSD/9.0/usr/src/sys/dev/sbus/rdfpga_sdcard.c b/NetBSD/9.0/usr/src/sys/dev/sbus/rdfpga_sdcard.c index bd725ca..de00be6 100644 --- a/NetBSD/9.0/usr/src/sys/dev/sbus/rdfpga_sdcard.c +++ b/NetBSD/9.0/usr/src/sys/dev/sbus/rdfpga_sdcard.c @@ -98,11 +98,14 @@ const struct cdevsw rdfpga_sdcard_cdevsw = { .d_flag = D_DISK }; +static void rdfpga_sdcard_set_geometry(struct rdfpga_sdcard_softc *sc); static void rdfpga_sdcard_minphys(struct buf *); +static int rdfpga_sdcard_diskstart(device_t self, struct buf *bp); struct dkdriver rdfpga_sdcard_dkdriver = { .d_strategy = rdfpga_sdcard_strategy, - .d_minphys = rdfpga_sdcard_minphys + .d_minphys = rdfpga_sdcard_minphys, + .d_diskstart = rdfpga_sdcard_diskstart }; extern struct cfdriver rdfpga_sdcard_cd; @@ -112,8 +115,6 @@ static int rdfpga_sdcard_wait_device_ready(struct rdfpga_sdcard_softc *sc, const static int rdfpga_sdcard_read_block(struct rdfpga_sdcard_softc *sc, const u_int32_t block, void *data); static int rdfpga_sdcard_write_block(struct rdfpga_sdcard_softc *sc, const u_int32_t block, void *data); -static void rdfpga_sdcard_set_geometry(struct rdfpga_sdcard_softc *sc); - struct rdfpga_sdcard_rb_32to512 { u_int32_t block; u_int8_t data[512]; @@ -142,7 +143,7 @@ rdfpga_sdcard_ioctl (dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) return (ENXIO); } - aprint_normal_dev(sc->dk.sc_dev, "%s:%d: ioctl (0x%08lx, %p, 0x%08x)\n", __PRETTY_FUNCTION__, __LINE__, cmd, data, flag); + aprint_normal_dev(sc->dk.sc_dev, "%s:%d: ioctl (0x%08lx, %p, 0x%08x) part %d\n", __PRETTY_FUNCTION__, __LINE__, cmd, data, flag, DISKPART(dev)); switch (cmd) { case RDFPGA_SDCARD_RS: @@ -316,6 +317,8 @@ rdfpga_sdcard_open(dev_t dev, int flag, int fmt, struct lwp *l) if (sd == NULL) { aprint_error("%s:%d: sd == NULL! giving up\n", __PRETTY_FUNCTION__, __LINE__); return (ENXIO); + } else { + aprint_normal("%s:%d: open device, part is %d\n", __PRETTY_FUNCTION__, __LINE__, DISKPART(dev)); } dksc = &sd->dk; @@ -621,8 +624,10 @@ static int rdfpga_sdcard_write_block(struct rdfpga_sdcard_softc *sc, const u_int void rdfpga_sdcard_strategy(struct buf *bp) -{ +{ +#if 0 struct rdfpga_sdcard_softc *sc = device_lookup_private(&rdfpga_sdcard_cd, DISKUNIT(bp->b_dev)); + int err = 0; if (sc == NULL) { aprint_error("%s:%d: sc == NULL! giving up\n", __PRETTY_FUNCTION__, __LINE__); bp->b_resid = bp->b_bcount; @@ -643,12 +648,26 @@ rdfpga_sdcard_strategy(struct buf *bp) if (bp->b_flags & B_READ) { unsigned char* data = bp->b_data; - daddr_t blk = bp->b_rawblkno; + daddr_t blk = bp->b_blkno; + struct partition *p = NULL; + + if (DISKPART(bp->b_dev) != RAW_PART) { + if ((err = bounds_check_with_label(&sc->dk.sc_dkdev, bp, 0)) <= 0) { + aprint_error("%s:%d: bounds_check_with_label -> %d\n", __PRETTY_FUNCTION__, __LINE__, err); + bp->b_resid = bp->b_bcount; + goto done; + } + p = &sc->dk.sc_dkdev.dk_label->d_partitions[DISKPART(bp->b_dev)]; + blk = bp->b_blkno + p->p_offset; + } while (bp->b_resid >= 512 && !bp->b_error) { if (blk < 62521344) { + aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_blkno = %lld, computed %lld (part %d)\n", __PRETTY_FUNCTION__, __LINE__, bp->b_blkno, blk, DISKPART(bp->b_dev)); +aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_rawblkno = %lld\n", __PRETTY_FUNCTION__, __LINE__, bp->b_rawblkno); bp->b_error = rdfpga_sdcard_read_block(sc, blk, data); } else { + aprint_error("%s:%d: blk = %lld read out of range! giving up\n", __PRETTY_FUNCTION__, __LINE__, blk); bp->b_error = EINVAL; } blk ++; @@ -665,12 +684,22 @@ rdfpga_sdcard_strategy(struct buf *bp) aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_bcount = %d\n", __PRETTY_FUNCTION__, __LINE__, bp->b_bcount); #else unsigned char* data = bp->b_data; - daddr_t blk = bp->b_rawblkno; + daddr_t blk = bp->b_blkno; + + if (DISKPART(bp->b_dev) != RAW_PART) { + if (bounds_check_with_label(&sc->dk.sc_dkdev, bp, 0) <= 0) { + bp->b_resid = bp->b_bcount; + goto done; + } + p = &sc->dk.sc_dkdev.dk_label->d_partitions[DISKPART(bp->b_dev)]; + blk = bp->b_blkno + p->p_offset; + } while (bp->b_resid >= 512 && !bp->b_error) { if (blk < 62521344) { bp->b_error = rdfpga_sdcard_write_block(sc, blk, data); } else { + aprint_error("%s:%d: blk = %lld write out of range! giving up\n", __PRETTY_FUNCTION__, __LINE__, blk); bp->b_error = EINVAL; } blk ++; @@ -685,6 +714,11 @@ rdfpga_sdcard_strategy(struct buf *bp) done: biodone(bp); +#else + struct rdfpga_sdcard_softc *sc = device_lookup_private(&rdfpga_sdcard_cd, DISKUNIT(bp->b_dev)); + + dk_strategy(&sc->dk, bp); +#endif } static void rdfpga_sdcard_set_geometry(struct rdfpga_sdcard_softc *sc) { @@ -718,3 +752,97 @@ rdfpga_sdcard_minphys(struct buf *bp) if (bp->b_bcount > 16) bp->b_bcount = 16; } + +static int +rdfpga_sdcard_diskstart(device_t self, struct buf *bp) +{ + struct rdfpga_sdcard_softc *sc = device_private(self); + int err = 0; + if (sc == NULL) { + aprint_error("%s:%d: sc == NULL! giving up\n", __PRETTY_FUNCTION__, __LINE__); + err = EINVAL; + goto done; + } + /* aprint_normal_dev(sc->dk.sc_dev, "%s:%d: part %d\n", __PRETTY_FUNCTION__, __LINE__, DISKPART(bp->b_dev)); */ + /* aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_bflags = 0x%08x\n", __PRETTY_FUNCTION__, __LINE__, bp->b_flags); */ + /* aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_bufsize = %d\n", __PRETTY_FUNCTION__, __LINE__, bp->b_bufsize); */ + /* aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_blkno = %lld\n", __PRETTY_FUNCTION__, __LINE__, bp->b_blkno); */ + /* aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_rawblkno = %lld\n", __PRETTY_FUNCTION__, __LINE__, bp->b_rawblkno); */ + /* aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_bcount = %d\n", __PRETTY_FUNCTION__, __LINE__, bp->b_bcount); */ + + bp->b_resid = bp->b_bcount; + + if (bp->b_bcount == 0) { + goto done; + } + + if (bp->b_flags & B_READ) { + unsigned char* data = bp->b_data; + daddr_t blk = bp->b_rawblkno; + /* struct partition *p = NULL; */ + + /* if (DISKPART(bp->b_dev) != RAW_PART) { */ + /* if ((err = bounds_check_with_label(&sc->dk.sc_dkdev, bp, 0)) <= 0) { */ + /* aprint_error("%s:%d: bounds_check_with_label -> %d\n", __PRETTY_FUNCTION__, __LINE__, err); */ + /* bp->b_resid = bp->b_bcount; */ + /* goto done; */ + /* } */ + /* p = &sc->dk.sc_dkdev.dk_label->d_partitions[DISKPART(bp->b_dev)]; */ + /* blk = bp->b_blkno + p->p_offset; */ + /* } */ + + while (bp->b_resid >= 512 && !err) { + if (blk < 62521344) { + err = rdfpga_sdcard_read_block(sc, blk, data); + } else { + aprint_error("%s:%d: blk = %lld read out of range! giving up\n", __PRETTY_FUNCTION__, __LINE__, blk); + err = EINVAL; + } + blk ++; + data += 512; + bp->b_resid -= 512; + } + } else { +#if 1 + err = EINVAL; + aprint_normal_dev(sc->dk.sc_dev, "%s:%d: part %d\n", __PRETTY_FUNCTION__, __LINE__, DISKPART(bp->b_dev)); + aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_bflags = 0x%08x\n", __PRETTY_FUNCTION__, __LINE__, bp->b_flags); + aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_bufsize = %d\n", __PRETTY_FUNCTION__, __LINE__, bp->b_bufsize); + aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_blkno = %lld\n", __PRETTY_FUNCTION__, __LINE__, bp->b_blkno); + aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_rawblkno = %lld\n", __PRETTY_FUNCTION__, __LINE__, bp->b_rawblkno); + aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_bcount = %d\n", __PRETTY_FUNCTION__, __LINE__, bp->b_bcount); +#else + unsigned char* data = bp->b_data; + daddr_t blk = bp->b_rawblkno; + /* struct partition *p = NULL; */ + + /* if (DISKPART(bp->b_dev) != RAW_PART) { */ + /* if (bounds_check_with_label(&sc->dk.sc_dkdev, bp, 0) <= 0) { */ + /* bp->b_resid = bp->b_bcount; */ + /* goto done; */ + /* } */ + /* p = &sc->dk.sc_dkdev.dk_label->d_partitions[DISKPART(bp->b_dev)]; */ + /* blk = bp->b_blkno + p->p_offset; */ + /* } */ + + while (bp->b_resid >= 512 && !err) { + if (blk < 62521344) { + err = rdfpga_sdcard_write_block(sc, blk, data); + } else { + aprint_error("%s:%d: blk = %lld write out of range! giving up\n", __PRETTY_FUNCTION__, __LINE__, blk); + err = EINVAL; + } + blk ++; + data += 512; + bp->b_resid -= 512; + } +#endif + } + + /* aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_resid = %d\n", __PRETTY_FUNCTION__, __LINE__, bp->b_resid); */ + /* aprint_normal_dev(sc->dk.sc_dev, "%s:%d: bp->b_error = %d\n", __PRETTY_FUNCTION__, __LINE__, bp->b_error); */ + + done: + biodone(bp); + return err; +} diff --git a/README.md b/README.md index 83ead9c..8fd0df9 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,13 @@ To save on PCB cost, the board is smaller than a 'true' SBus board; the hardware ## Current status -2021-03-14: The adapter board seems to work fine in two different SS20. Currently the embedded PROM code exposes three devices in the FPGA: +2021-03-21: The adapter board seems to work fine in two different SS20. Currently the embedded PROM code exposes three devices in the FPGA: * "RDOL,cryptoengine": exposes a (way too large) polynomial multiplier to implement GCM mode and a AES block. Currently used to implement DMA-based acceleration of AES-256-CBC through /dev/crypto. Unfortunately OpenSSL doesn't support AES-256-GCM in the cryptodev engine, and disagree with NetBSD's /dev/crypto on how to implement AES-256-CTR. And the default SSH cannot use cryptodev, it closes all file descriptors after cryptodev has opened /dev/crypto... still WiP. * "RDOL,trng": exposes a 5 MHz counter (didn't realize the SS20 already had a good counter) and a so-far-not-true TRNG (implemented by a PRNG). The 'true' random generators I've found make Vivado screams very loudly when synthesizing... anyway both works fine in NetBSD 9.0 as a timecounter and an entropy source (which a PRNG really isn't, I know). still WiP. -* "RDOL,sdcard": trying to expose the micro-sd card slot as a storage device, at first using SPI mode. So far reading seems to work, and NetBSD can see a Sun disklabel on the micro-sd card if it has been partitioned that way. Mounting a filesystem doesn't work yet. Writing not working yet. Very much WiP. +* "RDOL,sdcard": trying to expose the micro-sd card slot as a storage device, at first using SPI mode. So far reading seems to work, and NetBSD can see a Sun disklabel on the micro-sd card if it has been partitioned that way. Mounting a FAT filesystem read-only now works (with very little testing as of yet). Writing not working yet. Very much WiP. ## The hardware