Module Name: src
Committed By: ahoka
Date: Sun Apr 10 10:56:37 UTC 2011
Modified Files:
src/sys/dev/nand: nandemulator.c
Log Message:
Add some KASSERTs and a few more debug printf
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/nand/nandemulator.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/nand/nandemulator.c
diff -u src/sys/dev/nand/nandemulator.c:1.2 src/sys/dev/nand/nandemulator.c:1.3
--- src/sys/dev/nand/nandemulator.c:1.2 Sun Mar 27 13:33:04 2011
+++ src/sys/dev/nand/nandemulator.c Sun Apr 10 10:56:37 2011
@@ -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;