[coreboot] [PATCH] flashrom: External flasher support
Joseph Smith
joe at settoplinux.org
Fri May 8 03:34:55 CEST 2009
On Fri, 08 May 2009 02:57:27 +0200, Carl-Daniel Hailfinger
<c-d.hailfinger.devel.2006 at gmx.net> wrote:
> To prepare flashrom for Paraflasher (or other external flasher) support,
> each chip read/write access is either handled as memory mapped access or
> external flasher cycle.
>
> External flashers can set the flasher variable to their own ID/number
> during startup and handle accesses in the switch statement inside
> chip_{read,write}[bwl].
>
> Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>
>
Very cool Carl-Daniel!
So all we would have to do is add "case FLASHER_PARAFLASHER" and it's
external r/w to each one of the swithes and we are good to go?
By the way, sorry to be slacking on the Paraflasher project lately, I've
been a little busy lately...
> Index: flashrom-external_infrastructure/flash.h
> ===================================================================
> --- flashrom-external_infrastructure/flash.h (Revision 471)
> +++ flashrom-external_infrastructure/flash.h (Arbeitskopie)
> @@ -76,36 +76,6 @@
> #endif
> #endif
>
> -static inline void chip_writeb(uint8_t b, volatile void *addr)
> -{
> - *(volatile uint8_t *) addr = b;
> -}
> -
> -static inline void chip_writew(uint16_t b, volatile void *addr)
> -{
> - *(volatile uint16_t *) addr = b;
> -}
> -
> -static inline void chip_writel(uint32_t b, volatile void *addr)
> -{
> - *(volatile uint32_t *) addr = b;
> -}
> -
> -static inline uint8_t chip_readb(const volatile void *addr)
> -{
> - return *(volatile uint8_t *) addr;
> -}
> -
> -static inline uint16_t chip_readw(const volatile void *addr)
> -{
> - return *(volatile uint16_t *) addr;
> -}
> -
> -static inline uint32_t chip_readl(const volatile void *addr)
> -{
> - return *(volatile uint32_t *) addr;
> -}
> -
> #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
>
> struct flashchip {
> @@ -550,6 +520,15 @@
> int coreboot_init(void);
> extern char *lb_part, *lb_vendor;
>
> +/* external.c */
> +void chip_writeb(uint8_t b, volatile void *addr);
> +void chip_writew(uint16_t b, volatile void *addr);
> +void chip_writel(uint32_t b, volatile void *addr);
> +uint8_t chip_readb(const volatile void *addr);
> +uint16_t chip_readw(const volatile void *addr);
> +uint32_t chip_readl(const volatile void *addr);
> +int read_memmapped(struct flashchip *flash, uint8_t *buf);
> +
> /* spi.c */
> int probe_spi_rdid(struct flashchip *flash);
> int probe_spi_rdid4(struct flashchip *flash);
> Index: flashrom-external_infrastructure/Makefile
> ===================================================================
> --- flashrom-external_infrastructure/Makefile (Revision 471)
> +++ flashrom-external_infrastructure/Makefile (Arbeitskopie)
> @@ -34,7 +34,7 @@
> w49f002u.o 82802ab.o pm49fl00x.o sst49lf040.o en29f002a.o \
> sst49lfxxxc.o sst_fwhub.o layout.o cbtable.o flashchips.o physmap.o \
> flashrom.o w39v080fa.o sharplhf00l04.o w29ee011.o spi.o it87spi.o \
> - ichspi.o w39v040c.o sb600spi.o wbsio_spi.o m29f002.o
> + ichspi.o w39v040c.o sb600spi.o wbsio_spi.o m29f002.o external.o
>
> all: pciutils dep $(PROGRAM)
>
> Index: flashrom-external_infrastructure/external.c
> ===================================================================
> --- flashrom-external_infrastructure/external.c (Revision 0)
> +++ flashrom-external_infrastructure/external.c (Revision 0)
> @@ -0,0 +1,111 @@
> +/*
> + * This file is part of the flashrom project.
> + *
> + * Copyright (C) 2009 Carl-Daniel Hailfinger
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
> USA
> + */
> +
> +#include <stdint.h>
> +#include "flash.h"
> +
> +int flasher = 0;
> +#define FLASHER_INTERNAL 0
> +#define FLASHER_PARAFLASHER 1
> +
> +#define POISON_BYTE 0x5a
> +
> +void chip_writeb(uint8_t b, volatile void *addr)
> +{
> + switch (flasher) {
> + case FLASHER_INTERNAL:
> + *(volatile uint8_t *) addr = b;
> + break;
> + default:
> + fprintf(stderr, "ERROR: Unsupported flasher hardware!\n");
> + }
> +}
> +
> +void chip_writew(uint16_t b, volatile void *addr)
> +{
> + switch (flasher) {
> + case FLASHER_INTERNAL:
> + *(volatile uint16_t *) addr = b;
> + break;
> + default:
> + fprintf(stderr, "ERROR: Unsupported flasher hardware!\n");
> + }
> +}
> +
> +void chip_writel(uint32_t b, volatile void *addr)
> +{
> + switch (flasher) {
> + case FLASHER_INTERNAL:
> + *(volatile uint32_t *) addr = b;
> + break;
> + default:
> + fprintf(stderr, "ERROR: Unsupported flasher hardware!\n");
> + }
> +}
> +
> +uint8_t chip_readb(const volatile void *addr)
> +{
> + switch (flasher) {
> + case FLASHER_INTERNAL:
> + return *(volatile uint8_t *) addr;
> + break;
> + default:
> + fprintf(stderr, "ERROR: Unsupported flasher hardware!\n");
> + return POISON_BYTE;
> + }
> +}
> +
> +uint16_t chip_readw(const volatile void *addr)
> +{
> + switch (flasher) {
> + case FLASHER_INTERNAL:
> + return *(volatile uint16_t *) addr;
> + break;
> + default:
> + fprintf(stderr, "ERROR: Unsupported flasher hardware!\n");
> + return (POISON_BYTE << 8) | POISON_BYTE;
> + }
> +}
> +
> +uint32_t chip_readl(const volatile void *addr)
> +{
> + switch (flasher) {
> + case FLASHER_INTERNAL:
> + return *(volatile uint32_t *) addr;
> + break;
> + default:
> + fprintf(stderr, "ERROR: Unsupported flasher hardware!\n");
> + return (POISON_BYTE << 24) | (POISON_BYTE << 16) |
> + (POISON_BYTE << 8) | POISON_BYTE;
> + }
> +}
> +
> +int read_memmapped(struct flashchip *flash, uint8_t *buf)
> +{
> + int i;
> +
> + /* We could do a memcpy as optimization if the flash is onboard */
> + //memcpy(buf, (const char *)flash->virtual_memory, flash->total_size *
> 1024);
> + for (i = 0; i < flash->total_size * 1024; i++)
> + buf[i] = chip_readb(flash->virtual_memory + i);
> +
> + return 0;
> +}
> +
>
>
> --
> http://www.hailfinger.org/
--
Thanks,
Joseph Smith
Set-Top-Linux
www.settoplinux.org
More information about the coreboot
mailing list