This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RedBoot 'ifdisk' command


This patch adds a command to RedBoot called 'ifdisk'
It allows for a command to be executed conditionally based on the presence of a disk drive. It's included as an option to the RedBoot disks package.


It's used as:
ifdisk <drive> <any redboot command & parameters>

It can be used, for example, to load a Linux kernel from a removable flash drive, if present, or fall-through and load the kernel from a default drive. (Sort-of like booting off a floppy drive on a PC when the floppy is present otherwise defaulting to the hard drive).

For example, our system has a CF adapter that maps to hda1. It also has an internal flash mapped to mtdblock1. At the end of the boot script this boots off the CF when present, or the internal flash when the CF is not present:

ifdisk hda1 exec -b 0x100000 -c "noinitrd root=/dev/hda1 console=ttySA0"
exec -b 0x100000 -c "noinitrd root=/dev/mtdblock1 console=ttySA0"


It mainly borrows the code from the existing 'do_disks' function. A more general conditional execution model might have been nice, but this fit our current need.


Frank Pagliughi

diff -urN ecos-org/packages/redboot/current/cdl/redboot.cdl ecos/packages/redboot/current/cdl/redboot.cdl
--- ecos-org/packages/redboot/current/cdl/redboot.cdl	2006-05-14 09:36:23.000000000 -0400
+++ ecos/packages/redboot/current/cdl/redboot.cdl	2006-05-14 09:45:05.000000000 -0400
@@ -1051,6 +1051,16 @@
                   filesystems."
                 compile -library=libextras.a fs/iso9660fs.c
             }
+	    
+            cdl_component CYGSEM_REDBOOT_DISK_IFDISK_CMD {
+                display         "Support RedBoot 'ifdisk' command."
+                flavor          bool
+                default_value   0
+                description     "
+                        When enabled, RedBoot will include the 'ifdisk' conditional command.
+                        This allows for different boot options depending on which drives are present.
+			"
+	    }
         }
     
         cdl_component CYGPKG_REDBOOT_BOOT_SCRIPT {
diff -urN ecos-org/packages/redboot/current/src/fs/disk.c ecos/packages/redboot/current/src/fs/disk.c
--- ecos-org/packages/redboot/current/src/fs/disk.c	2006-05-14 09:36:23.000000000 -0400
+++ ecos/packages/redboot/current/src/fs/disk.c	2006-05-14 09:47:08.000000000 -0400
@@ -71,6 +71,16 @@
             do_disks
     );
 
+#ifdef CYGSEM_REDBOOT_DISK_IFDISK_CMD
+static void if_disk(int argc, char *argv[]);
+
+RedBoot_cmd("ifdisk",
+            "Conditional execution dependent on presence of disk drive.",
+            "<drive_name> <command> [command_params]",
+            if_disk
+	);
+#endif		// CYGSEM_REDBOOT_DISK_IFDISK_CMD
+
 static disk_t disk_table[CYGNUM_REDBOOT_MAX_DISKS];
 static int    disk_count = 0;
 
@@ -359,6 +369,60 @@
     }
 }
 
+#ifdef CYGSEM_REDBOOT_DISK_IFDISK_CMD
+extern struct cmd __RedBoot_CMD_TAB__[], __RedBoot_CMD_TAB_END__;
+
+static void
+if_disk(int argc, char *argv[])
+{
+    int i, j;
+    disk_t *d;
+    partition_t *p;
+    char name[16];
+	int bFound = 0;
+	struct cmd* cmd;
+
+	if (argc < 3) {
+		diag_printf("** Error: Please specify a drive name and command.\n");
+		return;
+	}
+
+	//diag_printf("Searching for disk '%s'\n", argv[1]);
+
+    for (i=0, d=disk_table; i<disk_count && !bFound;  i++, d++) {
+		*name = '\0';
+
+        switch (d->kind) {
+          case DISK_IDE_HD:
+            for (j = 0, p = d->partitions;
+                 j < CYGNUM_REDBOOT_MAX_PARTITIONS && !bFound;
+                 j++, p++) {
+                if (p->systype) {
+                    diag_sprintf(name, "hd%c%d", 'a' + d->index, j+1);
+					bFound = (strcmp(name, argv[1]) == 0);
+				}
+            }
+            break;
+          case DISK_IDE_CDROM:
+            diag_sprintf(name, "cd%d", d->index);
+			bFound = (strcmp(name, argv[1]) == 0);
+            break;
+        }
+    }
+
+	if (bFound) {
+		//diag_printf("Disk '%s' found. Executing '%s'\n", argv[1], argv[2]);
+
+		cmd = cmd_search(__RedBoot_CMD_TAB__, &__RedBoot_CMD_TAB_END__, argv[2]);
+		if (cmd != (struct cmd *)0)
+			(cmd->fun)(argc-2, argv+2);
+		else
+			diag_printf("** Error: Illegal command: \"%s\"\n", argv[2]);
+	}
+}
+#endif		// CYGSEM_REDBOOT_DISK_IFDISK_CMD
+
+
 static void *fileptr;
 static partition_t *file_part;
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]