This patch makes it possible to have a platform where the user can
optionally use an initramfs. Previously qi would abort if initramfs
was specified for the board but could not be found.

Adapted from patch sent by Michele Mazzucchi
<[email protected]> -- thanks!
---
 src/phase2.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/phase2.c b/src/phase2.c
index 4a7ff18..2c88f33 100644
--- a/src/phase2.c
+++ b/src/phase2.c
@@ -52,6 +52,21 @@ static void indicate(enum ui_indication ui_indication)
                (this_board->set_ui_indication)(ui_indication);
 }
 
+static int file_exists(const char * filepath)
+{
+       switch (this_kernel->filesystem) {
+       case FS_EXT2:
+               if (!ext2fs_mount()) {
+                       /* filesystem error, pretend file doesn't exist */
+                       puts("Unable to mount ext2 filesystem\n");
+                       return 0;
+               }
+               return (ext2fs_open(filepath) >= 0);
+       default:
+               return 0;
+       }
+}
+
 static int read_file(const char * filepath, u8 * destination, int size)
 {
        int len = size;
@@ -211,7 +226,7 @@ static void do_params(unsigned initramfs_len,
        params->u.mem.size = this_board->linux_mem_size;
        params = tag_next(params);
 
-       if (this_kernel->initramfs_filepath) {
+       if (this_kernel->initramfs_filepath && initramfs_len > 0) {
                /* INITRD2 tag */
                params->hdr.tag = ATAG_INITRD2;
                params->hdr.size = tag_size(tag_initrd);
@@ -425,7 +440,7 @@ static void try_this_kernel(void)
 
        /* initramfs if needed */
 
-       if (this_kernel->initramfs_filepath) {
+       if (this_kernel->initramfs_filepath && 
file_exists(this_kernel->initramfs_filepath)) {
                indicate(UI_IND_INITRAMFS_PULL);
                initramfs_len = read_file(this_kernel->initramfs_filepath,
                      (u8 *)this_board->linux_mem_start + INITRD_OFFSET,
-- 
1.7.2.5


Reply via email to