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 int do_bootm(cmd_tbl_t *, int, int, char *[]);
39 extern long do_fat_read(const char *, void *, unsigned long, int);
40 extern int do_fat_fsload(cmd_tbl_t *, int, int, char *[]);
42 static int load_rescue_image(ulong);
44 void cm5200_fwupdate(void)
50 char *argv[3] = { "bootm", ka, NULL };
52 /* Check if rescue system is disabled... */
53 if (getenv("norescue")) {
54 printf(LOG_PREFIX "Rescue System disabled.\n");
58 /* Check if we have a USB storage device and load image */
59 if (load_rescue_image(LOAD_ADDR))
62 bcmd = find_cmd("bootm");
66 sprintf(ka, "%lx", LOAD_ADDR);
68 /* prepare our bootargs */
69 rsargs = getenv("rs-args");
73 tmp = malloc(strlen(rsargs+1));
75 printf(LOG_PREFIX "Memory allocation failed\n");
82 setenv("bootargs", rsargs);
87 printf(LOG_PREFIX "Starting update system (bootargs=%s)...\n", rsargs);
88 do_bootm(bcmd, 0, 2, argv);
91 static int load_rescue_image(ulong addr)
93 disk_partition_t info;
102 char *argv[6] = { "fatload", "usb", dev, addr_str, nxri, NULL };
103 block_dev_desc_t *stor_dev = NULL;
106 /* Get name of firmware directory */
107 tmp = getenv("fw-dir");
109 /* Copy it into fwdir */
110 strncpy(fwdir, tmp ? tmp : FW_DIR, sizeof(fwdir));
111 fwdir[sizeof(fwdir) - 1] = 0; /* Terminate string */
113 printf(LOG_PREFIX "Checking for firmware image directory '%s' on USB"
114 " storage...\n", fwdir);
119 /* Check for storage device */
120 if (usb_stor_scan(1) != 0) {
125 /* Detect storage device */
126 for (devno = 0; devno < USB_MAX_STOR_DEV; devno++) {
127 stor_dev = usb_stor_get_dev(devno);
128 if (stor_dev->type != DEV_TYPE_UNKNOWN)
131 if (!stor_dev || stor_dev->type == DEV_TYPE_UNKNOWN) {
132 printf(LOG_PREFIX "No valid storage device found...\n");
137 /* Detect partition */
138 for (partno = -1, i = 0; i < 6; i++) {
139 if (get_partition_info(stor_dev, i, &info) == 0) {
140 if (fat_register_device(stor_dev, i) == 0) {
141 /* Check if rescue image is present */
142 FW_DEBUG("Looking for firmware directory '%s'"
143 " on partition %d\n", fwdir, i);
144 if (do_fat_read(fwdir, NULL, 0, LS_NO) == -1) {
145 FW_DEBUG("No NX rescue image on "
146 "partition %d.\n", i);
150 FW_DEBUG("Partition %d contains "
151 "firmware directory\n", partno);
161 printf(LOG_PREFIX "Error: No valid (FAT) partition "
165 printf(LOG_PREFIX "Error: No NX rescue image on FAT "
169 printf(LOG_PREFIX "Error: Failed with code %d\n",
176 /* Load the rescue image */
177 bcmd = find_cmd("fatload");
179 printf(LOG_PREFIX "Error - 'fatload' command not present.\n");
184 tmp = getenv("nx-rescue-image");
185 sprintf(nxri, "%s/%s", fwdir, tmp ? tmp : RESCUE_IMAGE);
186 sprintf(dev, "%d:%d", devno, partno);
187 sprintf(addr_str, "%lx", addr);
189 FW_DEBUG("fat_fsload device='%s', addr='%s', file: %s\n",
190 dev, addr_str, nxri);
192 if (do_fat_fsload(bcmd, 0, 5, argv) != 0) {