Message ID | 20201221005318.11866-7-jiaxun.yang@flygoat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Alpine Linux build fix and CI pipeline | expand |
On 21/12/2020 01.53, Jiaxun Yang wrote: > As per POSIX specification of limits.h [1], OS libc may define > PAGE_SIZE in limits.h. > > To prevent collosion of definition, we rename PAGE_SIZE here. > > [1]: https://pubs.opengroup.org/onlinepubs/7908799/xsh/limits.h.html > > Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> > --- > hw/block/nand.c | 40 ++++++++++++++++++++-------------------- > 1 file changed, 20 insertions(+), 20 deletions(-) > > diff --git a/hw/block/nand.c b/hw/block/nand.c > index 1d7a48a2ec..17645667d8 100644 > --- a/hw/block/nand.c > +++ b/hw/block/nand.c > @@ -114,24 +114,24 @@ static void mem_and(uint8_t *dest, const uint8_t *src, size_t n) > # define NAND_IO > > # define PAGE(addr) ((addr) >> ADDR_SHIFT) > -# define PAGE_START(page) (PAGE(page) * (PAGE_SIZE + OOB_SIZE)) > +# define PAGE_START(page) (PAGE(page) * (NAND_PAGE_SIZE + OOB_SIZE)) > # define PAGE_MASK ((1 << ADDR_SHIFT) - 1) > # define OOB_SHIFT (PAGE_SHIFT - 5) > # define OOB_SIZE (1 << OOB_SHIFT) > # define SECTOR(addr) ((addr) >> (9 + ADDR_SHIFT - PAGE_SHIFT)) > # define SECTOR_OFFSET(addr) ((addr) & ((511 >> PAGE_SHIFT) << 8)) > > -# define PAGE_SIZE 256 > +# define NAND_PAGE_SIZE 256 > # define PAGE_SHIFT 8 > # define PAGE_SECTORS 1 > # define ADDR_SHIFT 8 > # include "nand.c" > -# define PAGE_SIZE 512 > +# define NAND_PAGE_SIZE 512 > # define PAGE_SHIFT 9 > # define PAGE_SECTORS 1 > # define ADDR_SHIFT 8 > # include "nand.c" > -# define PAGE_SIZE 2048 > +# define NAND_PAGE_SIZE 2048 > # define PAGE_SHIFT 11 > # define PAGE_SECTORS 4 > # define ADDR_SHIFT 16 > @@ -661,7 +661,7 @@ type_init(nand_register_types) > #else > > /* Program a single page */ > -static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s) > +static void glue(nand_blk_write_, NAND_PAGE_SIZE)(NANDFlashState *s) > { > uint64_t off, page, sector, soff; > uint8_t iobuf[(PAGE_SECTORS + 2) * 0x200]; > @@ -681,11 +681,11 @@ static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s) > return; > } > > - mem_and(iobuf + (soff | off), s->io, MIN(s->iolen, PAGE_SIZE - off)); > - if (off + s->iolen > PAGE_SIZE) { > + mem_and(iobuf + (soff | off), s->io, MIN(s->iolen, NAND_PAGE_SIZE - off)); > + if (off + s->iolen > NAND_PAGE_SIZE) { > page = PAGE(s->addr); > - mem_and(s->storage + (page << OOB_SHIFT), s->io + PAGE_SIZE - off, > - MIN(OOB_SIZE, off + s->iolen - PAGE_SIZE)); > + mem_and(s->storage + (page << OOB_SHIFT), s->io + NAND_PAGE_SIZE - off, > + MIN(OOB_SIZE, off + s->iolen - NAND_PAGE_SIZE)); > } > > if (blk_pwrite(s->blk, sector << BDRV_SECTOR_BITS, iobuf, > @@ -713,7 +713,7 @@ static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s) > } > > /* Erase a single block */ > -static void glue(nand_blk_erase_, PAGE_SIZE)(NANDFlashState *s) > +static void glue(nand_blk_erase_, NAND_PAGE_SIZE)(NANDFlashState *s) > { > uint64_t i, page, addr; > uint8_t iobuf[0x200] = { [0 ... 0x1ff] = 0xff, }; > @@ -725,7 +725,7 @@ static void glue(nand_blk_erase_, PAGE_SIZE)(NANDFlashState *s) > > if (!s->blk) { > memset(s->storage + PAGE_START(addr), > - 0xff, (PAGE_SIZE + OOB_SIZE) << s->erase_shift); > + 0xff, (NAND_PAGE_SIZE + OOB_SIZE) << s->erase_shift); > } else if (s->mem_oob) { > memset(s->storage + (PAGE(addr) << OOB_SHIFT), > 0xff, OOB_SIZE << s->erase_shift); > @@ -751,7 +751,7 @@ static void glue(nand_blk_erase_, PAGE_SIZE)(NANDFlashState *s) > > memset(iobuf, 0xff, 0x200); > i = (addr & ~0x1ff) + 0x200; > - for (addr += ((PAGE_SIZE + OOB_SIZE) << s->erase_shift) - 0x200; > + for (addr += ((NAND_PAGE_SIZE + OOB_SIZE) << s->erase_shift) - 0x200; > i < addr; i += 0x200) { > if (blk_pwrite(s->blk, i, iobuf, BDRV_SECTOR_SIZE, 0) < 0) { > printf("%s: write error in sector %" PRIu64 "\n", > @@ -772,7 +772,7 @@ static void glue(nand_blk_erase_, PAGE_SIZE)(NANDFlashState *s) > } > } > > -static void glue(nand_blk_load_, PAGE_SIZE)(NANDFlashState *s, > +static void glue(nand_blk_load_, NAND_PAGE_SIZE)(NANDFlashState *s, > uint64_t addr, int offset) > { > if (PAGE(addr) >= s->pages) { > @@ -786,7 +786,7 @@ static void glue(nand_blk_load_, PAGE_SIZE)(NANDFlashState *s, > printf("%s: read error in sector %" PRIu64 "\n", > __func__, SECTOR(addr)); > } > - memcpy(s->io + SECTOR_OFFSET(s->addr) + PAGE_SIZE, > + memcpy(s->io + SECTOR_OFFSET(s->addr) + NAND_PAGE_SIZE, > s->storage + (PAGE(s->addr) << OOB_SHIFT), > OOB_SIZE); > s->ioaddr = s->io + SECTOR_OFFSET(s->addr) + offset; > @@ -800,23 +800,23 @@ static void glue(nand_blk_load_, PAGE_SIZE)(NANDFlashState *s, > } > } else { > memcpy(s->io, s->storage + PAGE_START(s->addr) + > - offset, PAGE_SIZE + OOB_SIZE - offset); > + offset, NAND_PAGE_SIZE + OOB_SIZE - offset); > s->ioaddr = s->io; > } > } > > -static void glue(nand_init_, PAGE_SIZE)(NANDFlashState *s) > +static void glue(nand_init_, NAND_PAGE_SIZE)(NANDFlashState *s) > { > s->oob_shift = PAGE_SHIFT - 5; > s->pages = s->size >> PAGE_SHIFT; > s->addr_shift = ADDR_SHIFT; > > - s->blk_erase = glue(nand_blk_erase_, PAGE_SIZE); > - s->blk_write = glue(nand_blk_write_, PAGE_SIZE); > - s->blk_load = glue(nand_blk_load_, PAGE_SIZE); > + s->blk_erase = glue(nand_blk_erase_, NAND_PAGE_SIZE); > + s->blk_write = glue(nand_blk_write_, NAND_PAGE_SIZE); > + s->blk_load = glue(nand_blk_load_, NAND_PAGE_SIZE); > } > > -# undef PAGE_SIZE > +# undef NAND_PAGE_SIZE > # undef PAGE_SHIFT > # undef PAGE_SECTORS > # undef ADDR_SHIFT > Reviewed-by: Thomas Huth <thuth@redhat.com>
diff --git a/hw/block/nand.c b/hw/block/nand.c index 1d7a48a2ec..17645667d8 100644 --- a/hw/block/nand.c +++ b/hw/block/nand.c @@ -114,24 +114,24 @@ static void mem_and(uint8_t *dest, const uint8_t *src, size_t n) # define NAND_IO # define PAGE(addr) ((addr) >> ADDR_SHIFT) -# define PAGE_START(page) (PAGE(page) * (PAGE_SIZE + OOB_SIZE)) +# define PAGE_START(page) (PAGE(page) * (NAND_PAGE_SIZE + OOB_SIZE)) # define PAGE_MASK ((1 << ADDR_SHIFT) - 1) # define OOB_SHIFT (PAGE_SHIFT - 5) # define OOB_SIZE (1 << OOB_SHIFT) # define SECTOR(addr) ((addr) >> (9 + ADDR_SHIFT - PAGE_SHIFT)) # define SECTOR_OFFSET(addr) ((addr) & ((511 >> PAGE_SHIFT) << 8)) -# define PAGE_SIZE 256 +# define NAND_PAGE_SIZE 256 # define PAGE_SHIFT 8 # define PAGE_SECTORS 1 # define ADDR_SHIFT 8 # include "nand.c" -# define PAGE_SIZE 512 +# define NAND_PAGE_SIZE 512 # define PAGE_SHIFT 9 # define PAGE_SECTORS 1 # define ADDR_SHIFT 8 # include "nand.c" -# define PAGE_SIZE 2048 +# define NAND_PAGE_SIZE 2048 # define PAGE_SHIFT 11 # define PAGE_SECTORS 4 # define ADDR_SHIFT 16 @@ -661,7 +661,7 @@ type_init(nand_register_types) #else /* Program a single page */ -static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s) +static void glue(nand_blk_write_, NAND_PAGE_SIZE)(NANDFlashState *s) { uint64_t off, page, sector, soff; uint8_t iobuf[(PAGE_SECTORS + 2) * 0x200]; @@ -681,11 +681,11 @@ static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s) return; } - mem_and(iobuf + (soff | off), s->io, MIN(s->iolen, PAGE_SIZE - off)); - if (off + s->iolen > PAGE_SIZE) { + mem_and(iobuf + (soff | off), s->io, MIN(s->iolen, NAND_PAGE_SIZE - off)); + if (off + s->iolen > NAND_PAGE_SIZE) { page = PAGE(s->addr); - mem_and(s->storage + (page << OOB_SHIFT), s->io + PAGE_SIZE - off, - MIN(OOB_SIZE, off + s->iolen - PAGE_SIZE)); + mem_and(s->storage + (page << OOB_SHIFT), s->io + NAND_PAGE_SIZE - off, + MIN(OOB_SIZE, off + s->iolen - NAND_PAGE_SIZE)); } if (blk_pwrite(s->blk, sector << BDRV_SECTOR_BITS, iobuf, @@ -713,7 +713,7 @@ static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s) } /* Erase a single block */ -static void glue(nand_blk_erase_, PAGE_SIZE)(NANDFlashState *s) +static void glue(nand_blk_erase_, NAND_PAGE_SIZE)(NANDFlashState *s) { uint64_t i, page, addr; uint8_t iobuf[0x200] = { [0 ... 0x1ff] = 0xff, }; @@ -725,7 +725,7 @@ static void glue(nand_blk_erase_, PAGE_SIZE)(NANDFlashState *s) if (!s->blk) { memset(s->storage + PAGE_START(addr), - 0xff, (PAGE_SIZE + OOB_SIZE) << s->erase_shift); + 0xff, (NAND_PAGE_SIZE + OOB_SIZE) << s->erase_shift); } else if (s->mem_oob) { memset(s->storage + (PAGE(addr) << OOB_SHIFT), 0xff, OOB_SIZE << s->erase_shift); @@ -751,7 +751,7 @@ static void glue(nand_blk_erase_, PAGE_SIZE)(NANDFlashState *s) memset(iobuf, 0xff, 0x200); i = (addr & ~0x1ff) + 0x200; - for (addr += ((PAGE_SIZE + OOB_SIZE) << s->erase_shift) - 0x200; + for (addr += ((NAND_PAGE_SIZE + OOB_SIZE) << s->erase_shift) - 0x200; i < addr; i += 0x200) { if (blk_pwrite(s->blk, i, iobuf, BDRV_SECTOR_SIZE, 0) < 0) { printf("%s: write error in sector %" PRIu64 "\n", @@ -772,7 +772,7 @@ static void glue(nand_blk_erase_, PAGE_SIZE)(NANDFlashState *s) } } -static void glue(nand_blk_load_, PAGE_SIZE)(NANDFlashState *s, +static void glue(nand_blk_load_, NAND_PAGE_SIZE)(NANDFlashState *s, uint64_t addr, int offset) { if (PAGE(addr) >= s->pages) { @@ -786,7 +786,7 @@ static void glue(nand_blk_load_, PAGE_SIZE)(NANDFlashState *s, printf("%s: read error in sector %" PRIu64 "\n", __func__, SECTOR(addr)); } - memcpy(s->io + SECTOR_OFFSET(s->addr) + PAGE_SIZE, + memcpy(s->io + SECTOR_OFFSET(s->addr) + NAND_PAGE_SIZE, s->storage + (PAGE(s->addr) << OOB_SHIFT), OOB_SIZE); s->ioaddr = s->io + SECTOR_OFFSET(s->addr) + offset; @@ -800,23 +800,23 @@ static void glue(nand_blk_load_, PAGE_SIZE)(NANDFlashState *s, } } else { memcpy(s->io, s->storage + PAGE_START(s->addr) + - offset, PAGE_SIZE + OOB_SIZE - offset); + offset, NAND_PAGE_SIZE + OOB_SIZE - offset); s->ioaddr = s->io; } } -static void glue(nand_init_, PAGE_SIZE)(NANDFlashState *s) +static void glue(nand_init_, NAND_PAGE_SIZE)(NANDFlashState *s) { s->oob_shift = PAGE_SHIFT - 5; s->pages = s->size >> PAGE_SHIFT; s->addr_shift = ADDR_SHIFT; - s->blk_erase = glue(nand_blk_erase_, PAGE_SIZE); - s->blk_write = glue(nand_blk_write_, PAGE_SIZE); - s->blk_load = glue(nand_blk_load_, PAGE_SIZE); + s->blk_erase = glue(nand_blk_erase_, NAND_PAGE_SIZE); + s->blk_write = glue(nand_blk_write_, NAND_PAGE_SIZE); + s->blk_load = glue(nand_blk_load_, NAND_PAGE_SIZE); } -# undef PAGE_SIZE +# undef NAND_PAGE_SIZE # undef PAGE_SHIFT # undef PAGE_SECTORS # undef ADDR_SHIFT
As per POSIX specification of limits.h [1], OS libc may define PAGE_SIZE in limits.h. To prevent collosion of definition, we rename PAGE_SIZE here. [1]: https://pubs.opengroup.org/onlinepubs/7908799/xsh/limits.h.html Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com> --- hw/block/nand.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-)