Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/nand Add some KASSERTs and a few more debug printf



details:   https://anonhg.NetBSD.org/src/rev/ec9f2c0bec05
branches:  trunk
changeset: 764007:ec9f2c0bec05
user:      ahoka <ahoka%NetBSD.org@localhost>
date:      Sun Apr 10 10:56:37 2011 +0000

description:
Add some KASSERTs and a few more debug printf

diffstat:

 sys/dev/nand/nandemulator.c |  32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)

diffs (140 lines):

diff -r 4a75c5e8df75 -r ec9f2c0bec05 sys/dev/nand/nandemulator.c
--- a/sys/dev/nand/nandemulator.c       Sun Apr 10 10:49:43 2011 +0000
+++ b/sys/dev/nand/nandemulator.c       Sun Apr 10 10:56:37 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nandemulator.c,v 1.2 2011/03/27 13:33:04 ahoka Exp $   */
+/*     $NetBSD: nandemulator.c,v 1.3 2011/04/10 10:56:37 ahoka Exp $   */
 
 /*-
  * Copyright (c) 2011 Department of Software Engineering,
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nandemulator.c,v 1.2 2011/03/27 13:33:04 ahoka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nandemulator.c,v 1.3 2011/04/10 10:56:37 ahoka Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -306,6 +306,8 @@
 {
        struct nandemulator_softc *sc = device_private(self);
 
+       DPRINTF(("device reset\n"));
+
        sc->sc_command = 0;
        sc->sc_register_writable = false;
        sc->sc_io_len = 0;
@@ -321,6 +323,9 @@
 {
        struct nandemulator_softc *sc = device_private(self);
        size_t page, offset;
+
+       KASSERT(sc->sc_address_counter ==
+           sc->sc_column_cycles + sc->sc_row_cycles);
        
        if (sc->sc_address_counter !=
            sc->sc_column_cycles + sc->sc_row_cycles) {
@@ -337,6 +342,8 @@
                (uintmax_t )page,
                (uintmax_t )offset));
 
+       KASSERT(offset < sc->sc_device_size);
+
        if (offset >= sc->sc_device_size) {
                aprint_error_dev(self, "address > device size!\n");
                sc->sc_io_len = 0;
@@ -400,6 +407,8 @@
                KASSERT(offset %
                    (sc->sc_block_size * sc->sc_page_size) == 0);
 
+               KASSERT(offset < sc->sc_device_size);
+
                if (offset >= sc->sc_device_size) {
                        aprint_error_dev(self, "address > device size!\n");
                } else {
@@ -423,6 +432,7 @@
        default:
                aprint_error_dev(self,
                    "invalid nand command (0x%hhx)\n", command);
+               KASSERT(false);
                sc->sc_io_len = 0;
        }
 };
@@ -432,6 +442,8 @@
 {
        struct nandemulator_softc *sc = device_private(self);
 
+       DPRINTF(("nandemulator_address: %hhx\n", address));
+
        /**
         * we have to handle read id/parameter page here,
         * as we can read right after giving the address.
@@ -497,6 +509,8 @@
 {
        struct nandemulator_softc *sc = device_private(self);
 
+       KASSERT(sc->sc_io_len > 0);
+
        if (sc->sc_io_len > 0) {
                *data = *sc->sc_io_pointer;
 
@@ -513,12 +527,16 @@
 {
        struct nandemulator_softc *sc = device_private(self);
 
+       KASSERT(sc->sc_register_writable);
+
        if (!sc->sc_register_writable) {
                aprint_error_dev(self,
                    "trying to write read only location without effect\n");
                return;
        }
 
+       KASSERT(sc->sc_io_len > 0);
+
        if (sc->sc_io_len > 0) {
                *sc->sc_io_pointer = data;
 
@@ -534,12 +552,16 @@
 {
        struct nandemulator_softc *sc = device_private(self);
 
+       KASSERT(sc->sc_buswidth == NANDEMULATOR_16BIT);
+
        if (sc->sc_buswidth != NANDEMULATOR_16BIT) {
                aprint_error_dev(self,
                    "trying to read a word on an 8bit chip\n");
                return;
        }
 
+       KASSERT(sc->sc_io_len > 1);
+
        if (sc->sc_io_len > 1) {
                *data = *(uint16_t *)sc->sc_io_pointer;
 
@@ -556,18 +578,24 @@
 {
        struct nandemulator_softc *sc = device_private(self);
 
+       KASSERT(sc->sc_register_writable);
+
        if (!sc->sc_register_writable) {
                aprint_error_dev(self,
                    "trying to write read only location without effect\n");
                return;
        }
 
+       KASSERT(sc->sc_buswidth == NANDEMULATOR_16BIT);
+
        if (sc->sc_buswidth != NANDEMULATOR_16BIT) {
                aprint_error_dev(self,
                    "trying to write a word to an 8bit chip");
                return;
        }
 
+       KASSERT(sc->sc_io_len > 1);
+
        if (sc->sc_io_len > 1) {
                *(uint16_t *)sc->sc_io_pointer = data;
 



Home | Main Index | Thread Index | Old Index