[PATCH] customized machine ID option in boot command
在boot命令中,添加了boot -i选项,用以动态设置并保存内核启动参数中machineID参数。
signed-off-by TanChangxian <ChangXian.Tan@gmail.com>
signed-off-by ChengYuanQuan <YuanQuan.Cheng@gmail.com>
signed-off-by voidjackjiang <VoidJack.Jiang@gmail.com>
------------------------------------------------------------------------------------------------------------------------
Index: app/boot/boot_linux.c
===================================================================
--- app/boot/boot_linux.c (revision 421)
+++ app/boot/boot_linux.c (working copy)
@@ -11,7 +11,6 @@
#define LINUX_IMAGE_NAME "zImage"
-
typedef void (*LINUX_KERNEL_ENTRY)(int, int, UINT32);
@@ -111,6 +110,7 @@
"\t-f [<part_num>]: root=/dev/mtdblock<part_num>\n"
"\t-n [nfs_server:/path/to/nfs/root]: boot vis NFS\n"
"\t-r [ramdisk_image_name]: boot with Ramdisk\n"
+ "\t-i [machine_ID]: set the machine's ID\n"
"\t-v: print the linux parameters and quit\n"
"\nExamples:\n"
"\t..."
@@ -408,6 +408,12 @@
i = 0;
printf("\n");
+ printf(" ***Machine ID is %d ***\n", GuSysGetMachineID());
+
while (1)
{
printf("[ATAG %d] ", ++i);
@@ -446,7 +452,7 @@
pTag = TAG_NEXT(pTag);
}
-
return 0;
}
@@ -577,6 +583,23 @@
BootUsage();
return 0;
+ case 'i':
+
+ if (i + 1 == argc || '-' == argv[i + 1][0])
+ {
+ pKeParam->szMachineID = CONF_MACHINE_ID;
+
+ break;
+ }
+
+ if (GuStrToVal(argv[++i], &(pKeParam->szMachineID)) < 0)
+ {
+ printf("Invalid option: %s", argv);
+ return -EINVAL;
+ }
+
+ break;
+
default:
printf("Invalid option: \"%s\"!\n", pArg);
BootUsage();
@@ -653,7 +676,8 @@
IrqDisable(); // fixme
- pfExecKernel(0, 6666, ATAG_BASE);
+ pfExecKernel(0, pKeParam->szMachineID, ATAG_BASE);
L1:
printf("Fail to boot linux!\n");
Index: app/flash/sysconf.c
===================================================================
--- app/flash/sysconf.c (revision 421)
+++ app/flash/sysconf.c (working copy)
@@ -12,6 +12,7 @@
static struct SysConf gSysConf;
+
// static int g_nVol = 0;
@@ -186,7 +187,6 @@
struct NetConf *pNetConf = &gSysConf.mNetConf;
struct LinuxParam *pKeParam = &gSysConf.mLinuxParam;
-
memset(&gSysConf, 0x0, sizeof(gSysConf)); // to be removed
pFlash = GuFlashOpen(BOOT_FLASH_ID);
@@ -214,6 +214,9 @@
pKeParam->nRootDev = 0;
+//init the machineID
+ pKeParam->szMachineID = CONF_MACHINE_ID;
+
for (i = 0; i < pPartInfo->nParts; i++)
{
struct PartAttr *pAttr = pPartInfo->vAttrTab + i;
@@ -385,6 +388,12 @@
}
+int GuSysGetMachineID()
+{
+ return gSysConf.mLinuxParam.szMachineID;
+}
+
+
static __INIT__ int PartInfoInit(struct Flash *pFlash, struct PartInfo *pPartInfo)
{
struct Partition *pPart;
@@ -448,6 +457,7 @@
return 0;
}
+
static __INIT__ int SysConfInit(void)
{
int ret;
Index: include/sysconf.h
===================================================================
--- include/sysconf.h (revision 421)
+++ include/sysconf.h (working copy)
@@ -29,7 +29,7 @@
struct LinuxParam
{
UINT32 dwBootMode;
-
+
int nRootDev;
char szImgKernel[MAX_FILE_NAME_LEN];
@@ -39,9 +39,10 @@
char szNfsPath[NFS_PATH_LEN];
char szConDev[CON_DEV_NAME_LEN + 1];
+
+ UINT32 szMachineID;
};
-
struct SysConf
{
UINT32 dwCheckSum;
[ 本帖最后由 voidjackjiang 于 2009-6-26 14:20 编辑 ]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
do NOT edit your patch, pls keep the original version.
szMachineID应以int型变量传递给kernel启动参数,因此需要做出如下修改:
1 修改szMachineID变量类型为int
2 重新命名szMachineID为nMachineID
------------------------------------------------------------------------------------------------------------------------------
Index: app/boot/boot_linux.c
===================================================================
--- app/boot/boot_linux.c (revision 421)
+++ app/boot/boot_linux.c (working copy)
@@ -11,7 +11,6 @@
#define LINUX_IMAGE_NAME "zImage"
-
typedef void (*LINUX_KERNEL_ENTRY)(int, int, UINT32);
@@ -111,6 +110,7 @@
"\t-f [<part_num>]: root=/dev/mtdblock<part_num>\n"
"\t-n [nfs_server:/path/to/nfs/root]: boot vis NFS\n"
"\t-r [ramdisk_image_name]: boot with Ramdisk\n"
+ "\t-i [machine_ID]: set the machine's ID\n"
"\t-v: print the linux parameters and quit\n"
"\nExamples:\n"
"\t..."
@@ -408,6 +408,8 @@
i = 0;
printf("\n");
+ printf(" ***Machine ID is %d ***\n", GuSysGetMachineID());
+
while (1)
{
printf("[ATAG %d] ", ++i);
@@ -446,7 +448,7 @@
pTag = TAG_NEXT(pTag);
}
-
+
return 0;
}
@@ -577,6 +579,23 @@
BootUsage();
return 0;
+ case 'i':
+
+ if (i + 1 == argc || '-' == argv[i + 1][0])
+ {
+ pKeParam->nMachineID = CONF_MACHINE_ID;
+
+ break;
+ }
+
+ if (GuStrToVal(argv[++i], &(pKeParam->nMachineID)) < 0)
+ {
+ printf("Invalid option: %s", argv);
+ return -EINVAL;
+ }
+
+ break;
+
default:
printf("Invalid option: \"%s\"!\n", pArg);
BootUsage();
@@ -653,7 +672,8 @@
IrqDisable(); // fixme
- pfExecKernel(0, 6666, ATAG_BASE);
+// pfExecKernel(0, 6666, ATAG_BASE);
+ pfExecKernel(0, pKeParam->nMachineID, ATAG_BASE);
L1:
printf("Fail to boot linux!\n");
Index: app/flash/sysconf.c
===================================================================
--- app/flash/sysconf.c (revision 421)
+++ app/flash/sysconf.c (working copy)
@@ -12,6 +12,7 @@
static struct SysConf gSysConf;
+
// static int g_nVol = 0;
@@ -186,7 +187,6 @@
struct NetConf *pNetConf = &gSysConf.mNetConf;
struct LinuxParam *pKeParam = &gSysConf.mLinuxParam;
-
memset(&gSysConf, 0x0, sizeof(gSysConf)); // to be removed
pFlash = GuFlashOpen(BOOT_FLASH_ID);
@@ -214,6 +214,9 @@
pKeParam->nRootDev = 0;
+//init the machineID
+ pKeParam->nMachineID = CONF_MACHINE_ID;
+
for (i = 0; i < pPartInfo->nParts; i++)
{
struct PartAttr *pAttr = pPartInfo->vAttrTab + i;
@@ -385,6 +388,12 @@
}
+int GuSysGetMachineID()
+{
+ return gSysConf.mLinuxParam.nMachineID;
+}
+
+
static __INIT__ int PartInfoInit(struct Flash *pFlash, struct PartInfo *pPartInfo)
{
struct Partition *pPart;
@@ -448,6 +457,7 @@
return 0;
}
+
static __INIT__ int SysConfInit(void)
{
int ret;
Index: include/sysconf.h
===================================================================
--- include/sysconf.h (revision 421)
+++ include/sysconf.h (working copy)
@@ -29,7 +29,7 @@
struct LinuxParam
{
UINT32 dwBootMode;
-
+
int nRootDev;
char szImgKernel[MAX_FILE_NAME_LEN];
@@ -39,9 +39,10 @@
char szNfsPath[NFS_PATH_LEN];
char szConDev[CON_DEV_NAME_LEN + 1];
+
+ int nMachineID;
};
-
struct SysConf
{
UINT32 dwCheckSum;
请规范化你的patch
如,你的patch中把若干空行加了tab,这是不应该出现的更动