[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 05/12] hw/nand: Writing to NAND can only clear bits
From: |
Peter Maydell |
Subject: |
[Qemu-devel] [PATCH 05/12] hw/nand: Writing to NAND can only clear bits |
Date: |
Fri, 15 Jul 2011 15:58:19 +0100 |
Writing to a NAND device cannot set bits, it can only clear them;
implement this rather than simply copying the data.
Signed-off-by: Peter Maydell <address@hidden>
---
hw/nand.c | 17 +++++++++++++----
1 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/hw/nand.c b/hw/nand.c
index e6c551d..d068eb6 100644
--- a/hw/nand.c
+++ b/hw/nand.c
@@ -75,6 +75,15 @@ struct NANDFlashState {
uint32_t ioaddr_vmstate;
};
+static void mem_and(uint8_t *dest, const uint8_t *src, size_t n)
+{
+ /* Like memcpy() but we logical-AND the data into the destination */
+ int i;
+ for (i = 0; i < n; i++) {
+ dest[i] &= src[i];
+ }
+}
+
# define NAND_NO_AUTOINCR 0x00000001
# define NAND_BUSWIDTH_16 0x00000002
# define NAND_NO_PADDING 0x00000004
@@ -595,7 +604,7 @@ static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState
*s)
return;
if (!s->bdrv) {
- memcpy(s->storage + PAGE_START(s->addr) + (s->addr & PAGE_MASK) +
+ mem_and(s->storage + PAGE_START(s->addr) + (s->addr & PAGE_MASK) +
s->offset, s->io, s->iolen);
} else if (s->mem_oob) {
sector = SECTOR(s->addr);
@@ -606,10 +615,10 @@ static void glue(nand_blk_write_,
PAGE_SIZE)(NANDFlashState *s)
return;
}
- memcpy(iobuf + (soff | off), s->io, MIN(s->iolen, PAGE_SIZE - off));
+ mem_and(iobuf + (soff | off), s->io, MIN(s->iolen, PAGE_SIZE - off));
if (off + s->iolen > PAGE_SIZE) {
page = PAGE(s->addr);
- memcpy(s->storage + (page << OOB_SHIFT), s->io + PAGE_SIZE - off,
+ mem_and(s->storage + (page << OOB_SHIFT), s->io + PAGE_SIZE - off,
MIN(OOB_SIZE, off + s->iolen - PAGE_SIZE));
}
@@ -624,7 +633,7 @@ static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState
*s)
return;
}
- memcpy(iobuf + soff, s->io, s->iolen);
+ mem_and(iobuf + soff, s->io, s->iolen);
if (bdrv_write(s->bdrv, sector, iobuf, PAGE_SECTORS + 2) == -1)
printf("%s: write error in sector %" PRIu64 "\n", __func__,
sector);
--
1.7.1
- [Qemu-devel] [PATCH 00/12] bugfix and qdevify NAND and ONENAND devices, Peter Maydell, 2011/07/15
- [Qemu-devel] [PATCH 10/12] hw/onenand: program actions can only clear bits, Peter Maydell, 2011/07/15
- [Qemu-devel] [PATCH 06/12] hw/nand: qdevify, Peter Maydell, 2011/07/15
- [Qemu-devel] [PATCH 05/12] hw/nand: Writing to NAND can only clear bits,
Peter Maydell <=
- [Qemu-devel] [PATCH 11/12] hw/sysbus: Add sysbus_mmio_unmap() for unmapping a region, Peter Maydell, 2011/07/15
- [Qemu-devel] [PATCH 08/12] onenand: Handle various ID fields separately, Peter Maydell, 2011/07/15
- [Qemu-devel] [PATCH 12/12] hw/onenand: qdevify, Peter Maydell, 2011/07/15
- [Qemu-devel] [PATCH 02/12] hw/nand: Support large NAND devices, Peter Maydell, 2011/07/15
- [Qemu-devel] [PATCH 09/12] onenand: Ignore zero writes to boot command space, Peter Maydell, 2011/07/15
- [Qemu-devel] [PATCH 07/12] onenand: Pass BlockDriverState to init function, Peter Maydell, 2011/07/15
- [Qemu-devel] [PATCH 04/12] hw/nand: Support multiple reads following READ STATUS, Peter Maydell, 2011/07/15
- [Qemu-devel] [PATCH 03/12] hw/nand: Support devices wider than 8 bits, Peter Maydell, 2011/07/15
- [Qemu-devel] [PATCH 01/12] hw/nand: Pass block device state to init function, Peter Maydell, 2011/07/15
- Re: [Qemu-devel] [PATCH 00/12] bugfix and qdevify NAND and ONENAND devices, Peter Maydell, 2011/07/28