Update of /cvsroot/blob/blob/src/blob
In directory sc8-pr-cvs1:/tmp/cvs-serv14258
Modified Files:
flash-commands.c
Log Message:
Use the partition table information for start and length when flashing
a parttion.
Moved Flash command here.
Index: flash-commands.c
===================================================================
RCS file: /cvsroot/blob/blob/src/blob/flash-commands.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- flash-commands.c 24 Jan 2003 09:39:20 -0000 1.4
+++ flash-commands.c 28 Jan 2003 03:32:43 -0000 1.5
@@ -39,39 +39,93 @@
#include <blob/util.h>
#include <blob/serial.h>
#include <blob/flash.h>
+#include <blob/partition.h>
+#include <blob/main.h>
#include <blob/command.h>
-static int parse_partition(char *s, u32 **addr, u32 *length)
+int parse_partition(char *s, u32 **addr, u32 *length)
{
- /* this will eventually be replaced by some functionality
- in the partition manager */
+ const blob_partition_t *p = pt_find_by_name(s);
+
+ if (p == 0)
+ return -EINVAL;
- if(strncmp(s, "blob", 5) == 0) {
- *addr = (u32 *)BLOB_FLASH_BASE;
- *length = BLOB_FLASH_LEN;
-#ifdef PARAM_FLASH_BASE
- } else if(strncmp(s, "param", 6) == 0) {
- *addr = (u32 *)PARAM_FLASH_BASE;
- *length = PARAM_FLASH_LEN;
-#endif
-#ifdef KERNEL_FLASH_BASE
- } else if(strncmp(s, "kernel", 7) == 0) {
- *addr = (u32 *)KERNEL_FLASH_BASE;
- *length = KERNEL_FLASH_LEN;
-#endif
-#ifdef RAMDISK_FLASH_BASE
- } else if(strncmp(s, "ramdisk", 8) == 0) {
- *addr = (u32 *)RAMDISK_FLASH_BASE;
- *length = RAMDISK_FLASH_LEN;
-#endif
+ *addr = (u32 *) pt_flash_start(p);
+ *length = p->size;
+
+ return 0;
+}
+
+
+
+static int Flash(int argc, char *argv[])
+{
+ int rv;
+ u32 *src;
+ u32 *dst;
+ u32 numBytes = 0;
+ u32 maxSize = 0;
+ u32 nwords;
+ block_source_t type = fromFlash;
+
+ if(argc < 2)
+ return -ENOPARAMS;
+
+ rv = parse_partition(argv[1], &dst, &maxSize);
+ if (rv < 0) {
+ printerror(rv, argv[1]);
+ return 0;
+ }
+
+ if(strncmp(argv[1], "blob", 5) == 0) {
+ src = (u32 *)BLOB_RAM_BASE;
+ numBytes = blob_status.blobSize;
+ type = blob_status.blobType;
+ } else if(strncmp(argv[1], "param", 6) == 0) {
+ src = (u32 *)PARAM_RAM_BASE;
+ numBytes = blob_status.paramSize;
+ type = blob_status.paramType;
+ } else if(strncmp(argv[1], "kernel", 7) == 0) {
+ src = (u32 *)KERNEL_RAM_BASE;
+ numBytes = blob_status.kernelSize;
+ type = blob_status.kernelType;
+ } else if(strncmp(argv[1], "ramdisk", 8) == 0) {
+ src = (u32 *)RAMDISK_RAM_BASE;
+ numBytes = blob_status.ramdiskSize;
+ type = blob_status.ramdiskType;
} else {
+ printerror(EINVAL, argv[1]);
+ return 0;
+ }
+
+ if(type == fromFlash) {
+ printerrprefix();
+ printf("%s not downloaded\n", argv[1]);
return -EINVAL;
}
+ if(numBytes > maxSize) {
+ printerrprefix();
+ printf("image too large for flash: 0x%08x > 0x%08x\n",
+ (unsigned int)numBytes, (unsigned int)maxSize);
+
+ return -ETOOLONG;
+ }
+
+ nwords = (numBytes + sizeof(u32) - 1) / sizeof(u32);
+
+ printf("Saving %s to flash\n", argv[1]);
+
+ flash_write_region(dst, src, nwords);
+
return 0;
}
+static char flashhelp[] = "flash {blob|param|kernel|ramdisk}\n"
+"Write <argument> image to flash\n";
+
+__commandlist(Flash, "flash", flashhelp);
@@ -103,8 +157,8 @@
return 0;
}
-static char lockhelp[] = "lock {blob|param|kernel|ramdisk}\n"
-"Lock <argument> region of flash\n";
+static char lockhelp[] = "lock partition\n"
+"Lock <partition> region of flash\n";
__commandlist(Lock, "lock", lockhelp);
@@ -139,8 +193,8 @@
return 0;
}
-static char unlockhelp[] = "unlock {blob|param|kernel|ramdisk}\n"
-"Unlock <argument> region of flash\n";
+static char unlockhelp[] = "unlock partition\n"
+"Unlock <partition> region of flash\n";
__commandlist(Unlock, "unlock", unlockhelp);
@@ -174,7 +228,7 @@
return 0;
}
-static char erasehelp[] = "erase {blob|param|kernel|ramdisk}\n"
-"Erase <argument> region of flash\n";
+static char erasehelp[] = "erase partition\n"
+"Erase <partition> region of flash\n";
__commandlist(Erase, "erase", erasehelp);
|