- 论坛徽章:
- 0
|
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 |
|