Skip to content

Commit

Permalink
mtd: nand: reinstate raw NAND IS_ENABLED(CONFIG_MTD_WRITE) checks
Browse files Browse the repository at this point in the history
Some barebox configurations like OMAP MLO require no MTD write support
to chainload the bigger second stage barebox. As these configurations
are often size limited by On-Chip SRAM, drivers are expected to guard
write-related code behind CONFIG_MTD_WRITE. This got lost with the
recent NAND sync leading to multiple kilobytes in increased code size.

Reinstate the IS_ENABLED(CONFIG_MTD_WRITE) checks to counteract this
somewhat. There's likely more opportunity to slim down nand_base as we
are still above the original size, but this here is the lowest hanging
fruit.

Fixes: 78c57f8 ("mtd: nand: update to Linux-6.9-rc2")
Signed-off-by: Ahmad Fatoum <[email protected]>
Link: https://lore.barebox.org/[email protected]
Signed-off-by: Sascha Hauer <[email protected]>
  • Loading branch information
a3f authored and saschahauer committed May 29, 2024
1 parent 2375d98 commit 55cf43c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions drivers/mtd/nand/raw/nand_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -3738,6 +3738,9 @@ int nand_write_oob_std(struct nand_chip *chip, int page)
{
struct mtd_info *mtd = nand_to_mtd(chip);

if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

return nand_prog_page_op(chip, page, mtd->writesize, chip->oob_poi,
mtd->oobsize);
}
Expand All @@ -3757,6 +3760,9 @@ static int nand_write_oob_syndrome(struct nand_chip *chip, int page)
int ret, i, len, pos, sndcmd = 0, steps = chip->ecc.steps;
const uint8_t *bufpoi = chip->oob_poi;

if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

/*
* data-ecc-data-ecc ... ecc-oob
* or
Expand Down Expand Up @@ -3959,6 +3965,9 @@ int nand_write_page_raw(struct nand_chip *chip, const uint8_t *buf,
struct mtd_info *mtd = nand_to_mtd(chip);
int ret;

if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

ret = nand_prog_page_begin_op(chip, page, 0, buf, mtd->writesize);
if (ret)
return ret;
Expand Down Expand Up @@ -3997,6 +4006,9 @@ int nand_monolithic_write_page_raw(struct nand_chip *chip, const u8 *buf,
unsigned int size = mtd->writesize;
u8 *write_buf = (u8 *)buf;

if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

if (oob_required) {
size += mtd->oobsize;

Expand Down Expand Up @@ -4029,6 +4041,9 @@ static int nand_write_page_raw_syndrome(struct nand_chip *chip,
uint8_t *oob = chip->oob_poi;
int steps, size, ret;

if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

ret = nand_prog_page_begin_op(chip, page, 0, NULL, 0);
if (ret)
return ret;
Expand Down Expand Up @@ -4091,6 +4106,9 @@ static int nand_write_page_swecc(struct nand_chip *chip, const uint8_t *buf,
uint8_t *ecc_calc = chip->ecc.calc_buf;
const uint8_t *p = buf;

if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

/* Software ECC calculation */
for (i = 0; eccsteps; eccsteps--, i += eccbytes, p += eccsize)
chip->ecc.calculate(chip, p, &ecc_calc[i]);
Expand Down Expand Up @@ -4120,6 +4138,9 @@ static int nand_write_page_hwecc(struct nand_chip *chip, const uint8_t *buf,
uint8_t *ecc_calc = chip->ecc.calc_buf;
const uint8_t *p = buf;

if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

ret = nand_prog_page_begin_op(chip, page, 0, NULL, 0);
if (ret)
return ret;
Expand Down Expand Up @@ -4171,6 +4192,9 @@ static int nand_write_subpage_hwecc(struct nand_chip *chip, uint32_t offset,
int oob_bytes = mtd->oobsize / ecc_steps;
int step, ret;

if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

ret = nand_prog_page_begin_op(chip, page, 0, NULL, 0);
if (ret)
return ret;
Expand Down Expand Up @@ -4238,6 +4262,9 @@ static int nand_write_page_syndrome(struct nand_chip *chip, const uint8_t *buf,
uint8_t *oob = chip->oob_poi;
int ret;

if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

ret = nand_prog_page_begin_op(chip, page, 0, NULL, 0);
if (ret)
return ret;
Expand Down Expand Up @@ -4304,6 +4331,9 @@ static int nand_write_page(struct nand_chip *chip, uint32_t offset,
struct mtd_info *mtd = nand_to_mtd(chip);
int status, subpage;

if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

if (!(chip->options & NAND_NO_SUBPAGE_WRITE) &&
chip->ecc.write_subpage)
subpage = offset || (data_len < mtd->writesize);
Expand Down Expand Up @@ -4350,6 +4380,9 @@ static int nand_do_write_ops(struct nand_chip *chip, loff_t to,
int ret;
int oob_required = oob ? 1 : 0;

if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

ops->retlen = 0;
if (!writelen)
return 0;
Expand Down Expand Up @@ -4467,6 +4500,9 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to,
struct nand_chip *chip = mtd_to_nand(mtd);
int ret = 0;

if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

ops->retlen = 0;

nand_get_device(chip);
Expand Down Expand Up @@ -4500,6 +4536,9 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to,
*/
static int nand_erase(struct mtd_info *mtd, struct erase_info *instr)
{
if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

return nand_erase_nand(mtd_to_nand(mtd), instr, 0);
}

Expand All @@ -4518,6 +4557,9 @@ int nand_erase_nand(struct nand_chip *chip, struct erase_info *instr,
int page, pages_per_block, ret, chipnr;
loff_t len;

if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

pr_debug("%s: start = 0x%012llx, len = %llu\n",
__func__, (unsigned long long)instr->addr,
(unsigned long long)instr->len);
Expand Down Expand Up @@ -4653,6 +4695,9 @@ static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs)
{
int ret;

if (!IS_ENABLED(CONFIG_MTD_WRITE))
return -ENOTSUPP;

ret = nand_block_isbad(mtd, ofs);
if (ret) {
/* If it was bad already, return success and do nothing */
Expand Down

0 comments on commit 55cf43c

Please sign in to comment.