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