summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/cmd_flash.c10
-rw-r--r--common/cmd_ide.c51
-rw-r--r--common/cmd_mem.c8
-rw-r--r--common/cmd_nand.c4
-rw-r--r--common/cmd_nvedit.c3
-rw-r--r--common/cmd_sf.c86
-rw-r--r--common/cmd_ubi.c3
-rw-r--r--common/console.c18
-rw-r--r--common/lcd.c9
-rw-r--r--common/serial.c64
10 files changed, 163 insertions, 93 deletions
diff --git a/common/cmd_flash.c b/common/cmd_flash.c
index 5508d73..6765347 100644
--- a/common/cmd_flash.c
+++ b/common/cmd_flash.c
@@ -455,6 +455,7 @@ int flash_sect_erase (ulong addr_first, ulong addr_last)
int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
+ int rcode = 0;
#ifndef CONFIG_SYS_NO_FLASH
flash_info_t *info;
ulong bank;
@@ -465,24 +466,25 @@ int do_protect (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
u8 dev_type, dev_num, pnum;
#endif
#endif /* CONFIG_SYS_NO_FLASH */
-#if !defined(CONFIG_SYS_NO_FLASH) || defined(CONFIG_HAS_DATAFLASH)
- ulong addr_first, addr_last;
-#endif
#ifdef CONFIG_HAS_DATAFLASH
int status;
#endif
+#if !defined(CONFIG_SYS_NO_FLASH) || defined(CONFIG_HAS_DATAFLASH)
int p;
- int rcode = 0;
+ ulong addr_first, addr_last;
+#endif
if (argc < 3)
return cmd_usage(cmdtp);
+#if !defined(CONFIG_SYS_NO_FLASH) || defined(CONFIG_HAS_DATAFLASH)
if (strcmp(argv[1], "off") == 0)
p = 0;
else if (strcmp(argv[1], "on") == 0)
p = 1;
else
return cmd_usage(cmdtp);
+#endif
#ifdef CONFIG_HAS_DATAFLASH
if ((strcmp(argv[2], "all") != 0) && (strcmp(argv[2], "bank") != 0)) {
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index 2e8c6e0..da5189c 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -985,9 +985,8 @@ input_data(int dev, ulong *sect_buf, int words)
*/
static void ide_ident (block_dev_desc_t *dev_desc)
{
- ulong iobuf[ATA_SECTORWORDS];
unsigned char c;
- hd_driveid_t *iop = (hd_driveid_t *)iobuf;
+ hd_driveid_t iop;
#ifdef CONFIG_ATAPI
int retries = 0;
@@ -1073,11 +1072,11 @@ static void ide_ident (block_dev_desc_t *dev_desc)
return;
#endif
- input_swap_data (device, iobuf, ATA_SECTORWORDS);
+ input_swap_data (device, (ulong *)&iop, ATA_SECTORWORDS);
- ident_cpy ((unsigned char*)dev_desc->revision, iop->fw_rev, sizeof(dev_desc->revision));
- ident_cpy ((unsigned char*)dev_desc->vendor, iop->model, sizeof(dev_desc->vendor));
- ident_cpy ((unsigned char*)dev_desc->product, iop->serial_no, sizeof(dev_desc->product));
+ ident_cpy ((unsigned char*)dev_desc->revision, iop.fw_rev, sizeof(dev_desc->revision));
+ ident_cpy ((unsigned char*)dev_desc->vendor, iop.model, sizeof(dev_desc->vendor));
+ ident_cpy ((unsigned char*)dev_desc->product, iop.serial_no, sizeof(dev_desc->product));
#ifdef __LITTLE_ENDIAN
/*
* firmware revision, model, and serial number have Big Endian Byte
@@ -1092,14 +1091,14 @@ static void ide_ident (block_dev_desc_t *dev_desc)
strswab (dev_desc->product);
#endif /* __LITTLE_ENDIAN */
- if ((iop->config & 0x0080)==0x0080)
+ if ((iop.config & 0x0080) == 0x0080)
dev_desc->removable = 1;
else
dev_desc->removable = 0;
#ifdef CONFIG_TUNE_PIO
/* Mode 0 - 2 only, are directly determined by word 51. */
- pio_mode = iop->tPIO;
+ pio_mode = iop.tPIO;
if (pio_mode > 2) {
printf("WARNING: Invalid PIO (word 51 = %d).\n", pio_mode);
pio_mode = 0; /* Force it to dead slow, and hope for the best... */
@@ -1109,18 +1108,18 @@ static void ide_ident (block_dev_desc_t *dev_desc)
* shall set bit 1 of word 53 to one and support the fields contained
* in words 64 through 70.
*/
- if (iop->field_valid & 0x02) {
+ if (iop.field_valid & 0x02) {
/* Mode 3 and above are possible. Check in order from slow
* to fast, so we wind up with the highest mode allowed.
*/
- if (iop->eide_pio_modes & 0x01)
+ if (iop.eide_pio_modes & 0x01)
pio_mode = 3;
- if (iop->eide_pio_modes & 0x02)
+ if (iop.eide_pio_modes & 0x02)
pio_mode = 4;
- if (ata_id_is_cfa((u16 *)iop)) {
- if ((iop->cf_advanced_caps & 0x07) == 0x01)
+ if (ata_id_is_cfa((u16 *)&iop)) {
+ if ((iop.cf_advanced_caps & 0x07) == 0x01)
pio_mode = 5;
- if ((iop->cf_advanced_caps & 0x07) == 0x02)
+ if ((iop.cf_advanced_caps & 0x07) == 0x02)
pio_mode = 6;
}
}
@@ -1133,19 +1132,19 @@ static void ide_ident (block_dev_desc_t *dev_desc)
/*
* Drive PIO mode autoselection
*/
- mode = iop->tPIO;
+ mode = iop.tPIO;
printf ("tPIO = 0x%02x = %d\n",mode, mode);
if (mode > 2) { /* 2 is maximum allowed tPIO value */
mode = 2;
debug ("Override tPIO -> 2\n");
}
- if (iop->field_valid & 2) { /* drive implements ATA2? */
+ if (iop.field_valid & 2) { /* drive implements ATA2? */
debug ("Drive implements ATA2\n");
- if (iop->capability & 8) { /* drive supports use_iordy? */
- cycle_time = iop->eide_pio_iordy;
+ if (iop.capability & 8) { /* drive supports use_iordy? */
+ cycle_time = iop.eide_pio_iordy;
} else {
- cycle_time = iop->eide_pio;
+ cycle_time = iop.eide_pio;
}
debug ("cycle time = %d\n", cycle_time);
mode = 4;
@@ -1166,7 +1165,7 @@ static void ide_ident (block_dev_desc_t *dev_desc)
#ifdef __BIG_ENDIAN
/* swap shorts */
- dev_desc->lba = (iop->lba_capacity << 16) | (iop->lba_capacity >> 16);
+ dev_desc->lba = (iop.lba_capacity << 16) | (iop.lba_capacity >> 16);
#else /* ! __BIG_ENDIAN */
/*
* do not swap shorts on little endian
@@ -1174,16 +1173,16 @@ static void ide_ident (block_dev_desc_t *dev_desc)
* See CF+ and CompactFlash Specification Revision 2.0:
* 6.2.1.6: Identfy Drive, Table 39, Word Address 57-58 for details.
*/
- dev_desc->lba = iop->lba_capacity;
+ dev_desc->lba = iop.lba_capacity;
#endif /* __BIG_ENDIAN */
#ifdef CONFIG_LBA48
- if (iop->command_set_2 & 0x0400) { /* LBA 48 support */
+ if (iop.command_set_2 & 0x0400) { /* LBA 48 support */
dev_desc->lba48 = 1;
- dev_desc->lba = (unsigned long long)iop->lba48_capacity[0] |
- ((unsigned long long)iop->lba48_capacity[1] << 16) |
- ((unsigned long long)iop->lba48_capacity[2] << 32) |
- ((unsigned long long)iop->lba48_capacity[3] << 48);
+ dev_desc->lba = (unsigned long long)iop.lba48_capacity[0] |
+ ((unsigned long long)iop.lba48_capacity[1] << 16) |
+ ((unsigned long long)iop.lba48_capacity[2] << 32) |
+ ((unsigned long long)iop.lba48_capacity[3] << 48);
} else {
dev_desc->lba48 = 0;
}
diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index 4daa1b3..e84cc4e 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -471,7 +471,7 @@ int do_mem_base (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
- ulong addr, length, i, junk;
+ ulong addr, length, i;
int size;
volatile uint *longp;
volatile ushort *shortp;
@@ -518,7 +518,7 @@ int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
longp = (uint *)addr;
i = length;
while (i-- > 0)
- junk = *longp++;
+ *longp++;
}
}
if (size == 2) {
@@ -526,14 +526,14 @@ int do_mem_loop (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
shortp = (ushort *)addr;
i = length;
while (i-- > 0)
- junk = *shortp++;
+ *shortp++;
}
}
for (;;) {
cp = (u_char *)addr;
i = length;
while (i-- > 0)
- junk = *cp++;
+ *cp++;
}
}
diff --git a/common/cmd_nand.c b/common/cmd_nand.c
index 66e06a5..6edca76 100644
--- a/common/cmd_nand.c
+++ b/common/cmd_nand.c
@@ -466,8 +466,6 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
int clean = argc > 2 && !strcmp("clean", argv[2]);
int o = clean ? 3 : 2;
int scrub = !strncmp(cmd, "scrub", 5);
- int part = 0;
- int chip = 0;
int spread = 0;
int args = 2;
@@ -475,10 +473,8 @@ int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
if (!strcmp(&cmd[5], ".spread")) {
spread = 1;
} else if (!strcmp(&cmd[5], ".part")) {
- part = 1;
args = 1;
} else if (!strcmp(&cmd[5], ".chip")) {
- chip = 1;
args = 0;
} else {
goto usage;
diff --git a/common/cmd_nvedit.c b/common/cmd_nvedit.c
index e8b116d..101bc49 100644
--- a/common/cmd_nvedit.c
+++ b/common/cmd_nvedit.c
@@ -460,7 +460,6 @@ int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
char buffer[CONFIG_SYS_CBSIZE];
char *init_val;
- int len;
if (argc < 2)
return cmd_usage(cmdtp);
@@ -468,7 +467,7 @@ int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
/* Set read buffer to initial value or empty sting */
init_val = getenv(argv[1]);
if (init_val)
- len = sprintf(buffer, "%s", init_val);
+ sprintf(buffer, "%s", init_val);
else
buffer[0] = '\0';
diff --git a/common/cmd_sf.c b/common/cmd_sf.c
index 27d6e39..c8c547a 100644
--- a/common/cmd_sf.c
+++ b/common/cmd_sf.c
@@ -6,6 +6,7 @@
*/
#include <common.h>
+#include <malloc.h>
#include <spi_flash.h>
#include <asm/io.h>
@@ -109,6 +110,80 @@ static int do_spi_flash_probe(int argc, char * const argv[])
return 0;
}
+/**
+ * Write a block of data to SPI flash, first checking if it is different from
+ * what is already there.
+ *
+ * If the data being written is the same, then *skipped is incremented by len.
+ *
+ * @param flash flash context pointer
+ * @param offset flash offset to write
+ * @param len number of bytes to write
+ * @param buf buffer to write from
+ * @param cmp_buf read buffer to use to compare data
+ * @param skipped Count of skipped data (incremented by this function)
+ * @return NULL if OK, else a string containing the stage which failed
+ */
+static const char *spi_flash_update_block(struct spi_flash *flash, u32 offset,
+ size_t len, const char *buf, char *cmp_buf, size_t *skipped)
+{
+ debug("offset=%#x, sector_size=%#x, len=%#x\n",
+ offset, flash->sector_size, len);
+ if (spi_flash_read(flash, offset, len, cmp_buf))
+ return "read";
+ if (memcmp(cmp_buf, buf, len) == 0) {
+ debug("Skip region %x size %x: no change\n",
+ offset, len);
+ *skipped += len;
+ return NULL;
+ }
+ if (spi_flash_erase(flash, offset, len))
+ return "erase";
+ if (spi_flash_write(flash, offset, len, buf))
+ return "write";
+ return NULL;
+}
+
+/**
+ * Update an area of SPI flash by erasing and writing any blocks which need
+ * to change. Existing blocks with the correct data are left unchanged.
+ *
+ * @param flash flash context pointer
+ * @param offset flash offset to write
+ * @param len number of bytes to write
+ * @param buf buffer to write from
+ * @return 0 if ok, 1 on error
+ */
+static int spi_flash_update(struct spi_flash *flash, u32 offset,
+ size_t len, const char *buf)
+{
+ const char *err_oper = NULL;
+ char *cmp_buf;
+ const char *end = buf + len;
+ size_t todo; /* number of bytes to do in this pass */
+ size_t skipped; /* statistics */
+
+ cmp_buf = malloc(flash->sector_size);
+ if (cmp_buf) {
+ for (skipped = 0; buf < end && !err_oper;
+ buf += todo, offset += todo) {
+ todo = min(end - buf, flash->sector_size);
+ err_oper = spi_flash_update_block(flash, offset, todo,
+ buf, cmp_buf, &skipped);
+ }
+ } else {
+ err_oper = "malloc";
+ }
+ free(cmp_buf);
+ if (err_oper) {
+ printf("SPI flash failed in %s step\n", err_oper);
+ return 1;
+ }
+ printf("%zu bytes written, %zu bytes skipped\n", len - skipped,
+ skipped);
+ return 0;
+}
+
static int do_spi_flash_read_write(int argc, char * const argv[])
{
unsigned long addr;
@@ -137,7 +212,9 @@ static int do_spi_flash_read_write(int argc, char * const argv[])
return 1;
}
- if (strcmp(argv[0], "read") == 0)
+ if (strcmp(argv[0], "update") == 0)
+ ret = spi_flash_update(flash, offset, len, buf);
+ else if (strcmp(argv[0], "read") == 0)
ret = spi_flash_read(flash, offset, len, buf);
else
ret = spi_flash_write(flash, offset, len, buf);
@@ -203,7 +280,8 @@ static int do_spi_flash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
return 1;
}
- if (strcmp(cmd, "read") == 0 || strcmp(cmd, "write") == 0)
+ if (strcmp(cmd, "read") == 0 || strcmp(cmd, "write") == 0 ||
+ strcmp(cmd, "update") == 0)
ret = do_spi_flash_read_write(argc, argv);
else if (strcmp(cmd, "erase") == 0)
ret = do_spi_flash_erase(argc, argv);
@@ -228,5 +306,7 @@ U_BOOT_CMD(
"sf write addr offset len - write `len' bytes from memory\n"
" at `addr' to flash at `offset'\n"
"sf erase offset [+]len - erase `len' bytes from `offset'\n"
- " `+len' round up `len' to block size"
+ " `+len' round up `len' to block size\n"
+ "sf update addr offset len - erase and write `len' bytes from memory\n"
+ " at `addr' to flash at `offset'"
);
diff --git a/common/cmd_ubi.c b/common/cmd_ubi.c
index 629758f..8c1bc23 100644
--- a/common/cmd_ubi.c
+++ b/common/cmd_ubi.c
@@ -316,7 +316,6 @@ static int ubi_volume_write(char *volume, void *buf, size_t size)
static int ubi_volume_read(char *volume, char *buf, size_t size)
{
int err, lnum, off, len, tbuf_size;
- size_t count_save = size;
void *tbuf;
unsigned long long tmp;
struct ubi_volume *vol;
@@ -347,7 +346,7 @@ static int ubi_volume_read(char *volume, char *buf, size_t size)
if (vol->corrupted)
printf("read from corrupted volume %d", vol->vol_id);
if (offp + size > vol->used_bytes)
- count_save = size = vol->used_bytes - offp;
+ size = vol->used_bytes - offp;
tbuf_size = vol->usable_leb_size;
if (size < tbuf_size)
diff --git a/common/console.c b/common/console.c
index 8c650e0..b23d933 100644
--- a/common/console.c
+++ b/common/console.c
@@ -298,6 +298,9 @@ int getc(void)
return 0;
#endif
+ if (!gd->have_console)
+ return 0;
+
if (gd->flags & GD_FLG_DEVINIT) {
/* Get from the standard input */
return fgetc(stdin);
@@ -314,6 +317,9 @@ int tstc(void)
return 0;
#endif
+ if (!gd->have_console)
+ return 0;
+
if (gd->flags & GD_FLG_DEVINIT) {
/* Test the standard input */
return ftstc(stdin);
@@ -335,6 +341,9 @@ void putc(const char c)
return;
#endif
+ if (!gd->have_console)
+ return;
+
if (gd->flags & GD_FLG_DEVINIT) {
/* Send to the standard output */
fputc(stdout, c);
@@ -356,6 +365,9 @@ void puts(const char *s)
return;
#endif
+ if (!gd->have_console)
+ return;
+
if (gd->flags & GD_FLG_DEVINIT) {
/* Send to the standard output */
fputs(stdout, s);
@@ -371,6 +383,9 @@ int printf(const char *fmt, ...)
uint i;
char printbuffer[CONFIG_SYS_PBSIZE];
+ if (!gd->have_console)
+ return 0;
+
va_start(args, fmt);
/* For this to work, printbuffer must be larger than
@@ -389,6 +404,9 @@ int vprintf(const char *fmt, va_list args)
uint i;
char printbuffer[CONFIG_SYS_PBSIZE];
+ if (!gd->have_console)
+ return 0;
+
/* For this to work, printbuffer must be larger than
* anything we ever want to print.
*/
diff --git a/common/lcd.c b/common/lcd.c
index 0555ab4..d9cb8ca 100644
--- a/common/lcd.c
+++ b/common/lcd.c
@@ -211,10 +211,13 @@ void lcd_printf(const char *fmt, ...)
static void lcd_drawchars (ushort x, ushort y, uchar *str, int count)
{
uchar *dest;
- ushort off, row;
+ ushort row;
+
+#if LCD_BPP == LCD_MONOCHROME
+ ushort off = x * (1 << LCD_BPP) % 8;
+#endif
dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
- off = x * (1 << LCD_BPP) % 8;
for (row=0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
uchar *s = str;
@@ -614,7 +617,6 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
unsigned long width, height, byte_width;
unsigned long pwidth = panel_info.vl_col;
unsigned colors, bpix, bmp_bpix;
- unsigned long compression;
#if defined CONFIG_PXA250 || defined CONFIG_PXA27X || defined CONFIG_CPU_MONAHANS
struct pxafb_info *fbi = &panel_info.pxa;
#elif defined(CONFIG_MPC823)
@@ -632,7 +634,6 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
height = le32_to_cpu (bmp->header.height);
bmp_bpix = le16_to_cpu(bmp->header.bit_count);
colors = 1 << bmp_bpix;
- compression = le32_to_cpu (bmp->header.compression);
bpix = NBITS(panel_info.vl_bpix);
diff --git a/common/serial.c b/common/serial.c
index 995d268..7bfc861 100644
--- a/common/serial.c
+++ b/common/serial.c
@@ -158,73 +158,49 @@ void serial_reinit_all (void)
}
}
-int serial_init (void)
+static struct serial_device *get_current(void)
{
- if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
- struct serial_device *dev = default_serial_console ();
+ struct serial_device *dev;
- return dev->init ();
- }
+ if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
+ dev = default_serial_console();
+
+ /* We must have a console device */
+ if (!dev)
+ panic("Cannot find console");
+ } else
+ dev = serial_current;
+ return dev;
+}
- return serial_current->init ();
+int serial_init(void)
+{
+ return get_current()->init();
}
void serial_setbrg (void)
{
- if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
- struct serial_device *dev = default_serial_console ();
-
- dev->setbrg ();
- return;
- }
-
- serial_current->setbrg ();
+ get_current()->setbrg();
}
int serial_getc (void)
{
- if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
- struct serial_device *dev = default_serial_console ();
-
- return dev->getc ();
- }
-
- return serial_current->getc ();
+ return get_current()->getc();
}
int serial_tstc (void)
{
- if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
- struct serial_device *dev = default_serial_console ();
-
- return dev->tstc ();
- }
-
- return serial_current->tstc ();
+ return get_current()->tstc();
}
void serial_putc (const char c)
{
- if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
- struct serial_device *dev = default_serial_console ();
-
- dev->putc (c);
- return;
- }
-
- serial_current->putc (c);
+ get_current()->putc(c);
}
void serial_puts (const char *s)
{
- if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
- struct serial_device *dev = default_serial_console ();
-
- dev->puts (s);
- return;
- }
-
- serial_current->puts (s);
+ get_current()->puts(s);
}
#if CONFIG_POST & CONFIG_SYS_POST_UART