diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-12-07 16:00:56 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2012-12-07 16:00:56 +0000 |
commit | 756aa6b90920d0087ad708c3ad10e091be79e46e (patch) | |
tree | c29f3db20b8275cd22e7c4d36c3d722f2fdf6277 /nuttx/drivers/mtd/ftl.c | |
parent | 4c98d2e73211a2bde3530c9f1f369efa0d0745e1 (diff) | |
download | px4-firmware-756aa6b90920d0087ad708c3ad10e091be79e46e.tar.gz px4-firmware-756aa6b90920d0087ad708c3ad10e091be79e46e.tar.bz2 px4-firmware-756aa6b90920d0087ad708c3ad10e091be79e46e.zip |
Patches from Petteri Aimonen + stdbool and rand() changes for Freddie Chopin
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5415 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/drivers/mtd/ftl.c')
-rw-r--r-- | nuttx/drivers/mtd/ftl.c | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/nuttx/drivers/mtd/ftl.c b/nuttx/drivers/mtd/ftl.c index cdb35aa5c..6cf8f0317 100644 --- a/nuttx/drivers/mtd/ftl.c +++ b/nuttx/drivers/mtd/ftl.c @@ -1,7 +1,7 @@ /**************************************************************************** * drivers/mtd/ftl.c * - * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2011-2012 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -229,6 +229,10 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer, remaining = nblocks; if (alignedblock > startblock) { + /* Check if the write is shorter than to the end of the erase block */ + + bool short_write = (remaining < (alignedblock - startblock)); + /* Read the full erase block into the buffer */ rwblock = startblock & ~mask; @@ -252,9 +256,19 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer, /* Copy the user data at the end of the buffered erase block */ offset = (startblock & mask) * dev->geo.blocksize; - nbytes = dev->geo.erasesize - offset; + + if (short_write) + { + nbytes = remaining * dev->geo.blocksize; + } + else + { + nbytes = dev->geo.erasesize - offset; + } + fvdbg("Copy %d bytes into erase block=%d at offset=%d\n", nbytes, eraseblock, offset); + memcpy(dev->eblock + offset, buffer, nbytes); /* And write the erase back to flash */ @@ -268,8 +282,16 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer, /* Then update for amount written */ - remaining -= dev->blkper - (startblock & mask); - buffer += nbytes; + if (short_write) + { + remaining = 0; + } + else + { + remaining -= dev->blkper - (startblock & mask); + } + + buffer += nbytes; } /* How handle full erase pages in the middle */ @@ -290,6 +312,7 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer, fvdbg("Write %d bytes into erase block=%d at offset=0\n", dev->geo.erasesize, alignedblock); + nxfrd = MTD_BWRITE(dev->mtd, alignedblock, dev->blkper, buffer); if (nxfrd != dev->blkper) { |