Changeset 03d2108 in rtems


Ignore:
Timestamp:
Jul 1, 2011, 1:05:06 PM (8 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
d504e48
Parents:
baa12f26
Message:

2011-07-01 Stephan Hoffmann <sho@…>

Sebastian Huber <sebastian.huber@…>

  • misc/nand-mlc-erase-block-safe.c: New file
  • Makefile.am: Reflect change from above.
  • misc/nand-mlc-write-blocks.c: Use lpc32xx_mlc_erase_block_safe_3().
  • include/nand-mlc.h: Bad block handling.
Location:
c/src/lib/libbsp/arm/lpc32xx
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/lpc32xx/ChangeLog

    rbaa12f26 r03d2108  
     12011-07-01      Stephan Hoffmann <sho@reLinux.de>
     2                Sebastian Huber <sebastian.huber@embedded-brains.de>
     3
     4        * misc/nand-mlc-erase-block-safe.c: New file
     5        * Makefile.am: Reflect change from above.
     6        * misc/nand-mlc-write-blocks.c: Use lpc32xx_mlc_erase_block_safe_3().
     7        * include/nand-mlc.h: Bad block handling.
     8
    192011-06-19      Ralf Corsépius <ralf.corsepius@rtems.org>
    210
  • c/src/lib/libbsp/arm/lpc32xx/Makefile.am

    rbaa12f26 r03d2108  
    126126        misc/nand-mlc-read-blocks.c \
    127127        misc/nand-mlc-write-blocks.c \
     128        misc/nand-mlc-erase-block-safe.c \
    128129        misc/restart.c \
    129130        misc/boot.c \
  • c/src/lib/libbsp/arm/lpc32xx/include/nand-mlc.h

    rbaa12f26 r03d2108  
    88
    99/*
    10  * Copyright (c) 2010
    11  * embedded brains GmbH
    12  * Obere Lagerstr. 30
    13  * D-82178 Puchheim
    14  * Germany
    15  * <rtems@embedded-brains.de>
     10 * Copyright (c) 2010-2011 embedded brains GmbH.  All rights reserved.
     11 *
     12 *  embedded brains GmbH
     13 *  Obere Lagerstr. 30
     14 *  82178 Puchheim
     15 *  Germany
     16 *  <rtems@embedded-brains.de>
     17 *
     18 * Copyright (c) 2011 Stephan Hoffmann <sho@reLinux.de>
    1619 *
    1720 * The license and distribution terms for this file may be
     
    167170
    168171/**
     172 * @brief Bad block mark.
     173 *
     174 * We define our own bad block mark to be able to recognize the blocks that
     175 * have been marked bad during operation later.
     176 */
     177#define MLC_BAD_BLOCK_MARK ((uint32_t) 0xbadb)
     178
     179/**
     180 * @brief The bytes 4 and 5 are reserved for bad block handling.
     181 */
     182#define MLC_RESERVED ((uint32_t) 0xffff)
     183
     184/**
    169185 * @name NAND Status Register
    170186 *
     
    254270
    255271/**
     272 * @brief Erases the block with index @a block_index.
     273 *
     274 * In case of an erase error all pages and the spare areas of this block are
     275 * programmed with zero values.  This will mark the first and second page as
     276 * bad.
     277 *
     278 * @retval RTEMS_SUCCESSFUL Successful operation.
     279 * @retval RTEMS_INCORRECT_STATE The first or second page of this block is bad.
     280 * @retval RTEMS_INVALID_ID Invalid @a block_index value.
     281 * @retval RTEMS_IO_ERROR Erase error.
     282 */
     283rtems_status_code lpc32xx_mlc_erase_block_safe(uint32_t block_index);
     284
     285/**
     286 * @brief Erases the block with index @a block_index.
     287 *
     288 * Variant of lpc32xx_mlc_erase_block_safe() with more parameters for
     289 * efficiency reasons.
     290 */
     291rtems_status_code lpc32xx_mlc_erase_block_safe_3(
     292  uint32_t block_index,
     293  uint32_t first_page_of_block,
     294  uint32_t pages_per_block
     295);
     296
     297/**
    256298 * @brief Writes the page with index @a page_index.
    257299 *
     
    279321 * @retval RTEMS_SUCCESSFUL Successful operation.
    280322 * @retval RTEMS_INVALID_ID Invalid @a block_begin or @a block_end value.
    281  * @retval RTEMS_IO_ERROR To many bad blocks or source area to big.
     323 * @retval RTEMS_IO_ERROR Too many bad blocks or source area too big.
    282324 */
    283325rtems_status_code lpc32xx_mlc_write_blocks(
     
    329371}
    330372
     373static inline void lpc32xx_mlc_set_bad_page(uint32_t *spare)
     374{
     375  spare [1] = MLC_BAD_BLOCK_MARK;
     376}
     377
     378static inline void lpc32xx_mlc_set_reserved(uint32_t *spare)
     379{
     380  spare [1] = MLC_RESERVED;
     381}
     382
    331383/** @} */
    332384
  • c/src/lib/libbsp/arm/lpc32xx/misc/nand-mlc-write-blocks.c

    rbaa12f26 r03d2108  
    88
    99/*
    10  * Copyright (c) 2010
    11  * embedded brains GmbH
    12  * Obere Lagerstr. 30
    13  * D-82178 Puchheim
    14  * Germany
    15  * <rtems@embedded-brains.de>
     10 * Copyright (c) 2010-2011 embedded brains GmbH.  All rights reserved.
     11 *
     12 *  embedded brains GmbH
     13 *  Obere Lagerstr. 30
     14 *  82178 Puchheim
     15 *  Germany
     16 *  <rtems@embedded-brains.de>
    1617 *
    1718 * The license and distribution terms for this file may be
     
    2122
    2223#include <bsp/nand-mlc.h>
    23 
    24 #include <string.h>
    25 
    26 #include <bsp.h>
    2724
    2825static const uint32_t ones_spare [MLC_LARGE_SPARE_WORD_COUNT] = {
     
    4441  0xffffffff
    4542};
    46 
    47 static void zero_block(uint32_t first_page_of_block, uint32_t pages_per_block)
    48 {
    49   uint32_t page = 0;
    50 
    51   for (page = 0; page < pages_per_block; ++page) {
    52     lpc32xx_mlc_write_page_with_ecc(
    53       first_page_of_block + page,
    54       lpc32xx_magic_zero_begin,
    55       lpc32xx_magic_zero_begin
    56     );
    57   }
    58 }
    59 
    60 static bool is_bad_page(
    61   uint32_t first_page_of_block,
    62   uint32_t page
    63 )
    64 {
    65   uint32_t spare [MLC_LARGE_SPARE_WORD_COUNT];
    66 
    67   memset(spare, 0, MLC_LARGE_SPARE_SIZE);
    68   lpc32xx_mlc_read_page(
    69     first_page_of_block + page,
    70     lpc32xx_magic_zero_begin,
    71     spare
    72   );
    73   return lpc32xx_mlc_is_bad_page(spare);
    74 }
    75 
    76 static rtems_status_code erase_block(
    77   uint32_t block,
    78   uint32_t first_page_of_block,
    79   uint32_t pages_per_block
    80 )
    81 {
    82   rtems_status_code sc = RTEMS_SUCCESSFUL;
    83 
    84   if (is_bad_page(first_page_of_block, 0)) {
    85     return RTEMS_IO_ERROR;
    86   }
    87 
    88   if (is_bad_page(first_page_of_block, 1)) {
    89     return RTEMS_IO_ERROR;
    90   }
    91 
    92   sc = lpc32xx_mlc_erase_block(block);
    93   if (sc != RTEMS_SUCCESSFUL) {
    94     zero_block(first_page_of_block, pages_per_block);
    95 
    96     return RTEMS_IO_ERROR;
    97   }
    98 
    99   return RTEMS_SUCCESSFUL;
    100 }
    10143
    10244rtems_status_code lpc32xx_mlc_write_blocks(
     
    12567    uint32_t page = 0;
    12668
    127     sc = erase_block(block, first_page_of_block, pages_per_block);
     69    sc = lpc32xx_mlc_erase_block_safe_3(
     70      block,
     71      first_page_of_block,
     72      pages_per_block
     73    );
    12874    if (sc != RTEMS_SUCCESSFUL) {
    12975      continue;
Note: See TracChangeset for help on using the changeset viewer.