1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/*
* ubparams.c
*
* Generate a u-boot parameter block with correct crc
*
* (C) 1007 Guthrie Consulting
* hamish@prodigi.ch
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef __ASSEMBLY__
#define __ASSEMBLY__
#endif
#define __ASM_STUB_PROCESSOR_H__
#include <config.h>
#undef __ASSEMBLY__
#include <environment.h>
#define XMK_STR(x) #x
#define MK_STR(x) XMK_STR(x)
extern unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
#if !defined(ENV_CRC)
#define ENV_CRC ~0
#endif
static char *environment[] = {
"bootdelay=3\0"
"baudrate=115200\0"
"stdin=serial\0"
"stdout=serial\0"
"stderr=serial\0"
"partitions=mtdparts=AT45DB642.spi0:132k(bootloader),33k(ubparams),99k(spare),1056k(linux),1056k(rootfs),33k(nvram),-(rootfs_data)\0"
"fbargs=setenv bootargs mtdparts=AT45DB642.spi0:132k(bootloader),33k(ubparams),99k(spare),1056k(linux),1056k(rootfs),33k(nvram),-(rootfs_data) root=/dev/mtdblock4 ro init=/etc/preinit console=/dev/ttyS0,115200,mem=32M\0"
"rdba=setenv bootargs mtdparts=AT45DB642.spi0:132k(bootloader),33k(ubparams),99k(spare),1056k(linux),1056k(rootfs),33k(nvram),-(rootfs_data) root=/dev/ram rw initrd=0x21200000,6000000 ramdisk_size=20000 init=/etc/preinit console=/dev/ttyS0,115200,mem=32M\0"
"rdram=run rdba; tftp 21000000 vImage; tftp 21200000 root.squashfs; bootm 21000000\0"
"flash=run fbargs; bootm 0xc0042000\0"
"bootargs=setenv bootargs mtdparts=AT45DB642.spi0:132k(bootloader),33k(ubparams),99k(spare),1056k(linux),1056k(rootfs),33k(nvram),-(rootfs_data) root=/dev/mtdblock4 ro init=/etc/preinit console=/dev/ttyS0,115200,mem=32M\0"
"bootcmd=bootm 0xc0042000\0"
"ipaddr=10.0.1.73\0"
"serverip=10.0.1.210\0"
"\0"
};
int main(int argc, char *argv[]) {
env_t *envptr;
char *src, *srcptr;
char *dataptr;
FILE *params;
int argfail = 1;
char newmac[30];
char newser[30];
int paramlen = 0;
int progmac = 0;
int progser = 0;
if (argc < 3) {
printf ("Invalid arguments\n");
return 1;
}
switch (argc) {
case 5:
if (strcmp(argv[3], "--serial") == 0) {
argfail = 0;
sprintf(newser, "serial#=%s", argv[4]);
progser = 1;
}
case 3:
if (strcmp(argv[1], "--mac") == 0) {
argfail = 0;
sprintf(newmac, "ethaddr=%s", argv[2]);
progmac = 1;
}
else
argfail = 1;
}
if (argfail) {
printf("Invalid arguments\n");
return 1;
}
src = srcptr = *environment;
envptr = (env_t *)malloc(CFG_ENV_SIZE);
dataptr = (char *)envptr + ENV_HEADER_SIZE;
while(*srcptr) {
//printf("%d, %s\n", strlen(srcptr), srcptr);
paramlen += strlen(srcptr) + 1;
srcptr += strlen(srcptr) + 1;
}
printf("Make u-boot params\n");
printf("Params size is %d\n", CFG_ENV_SIZE);
memset(envptr, 0, CFG_ENV_SIZE);
memcpy(dataptr, src, paramlen);
dataptr += paramlen;
if (progmac) {
memcpy(dataptr, newmac, strlen(newmac));
dataptr += strlen(newmac) + 1;
}
if (progser) {
memcpy(dataptr, newser, strlen(newser));
dataptr += strlen(newser) + 1;
}
envptr->crc = crc32(0, envptr->data, ENV_SIZE);
params = fopen("params", "w");
fwrite(envptr, CFG_ENV_SIZE, 1, params);
fclose(params);
free(envptr);
return 0;
}
|