]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/cm5200/fwupdate.c
2 * (C) Copyright 2007 Schindler Lift Inc.
3 * (C) Copyright 2007 DENX Software Engineering
5 * Author: Michel Marti <mma@objectxp.com>
6 * Adapted for U-Boot 1.2 by Piotr Kruszynski <ppk@semihalf.com>:
8 * - bugfix for overwriting bootargs by user
10 * See file CREDITS for list of people who contributed to this
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
38 extern long do_fat_read(const char *, void *, unsigned long, int);
39 extern int do_fat_fsload(cmd_tbl_t
*, int, int, char * const []);
41 static int load_rescue_image(ulong
);
43 void cm5200_fwupdate(void)
49 char * const argv
[3] = { "bootm", ka
, NULL
};
51 /* Check if rescue system is disabled... */
52 if (getenv("norescue")) {
53 printf(LOG_PREFIX
"Rescue System disabled.\n");
57 /* Check if we have a USB storage device and load image */
58 if (load_rescue_image(LOAD_ADDR
))
61 bcmd
= find_cmd("bootm");
65 sprintf(ka
, "%lx", (ulong
)LOAD_ADDR
);
67 /* prepare our bootargs */
68 rsargs
= getenv("rs-args");
72 tmp
= malloc(strlen(rsargs
+1));
74 printf(LOG_PREFIX
"Memory allocation failed\n");
81 setenv("bootargs", rsargs
);
86 printf(LOG_PREFIX
"Starting update system (bootargs=%s)...\n", rsargs
);
87 do_bootm(bcmd
, 0, 2, argv
);
90 static int load_rescue_image(ulong addr
)
92 disk_partition_t info
;
101 char * const argv
[6] = { "fatload", "usb", dev
, addr_str
, nxri
, NULL
};
102 block_dev_desc_t
*stor_dev
= NULL
;
105 /* Get name of firmware directory */
106 tmp
= getenv("fw-dir");
108 /* Copy it into fwdir */
109 strncpy(fwdir
, tmp
? tmp
: FW_DIR
, sizeof(fwdir
));
110 fwdir
[sizeof(fwdir
) - 1] = 0; /* Terminate string */
112 printf(LOG_PREFIX
"Checking for firmware image directory '%s' on USB"
113 " storage...\n", fwdir
);
118 /* Check for storage device */
119 if (usb_stor_scan(1) != 0) {
124 /* Detect storage device */
125 for (devno
= 0; devno
< USB_MAX_STOR_DEV
; devno
++) {
126 stor_dev
= usb_stor_get_dev(devno
);
127 if (stor_dev
->type
!= DEV_TYPE_UNKNOWN
)
130 if (!stor_dev
|| stor_dev
->type
== DEV_TYPE_UNKNOWN
) {
131 printf(LOG_PREFIX
"No valid storage device found...\n");
136 /* Detect partition */
137 for (partno
= -1, i
= 0; i
< 6; i
++) {
138 if (get_partition_info(stor_dev
, i
, &info
) == 0) {
139 if (fat_register_device(stor_dev
, i
) == 0) {
140 /* Check if rescue image is present */
141 FW_DEBUG("Looking for firmware directory '%s'"
142 " on partition %d\n", fwdir
, i
);
143 if (do_fat_read(fwdir
, NULL
, 0, LS_NO
) == -1) {
144 FW_DEBUG("No NX rescue image on "
145 "partition %d.\n", i
);
149 FW_DEBUG("Partition %d contains "
150 "firmware directory\n", partno
);
160 printf(LOG_PREFIX
"Error: No valid (FAT) partition "
164 printf(LOG_PREFIX
"Error: No NX rescue image on FAT "
168 printf(LOG_PREFIX
"Error: Failed with code %d\n",
175 /* Load the rescue image */
176 bcmd
= find_cmd("fatload");
178 printf(LOG_PREFIX
"Error - 'fatload' command not present.\n");
183 tmp
= getenv("nx-rescue-image");
184 sprintf(nxri
, "%s/%s", fwdir
, tmp
? tmp
: RESCUE_IMAGE
);
185 sprintf(dev
, "%d:%d", devno
, partno
);
186 sprintf(addr_str
, "%lx", addr
);
188 FW_DEBUG("fat_fsload device='%s', addr='%s', file: %s\n",
189 dev
, addr_str
, nxri
);
191 if (do_fat_fsload(bcmd
, 0, 5, argv
) != 0) {