07 Nov, 2013

3 commits

  • Now that the last user of NAND_BBT_SCANALLPAGES has been removed, let's
    kill this peculiar BBT feature flag.

    Signed-off-by: Brian Norris
    Reviewed-by: Ezequiel Garcia
    Signed-off-by: Artem Bityutskiy

    Brian Norris
     
  • Hardware:
    CPU: XLP832,the 64-bit OS
    NOR Flash:S29GL128S 128M
    Software:
    Kernel:2.6.32.41
    Filesystem:JFFS2
    When writing files, errors appear:
    Write len 182 but return retlen 180
    Write of 182 bytes at 0x072c815c failed. returned -5, retlen 180
    Write len 186 but return retlen 184
    Write of 186 bytes at 0x072caff4 failed. returned -5, retlen 184
    These errors exist only in 64-bit systems,not in 32-bit systems. After analysis, we
    found that the left shift operation is wrong in map_word_load_partial. For instance:
    unsigned char buf[3] ={0x9e,0x3a,0xea};
    map_bankwidth(map) is 4;
    for (i=0; i < 3; i++) {
    int bitpos;
    bitpos = (map_bankwidth(map)-1-i)*8;
    orig.x[0] &= ~(0xff << bitpos);
    orig.x[0] |= buf[i] << bitpos;
    }

    The value of orig.x[0] is expected to be 0x9e3aeaff, but in this situation(64-bit
    System) we'll get the wrong value of 0xffffffff9e3aeaff due to the 64-bit sign
    extension:
    buf[i] is defined as "unsigned char" and the left-shift operation will convert it
    to the type of "signed int", so when left-shift buf[i] by 24 bits, the final result
    will get the wrong value: 0xffffffff9e3aeaff.

    If the left-shift bits are less than 24, then sign extension will not occur. Whereas
    the bankwidth of the nor flash we used is 4, therefore this BUG emerges.

    Signed-off-by: Pang Xunlei
    Signed-off-by: Zhang Yi
    Signed-off-by: Lu Zhongjun
    Cc:
    Signed-off-by: Brian Norris

    Wang Haitao
     
  • This patch moves the char and block major number definitions
    to major.h to be with the rest of the major numbers.
    While doing this, include major.h in the files that need it.

    Signed-off-by: Ezequiel Garcia
    Signed-off-by: Brian Norris

    Ezequiel Garcia
     

28 Oct, 2013

4 commits

  • This helper detects that whether the mtd's type is nand type.

    Now, it's clear that the MTD_NANDFLASH stands for SLC nand only.
    So use the mtd_type_is_nand() to replace the old check method
    to do the nand type (include the SLC and MLC) check.

    Signed-off-by: Huang Shijie
    Signed-off-by: Brian Norris

    Huang Shijie
     
  • The @cellinfo fields contains unused information, such as write caching,
    internal chip numbering, etc. But we only use it to check the SLC or MLC.

    This patch tries to make it more clear and simple, renames the @cellinfo
    to @bits_per_cell.

    In order to avoiding the bisect issue, this patch also does the following
    changes:
    (0) add a macro NAND_CI_CELLTYPE_SHIFT to avoid the hardcode.

    (1) add a helper to parse out the cell type : nand_get_bits_per_cell()

    (2) parse out the cell type for extended-ID chips and the full-id nand chips.

    Signed-off-by: Huang Shijie
    Signed-off-by: Brian Norris

    Huang Shijie
     
  • Add a helper to check if a nand chip is SLC or MLC.
    This helper makes the code more readable.

    Signed-off-by: Huang Shijie
    Signed-off-by: Brian Norris

    Huang Shijie
     
  • This field is never used, except to print it out.

    Signed-off-by: Brian Norris

    Brian Norris
     

31 Aug, 2013

5 commits

  • In order to implement the NAND boot for some Freescale's chips, such as
    imx23/imx28/imx50/imx6, we use a tool (called kobs-ng) to burn the uboot
    and some metadata to nand chip. And the ROM code will use the metadata to
    configrate the BCH, and to find the uboot.

    The ECC information(ecc step size, ecc strength) which is used to configrure
    the BCH is part of the metadata. The kobs-ng can get the ecc strength from
    the sys node /sys/*/ecc_strength now. But it can not get the ecc step size.

    This patch adds a new field to store the ecc step size in mtd_info{}, and
    it makes preparation for the next patches.

    Signed-off-by: Huang Shijie
    Signed-off-by: Artem Bityutskiy
    Signed-off-by: Brian Norris
    Signed-off-by: David Woodhouse

    Huang Shijie
     
  • Add an instance of an anonymous struct to store the ECC info for full id
    nand chips.
    @ecc.strength_ds: ECC correctability from the datasheet.
    @ecc.step_ds: ECC size required by the @ecc.strength_ds,

    These two fields are all from the datasheet.

    Also add the necessary macros to make the code simple and clean.

    Signed-off-by: Huang Shijie
    Signed-off-by: Brian Norris
    Signed-off-by: David Woodhouse

    Huang Shijie
     
  • add a helper to get the supported features for ONFI nand.
    Also add the neccessary macros.

    Signed-off-by: Huang Shijie
    Reviewed-and-tested-by: Brian Norris
    Signed-off-by: Brian Norris
    Signed-off-by: David Woodhouse

    Huang Shijie
     
  • Since the ONFI 2.1, the onfi spec adds the Extended Parameter Page
    to store the ECC info.

    The onfi spec tells us that if the nand chip's recommended ECC codeword
    size is not 512 bytes, then the @ecc_bits is 0xff. The host _SHOULD_ then
    read the Extended ECC information that is part of the extended parameter
    page to retrieve the ECC requirements for this device.

    This patch adds
    [1] the neccessary fields for nand_onfi_params{},
    [2] and adds the onfi_ext_ecc_info{} for Extended ECC information,
    [3] adds onfi_ext_section{} for extended sections,
    [4] and adds onfi_ext_param_page{} for the Extended Parameter Page.

    Acked-by: Pekon Gupta
    Signed-off-by: Huang Shijie
    Reviewed-and-tested-by: Brian Norris
    [Brian: amended for checkpatch.pl]
    Signed-off-by: Brian Norris

    Signed-off-by: David Woodhouse

    Huang Shijie
     
  • 1.) Why add the ECC information to the nand_chip{} ?
    Each nand chip has its requirement for the ECC correctability, such as
    "4bit ECC for each 512Byte" or "40bit ECC for each 1024Byte".
    This ECC info is very important to the nand controller, such as gpmi.

    Take the Micron MT29F64G08CBABA for example, its geometry is
    8KiB page size, 744 bytes oob size and it requires 40bit ECC per 1KiB.
    If we do not provide the ECC info to the gpmi nand driver, it has to
    calculate the ECC correctability itself. The gpmi driver will gets the 56bit
    ECC for per 1KiB which is beyond its BCH's 40bit ecc capibility.
    The gpmi will quits in this case. But in actually, the gpmi can supports
    this nand chip if it can get the right ECC info.

    2.) about the new fields.
    The @ecc_strength_ds stands for the ecc bits needed within the @ecc_step_ds.
    The two fields should be set from the nand chip's datasheets.

    For example:
    "4bit ECC for each 512Byte" could be:
    @ecc_strength_ds = 4, @ecc_step_ds = 512.
    "40bit ECC for each 1024Byte" could be:
    @ecc_strength_ds = 40, @ecc_step_ds = 1024.

    3.) Why do not re-use the @strength and @size in the nand_ecc_ctrl{}?
    The @strength and @size in nand_ecc_ctrl{} is used by the nand controller
    driver, while the @ecc_strength_ds and @ecc_step_ds are get from the datasheet.

    Signed-off-by: Huang Shijie
    Reviewed-and-tested-by: Brian Norris
    Signed-off-by: Brian Norris
    Signed-off-by: David Woodhouse

    Huang Shijie
     

30 Aug, 2013

2 commits

  • NAND_BBT_SCANEMPTY is a strange, badly-supported option with omap as its
    single remaining user.

    NAND_BBT_SCANEMPTY was likely used by accident in omap2[1]. And anyway,
    omap2 doesn't scan the chip for bad blocks (courtesy of
    NAND_SKIP_BBTSCAN), and so its use of this option is irrelevant.

    This patch drops the NAND_BBT_SCANEMPTY option.

    [1] http://lists.infradead.org/pipermail/linux-mtd/2012-July/042902.html

    Signed-off-by: Brian Norris
    Cc: Ivan Djelic
    Signed-off-by: Artem Bityutskiy
    Signed-off-by: David Woodhouse

    Brian Norris
     
  • nand_base.c shouldn't have to know the implementation details of
    nand_bbt's in-memory BBT. Specifically, nand_base shouldn't perform the
    bit masking and shifting to isolate a BBT entry.

    Instead, just move some of the BBT code into a new nand_markbad_bbt()
    interface. This interface allows external users (i.e., nand_base) to
    mark a single block as bad in the BBT. Then nand_bbt will take care of
    modifying the in-memory BBT and updating the flash-based BBT (if
    applicable).

    Signed-off-by: Brian Norris
    Signed-off-by: Artem Bityutskiy
    Signed-off-by: David Woodhouse

    Brian Norris
     

06 Aug, 2013

4 commits


10 May, 2013

1 commit

  • Pull MTD update from David Woodhouse:

    - Lots of cleanups from Artem, including deletion of some obsolete
    drivers

    - Support partitions larger than 4GiB in device tree

    - Support for new SPI chips

    * tag 'for-linus-20130509' of git://git.infradead.org/linux-mtd: (83 commits)
    mtd: omap2: Use module_platform_driver()
    mtd: bf5xx_nand: Use module_platform_driver()
    mtd: denali_dt: Remove redundant use of of_match_ptr
    mtd: denali_dt: Change return value to fix smatch warning
    mtd: denali_dt: Use module_platform_driver()
    mtd: denali_dt: Fix incorrect error check
    mtd: nand: subpage write support for hardware based ECC schemes
    mtd: omap2: use msecs_to_jiffies()
    mtd: nand_ids: use size macros
    mtd: nand_ids: improve LEGACY_ID_NAND macro a bit
    mtd: add 4 Toshiba nand chips for the full-id case
    mtd: add the support to parse out the full-id nand type
    mtd: add new fields to nand_flash_dev{}
    mtd: sh_flctl: Use of_match_ptr() macro
    mtd: gpio: Use of_match_ptr() macro
    mtd: gpio: Use devm_kzalloc()
    mtd: davinci_nand: Use of_match_ptr()
    mtd: dataflash: Use of_match_ptr() macro
    mtd: remove h720x flash support
    mtd: onenand: remove OneNAND simulator
    ...

    Linus Torvalds
     

06 May, 2013

1 commit


05 Apr, 2013

16 commits

  • This patch adds support for subpage (partial-page) writes when using
    hardware based ECC schemes.
    Advantages:
    (1) reduces storage overhead when using file-systems like UBIFS, which
    store LEB header at page-size granularity.
    (2) allows independent subpage writes, thereby increasing NAND storage
    efficiency for non-page aligned data.
    + updated cafe_nand and lpc32xx_mlc NAND drivers for change in
    chip->write_page interface.

    Signed-off-by: Gupta, Pekon
    Signed-off-by: Artem Bityutskiy
    Signed-off-by: David Woodhouse

    Gupta, Pekon
     
  • Notice that all the flashes belonging to the "legacy ID" class have 512 bytes
    NAND page. This means we may simplify the 'LEGACY_ID_NAND()' macro as well as
    the NAND ID table a little.

    Signed-off-by: Artem Bityutskiy
    Signed-off-by: David Woodhouse

    Artem Bityutskiy
     
  • As time goes on, we begin to meet the situation that we can not get enough
    information from some nand chips's id data. Take some Toshiba's nand chips
    for example. I have 4 Toshiba's nand chips in my hand:
    TC58NVG2S0F, TC58NVG3S0F, TC58NVG5D2, TC58NVG6D2

    When we read these chips' datasheets, we will get the geometry of these chips:
    TC58NVG2S0F : 4096 + 224
    TC58NVG3S0F : 4096 + 232
    TC58NVG5D2 : 8192 + 640
    TC58NVG6D2 : 8192 + 640

    But we can not parse out the correct oob size for these chips from the id data.

    This patch adds some new fields to the nand_flash_dev{}:
    @id_len: the valid length of the id data. See the comments in
    nand_id_has_period()
    @oobsize: the oob size.

    Signed-off-by: Huang Shijie
    Reviewed-by: Brian Norris
    Signed-off-by: Artem Bityutskiy
    Signed-off-by: David Woodhouse

    Huang Shijie
     
  • Introduce a helpful macro for the maximum NAND ID sequence length instead of
    using the "8" magic number.

    Signed-off-by: Artem Bityutskiy
    Acked-by: Huang Shijie
    Signed-off-by: David Woodhouse

    Artem Bityutskiy
     
  • Use 'unsigned int' instead of 'unsigned long' in the NAND chip description data
    structure, because 32-bits is more than enough for our purposes. We do not need
    64-bits, which is what we end up on 64-bit architectures. We declare many
    instances of this data structure, so this should help saving some amount of
    memory.

    Signed-off-by: Artem Bityutskiy
    Signed-off-by: David Woodhouse

    Artem Bityutskiy
     
  • Be a bit stricter and add few more 'const' qualifiers.

    Signed-off-by: Artem Bityutskiy
    Signed-off-by: David Woodhouse

    Artem Bityutskiy
     
  • Be a bit stricter and add few more 'const' qualifiers.

    Signed-off-by: Artem Bityutskiy
    Signed-off-by: David Woodhouse

    Artem Bityutskiy
     
  • 'mtd_device_parse_register()' and 'parse_mtd_partitions()' functions accept a
    an array of character pointers. These functions modify neither the pointers nor
    the characters they point to. The characters are actually names of the MTD
    parsers.

    At the moment, the argument type is 'const char **', which means that only the
    names of the parsers are constant. Let's turn the argument type into 'const
    char * const *', which means that both names and the pointers which point to
    them are constant.

    Signed-off-by: Artem Bityutskiy
    Signed-off-by: David Woodhouse

    Artem Bityutskiy
     
  • Up until now we identified NAND chips by the 'device ID' part of the full chip
    ID array, which is the second full ID array byte. However, the newest flashes
    use the same device ID for chips with identical page and eraseblock sizes, but
    different OOB sizes. And unfortunately, it is not clear if there is a
    "standard" way to fetch the OOB size from chip's full ID array. Here is an
    example:

    Toshiba TC58NVG2S0F: 0x98, 0xdc, 0x90, 0x26, 0x76, 0x15, 0x01, 0x08
    Toshiba TC58NVG3S0F: 0x98, 0xd3, 0x90, 0x26, 0x76, 0x15, 0x02, 0x08

    The first one is a 512MiB NAND chip with 4KiB NAND pages, 256KiB eraseblock
    size and 224 bytes OOB. The second one is a 1GiB NAND chip with the same page
    and eraseblock sizes, but with 232 bytes OOB.

    This means that we have to store full ID in our NAND flashes table in order to
    distinguish between these 2.

    This patch adds the 'id[8]' field to the 'struct nand_flash_dev' structure, and
    it makes it to be a part of anonymous union, where the second member is a
    structure containing the 'mfr_id' and 'dev_id' bytes. The union makes sure that
    'mfr_id' refers the same RAM address as 'id[0]' and 'dev_id' refers the same
    RAM address as 'id[1]'. The only motivation for the union is an assumption that
    'type->dev_id' is more readable than 'type->id[1]'.

    Signed-off-by: Artem Bityutskiy
    Signed-off-by: David Woodhouse

    Artem Bityutskiy
     
  • Introduce helper macros for defining NAND chips. These macros do not really add
    much value in the current code-base. However, we are going to add full ID
    support which adds some more complexity to the table, and helper macros become
    useful for readability.

    Signed-off-by: Artem Bityutskiy
    Signed-off-by: David Woodhouse

    Artem Bityutskiy
     
  • The 'id' is a bit confusing name because NAND IDs are multi-byte. Re-name
    it to 'dev_id' to make it clear that this is the "device ID" part (the second
    byte).

    While on it, clean-up the commentary for 'struct nand_flash_dev'.

    Signed-off-by: Artem Bityutskiy
    Acked-by: Brian Norris
    Signed-off-by: David Woodhouse

    Artem Bityutskiy
     
  • We have this unused macro, let's use it and justify its existence.

    Signed-off-by: Artem Bityutskiy
    Acked-by: Brian Norris
    Signed-off-by: David Woodhouse

    Artem Bityutskiy
     
  • It is unused.

    Signed-off-by: Artem Bityutskiy
    Acked-by: Brian Norris
    Signed-off-by: David Woodhouse

    Artem Bityutskiy
     
  • It is not used anywhere.

    Signed-off-by: Artem Bityutskiy
    Acked-by: Brian Norris
    Signed-off-by: David Woodhouse

    Artem Bityutskiy
     
  • Signed-off-by: Artem Bityutskiy
    Acked-by: Brian Norris
    Signed-off-by: David Woodhouse

    Artem Bityutskiy
     
  • We have only one AG-AND driver and it was not touched since 2005. It looks
    like AG-AND was not really make it to mass-production and can be considered
    a dead technology.

    Along with the AG-AND support, this patch removes the BBT_AUTO_REFRESH feature,
    because the only user of this feature is AG-AND. And even though it is
    implemented as a generic feature, I prefer to remove it because NAND flashes do
    not really need it in this form.

    Signed-off-by: Artem Bityutskiy
    Acked-by: Brian Norris
    Signed-off-by: David Woodhouse

    Artem Bityutskiy
     

14 Mar, 2013

1 commit

  • This partially reverts commit 1696e6bc2ae83734e64e206ac99766ea19e9a14e
    ("mtd: nand: kill NAND_NO_READRDY").

    In that patch I overlooked a few things.

    The original documentation for NAND_NO_READRDY included "True for all
    large page devices, as they do not support autoincrement." I was
    conflating "not support autoincrement" with the NAND_NO_AUTOINCR option,
    which was in fact doing nothing. So, when I dropped NAND_NO_AUTOINCR, I
    concluded that I then could harmlessly drop NAND_NO_READRDY. But of
    course the fact the NAND_NO_AUTOINCR was doing nothing didn't mean
    NAND_NO_READRDY was doing nothing...

    So, NAND_NO_READRDY is re-introduced as NAND_NEED_READRDY and applied
    only to those few remaining small-page NAND which needed it in the first
    place.

    Cc: stable@kernel.org [3.5+]
    Reported-by: Alexander Shiyan
    Tested-by: Alexander Shiyan
    Signed-off-by: Brian Norris
    Signed-off-by: David Woodhouse

    Brian Norris
     

22 Feb, 2013

1 commit

  • Several map-related functions look like a serie of ifs, checking
    widths of map. Those functions do not have any handling for default
    case. Instead of fiddling with uninitialized_var in those functions,
    let's just add a (correct) BUG() to the default case on those maps. This
    will also allow us to catch potential errors in maps setup in future.

    Signed-off-by: Dmitry Eremin-Solenikov
    Signed-off-by: Artem Bityutskiy

    Dmitry Eremin-Solenikov
     

04 Feb, 2013

1 commit

  • Currently cfi_cmdset_0002.c does not support PPB locking of sectors. This
    patch adds support for this locking/unlocking mechanism. It is needed on
    some platforms, since newer U-Boot versions do support this PPB locking
    and protect for example their environment sector(s) this way.

    This PPB locking/unlocking will be enabled for all devices supported by
    cfi_cmdset_0002 reporting 8 in the CFI word 0x49 (Sector Protect/Unprotect
    scheme).

    Please note that PPB locking does support sector-by-sector locking. But
    the whole chip can only be unlocked together. So unlocking one sector
    will automatically unlock all sectors of this device. Because of this
    chip limitation, the PPB unlocking function saves the current locking
    status of all sectors before unlocking the whole device. After unlocking
    the saved locking status is re-configured. This way only the addressed
    sectors will be unlocked.

    To selectively enable this advanced sector protection mechanism, the
    device-tree property "use-advanced-sector-protection" has been created.
    To enable support for this locking this property needs to be present in the
    flash DT node. E.g.:

    nor_flash@0,0 {
    compatible = "amd,s29gl256n", "cfi-flash";
    bank-width = ;
    use-advanced-sector-protection;
    ...

    Tested with Spansion S29GL512S10THI and Micron JS28F512M29EWx flash
    devices.

    Signed-off-by: Stefan Roese
    Tested-by: Holger Brunck
    Signed-off-by: Artem Bityutskiy

    Stefan Roese
     

03 Dec, 2012

1 commit

  • The driver call nand_scan_ident in 8 bit mode, then
    readid or onfi detection are done (and detect bus width).
    The driver should update its bus width before calling nand_scan_tail.

    This work because readid and onfi are read work 8 byte mode.

    Note that nand_scan_ident send command (NAND_CMD_RESET, NAND_CMD_READID, NAND_CMD_PARAM), address and read data
    The ONFI specificication is not very clear for x16 device if high byte of address should be driven to 0,
    but according to [1] it should be ok to not drive it during autodetection.

    [1]
    3.3.2. Target Initialization

    [...]
    The Read ID and Read Parameter Page commands only use the lower 8-bits of the data bus.
    The host shall not issue commands that use a word data width on x16 devices until the host
    determines the device supports a 16-bit data bus width in the parameter page.

    Signed-off-by: Matthieu CASTET
    Signed-off-by: Artem Bityutskiy

    Matthieu CASTET