免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2923 | 回复: 2
打印 上一主题 下一主题

[PATCH]g-bios add boot -l option:boot linux via specified command line [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-10-30 18:12 |只看该作者 |倒序浏览
g-bios boot 命令新增加-l选项,可直接指定Linux kernel command line 启动内核.


From 6b1511274b593266974cf9828a7095fe32e86137 Mon Sep 17 00:00:00 2001
From: genan <genan61@163.com>
Date: Fri, 30 Oct 2009 17:19:38 +0800
Subject: [PATCH 1/2]         modified:   thread/shell.c

---
thread/shell.c |   12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/thread/shell.c b/thread/shell.c
index 09cb2e0..6b2c635 100644
--- a/thread/shell.c
+++ b/thread/shell.c
@@ -54,7 +54,6 @@ static void ShowPrompt(void)
        printf("g-bios: %d# ", d);
}

-
static void InsertOneKey(char input_c, char *buf, int *cur_pos, int *cur_max)
{
        int i;
@@ -65,12 +64,10 @@ static void InsertOneKey(char input_c, char *buf, int *cur_pos, int *cur_max)
        ++(*cur_pos);
        ++(*cur_max);

-        printf("\033[4h");
+       
        putchar(input_c);
-        printf("\033[4l");
}

-
static void BackSpaceOneKey(char *buf, int *cur_pos, int *cur_max)
{
        int i;
@@ -346,11 +343,14 @@ int CommandRead(char buf[])


        memset(buf, 0, MAX_ARG_LEN);
+       

        while (0 == cur_max)
        {
                input_c = 0;

+                printf("\033[4h");
+
                ShowPrompt();
                while (input_c != '\r' && input_c != '\n')
                {
@@ -488,6 +488,8 @@ int CommandRead(char buf[])

        CmdUpdateHistory(buf);

+        printf("\033[4l");
+
        return 0;
}

@@ -609,5 +611,7 @@ int __INIT__ InitCmdQueue(void)
                return -ENOMEM;
        }

+       
+
        return 0;
}
--
1.6.3.3


0001-modified-thread-shell.c.patch.tar.gz (790 Bytes, 下载次数: 21)

论坛徽章:
0
2 [报告]
发表于 2009-10-30 18:14 |只看该作者
From d2582ab90216eccc92420f291b4e796a272edd97 Mon Sep 17 00:00:00 2001
From: genan <genan61@163.com>
Date: Fri, 30 Oct 2009 17:53:50 +0800
Subject: [PATCH 2/2] add boot -l option:boot linux via specified command line

---
app/boot/atag.h       |    1 -
app/boot/boot.c       |   90 ++++++++++++++++++++++++++++++++++--------------
include/core/thread.h |    2 +-
include/sysconf.h     |    5 ++-
4 files changed, 69 insertions(+), 29 deletions(-)

diff --git a/app/boot/atag.h b/app/boot/atag.h
index 789cecc..7e07f1e 100644
--- a/app/boot/atag.h
+++ b/app/boot/atag.h
@@ -140,5 +140,4 @@ struct Atag


#define CONF_RAM_BANK_NUM        1
-#define DEFAULT_KCMDLINE_LEN     1024

diff --git a/app/boot/boot.c b/app/boot/boot.c
index 740ced7..b4ff9d3 100644
--- a/app/boot/boot.c
+++ b/app/boot/boot.c
@@ -10,6 +10,7 @@
// #define CONF_FS_PART_ONLY // fixme: move to autoconf.h
// #define NOT_MERGE_GB_PARTS

+
#define LINUX_IMAGE_NAME "zImage"


@@ -108,9 +109,10 @@ static int BootUsage(void)
{
        printf("Usage: boot [options] \n"
                "\noptions:\n"
-                "\t-t [kernel_image_name]:  download kernel image via tftp.\n"
+                "\t-t [kernel_image_name]:  download kernel image via tftp\n"
                "\t-f [<part_num>]:  root=/dev/mtdblock<part_num>\n"
-                "\t-n [nfs_server:/path/to/nfs/root]:  boot vis NFS\n"
+                "\t-n [nfs_server:/path/to/nfs/root]:  boot via NFS\n"
+                "\t-l [kernel command line]:  boot via spcified CmdLine\n"
                "\t-r [ramdisk_image_name]:  boot with Ramdisk\n"
                "\t-v:  print the linux parameters and quit\n"
                "\nExamples:\n"
@@ -481,7 +483,7 @@ static int ShowBootArgs(void *pTagBase)

int main(int argc, char *argv[])
{
-        int   i, ret;
+        int   i, ret = 0;
        ULONG ulDevNum;
        char szCmdline[DEFAULT_KCMDLINE_LEN];
        BOOL isShowArg = FALSE;
@@ -597,6 +599,30 @@ int main(int argc, char *argv[])
                        isShowArg = TRUE;
                        break;

+                case 'l':
+                        if (i + 1 == argc)
+                        {
+                                //fix me:need to check kernel command line.
+                                if (pKeParam->szCmdLine[0] != 'r')
+                                {
+                                        printf("Invalid kernel command line!\n";
+                                        return -EINVAL;
+                                }
+                        }
+                        else
+                        {
+                                strcpy(pKeParam->szCmdLine, argv[++i]);
+
+                                for (i++; i < argc; i++)
+                                {
+                                        strcat(pKeParam->szCmdLine, " ";
+                                        strcat(pKeParam->szCmdLine, argv);
+                                }
+                        }
+
+                        pKeParam->dwBootMode = BM_CMDLINE;
+                        break;
+
                case 'h':
                        BootUsage();
                        return 0;
@@ -613,22 +639,33 @@ int main(int argc, char *argv[])
                GuSysConfSave();
        }

-        ret = BuildCmdline(szCmdline, sizeof(szCmdline));
-        if (ret < 0)
+        if(!(pKeParam->dwBootMode & BM_CMDLINE))
        {
-                printf("Warning: fail to setup linux command line!\n\"%s\"\n", szCmdline);
-                // anyway, we'd go ahead
+                ret = BuildCmdline(szCmdline, sizeof(szCmdline));
+                if (ret < 0)
+                {
+                        printf("Warning: fail to setup linux command line!\n\"%s\"\n", szCmdline);
+                        // anyway, we'd go ahead
+                }
+        }
+        else
+        {
+                strncpy(szCmdline, pKeParam->szCmdLine, DEFAULT_KCMDLINE_LEN);
        }

+
        BUG_ON ((pKeParam->dwBootMode & ~BM_MASK) == 0);

-        if (pKeParam->szImgKernel[0] != '\0') // fixme for error return (i.e. permission denied)
+        if (!isShowArg)
        {
-                ret = TftpLoadImage(PT_OS_LINUX, pKeParam->szImgKernel, &pImgKernel);
-        }
-        else
-        {
-                ret = PartLoadImage(PT_OS_LINUX, &pImgKernel);
+                if (pKeParam->szImgKernel[0] != '\0') // fixme for error return (i.e. permission denied)
+                {
+                        ret = TftpLoadImage(PT_OS_LINUX, pKeParam->szImgKernel, &pImgKernel);
+                }
+                else
+                {
+                        ret = PartLoadImage(PT_OS_LINUX, &pImgKernel);
+                }
        }

        // TODO: check the kernel image
@@ -642,25 +679,26 @@ int main(int argc, char *argv[])

        printf("\n";

-
        pTag = BeginSetupTag((void *)ATAG_BASE);
-
        pTag = SetupCmdlineTag(pTag, szCmdline);

        if (pKeParam->dwBootMode & BM_RAMDISK)
        {
-                if (pKeParam->szImgRd[0] != '\0')
+                if (!isShowArg)
                {
-                        ret = TftpLoadImage(PT_FS_RAMDISK, pKeParam->szImgRd, &pImgRamdisk);
-                }
-                else
-                {
-                        ret = PartLoadImage(PT_FS_RAMDISK, &pImgRamdisk);
-                }
+                        if (pKeParam->szImgRd[0] != '\0')
+                        {
+                                ret = TftpLoadImage(PT_FS_RAMDISK, pKeParam->szImgRd, &pImgRamdisk);
+                        }
+                        else
+                        {
+                                ret = PartLoadImage(PT_FS_RAMDISK, &pImgRamdisk);
+                        }

-                if (ret < 0)
-                {
-                        goto L1;
+                        if (ret < 0)
+                        {
+                                goto L1;
+                        }
                }

                // TODO: check the ramdisk
@@ -681,7 +719,7 @@ int main(int argc, char *argv[])

        IrqDisable(); // fixme

-        pfExecKernel(0, MACH_ID, ATAG_BASE);
+        pfExecKernel(0, 0x350, ATAG_BASE);

L1:
        printf("\n";
diff --git a/include/core/thread.h b/include/core/thread.h
index e8f3219..3d6421a 100644
--- a/include/core/thread.h
+++ b/include/core/thread.h
@@ -7,7 +7,7 @@
#undef  APP_DEBUG

#define __GBIOS_APP__       __attribute__((section(".GBiosApp"))
-#define MAX_ARG_LEN                  128
+#define MAX_ARG_LEN                  512
#define MAX_ARGC                        64


diff --git a/include/sysconf.h b/include/sysconf.h
index ffd038d..9e0f89f 100644
--- a/include/sysconf.h
+++ b/include/sysconf.h
@@ -17,13 +17,14 @@


#define CON_DEV_NAME_LEN    63
-
+#define DEFAULT_KCMDLINE_LEN     512

#define BM_MASK        ((1 << - 1)

#define BM_RAMDISK     (1 <<
#define BM_FLASHDISK   (2 <<
#define BM_NFS         (4 <<
+#define BM_CMDLINE     (8 <<


struct LinuxParam
@@ -39,6 +40,8 @@ struct LinuxParam
        char   szNfsPath[NFS_PATH_LEN];

        char   szConDev[CON_DEV_NAME_LEN + 1];
+
+        char   szCmdLine[DEFAULT_KCMDLINE_LEN];
};


--
1.6.3.3

0002-add-boot-l-option-boot-linux-via-specified-command-l.patch.tar.gz

2.15 KB, 下载次数: 21

论坛徽章:
0
3 [报告]
发表于 2009-10-30 19:11 |只看该作者
不错
下下来看看
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP