4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * send_file.c: to support firmware download (get fw S-records from the
31 * user-specified file and send S-records string down to the service processor
44 ADM_Send_file(FILE *FilePtr
)
46 static char ADM_Line
[ADM_LINE_SIZE
];
47 static bp_msg_t Message
;
48 static struct timespec Timeout
;
58 * Determine the length of the file
60 if (fseek(FilePtr
, 0L, SEEK_END
) == 0) {
61 FileLength
= ftell(FilePtr
);
67 while ((fgets(ADM_Line
, ADM_LINE_SIZE
, FilePtr
) != NULL
) &&
69 if ((ADM_Line
[0] == 'S') &&
70 ((ADM_Line
[1] == '7') || (ADM_Line
[1] == '8') ||
71 (ADM_Line
[1] == '9'))) {
75 BootRetry
= ADM_BOOT_RETRY
;
76 while (BootRetry
> 0) {
78 rsc_raw_write(ADM_Line
, strlen(ADM_Line
))) != 0) {
83 * Initialize Timeout each time just to be robust.
84 * Since this operation is not time critical, this is
88 Timeout
.tv_sec
= ADM_BOOT_LOAD_TIMEOUT
;
89 /* If we timeout, decrement BootRetry and try again */
90 if ((Status
= ADM_Boot_recv(&Message
, &Timeout
)) != 0) {
91 /* We got a timeout */
92 BootRetry
= BootRetry
- 1;
97 /* we got a message back, see what it is */
98 if ((Message
.cmd
== BP_RSC_BOOTOK
) &&
99 (Message
.dat1
== 0) &&
100 (Message
.dat2
== 0)) {
106 if ((Message
.cmd
!= BP_RSC_BOOTACK
) ||
107 (Message
.dat1
!= BP_DAT1_SRECORD_ACK
)) {
110 BP_DAT1_SRECORD_NAK
) {
113 ADM_Display_download_error(
120 * We got a valid acknowledge, break out of
121 * loop and start to download next s-record
127 /* See if we ever got a response */
128 if (BootRetry
<= 0) {
129 (void) fprintf(stderr
, "\n%s\n\n",
130 gettext("scadm: SC failed to respond during "
136 if ((LinesWritten
% 100) == 0) {
138 (void) fflush(stdout
);
140 if ((LinesWritten
% 4000) == 0) {
142 /* Show % progress */
143 FilePos
= ftell(FilePtr
);
144 (void) printf(" (%ld%%)",
145 (FilePos
* 100) / FileLength
);
148 (void) fflush(stdout
);
151 if ((FileLength
) && ((LinesWritten
% 4000) != 0)) {
152 /* Show final % progress (should normally be 100%) */
153 FilePos
= ftell(FilePtr
);
154 (void) printf(" (%ld%%)",
155 (FilePos
* 100) / FileLength
);
164 ADM_Display_download_error(int cmd
, int dat1
)
166 if (cmd
== BP_RSC_BOOTFAIL
) {
167 if (dat1
== BP_DAT1_REJECTED
) {
168 (void) fprintf(stderr
, "\n%s\n\n",
169 gettext("scadm: download rejected"));
171 } else if (dat1
== BP_DAT1_RANGE_ERR
) {
172 (void) fprintf(stderr
, "\n%s\n\n",
173 gettext("scadm: download failed, "
174 "SC reported range error"));
176 } else if (dat1
== BP_DAT1_VERIFY_ERR
) {
177 (void) fprintf(stderr
, "\n%s\n\n",
178 gettext("scadm: download failed, "
179 "SC reported verify error"));
181 } else if (dat1
== BP_DAT1_ERASE_ERR
) {
182 (void) fprintf(stderr
, "\n%s\n\n",
183 gettext("scadm: download failed, "
184 "SC reported erase error"));
186 } else if (dat1
== BP_DAT1_INT_WP_ERR
) {
187 (void) fprintf(stderr
, "\n%s\n\n",
188 gettext("scadm: download failed, "
189 "SC reported int_wp error"));
191 } else if (dat1
== BP_DAT1_WP_ERR
) {
192 (void) fprintf(stderr
, "\n%s\n\n",
193 gettext("scadm: download failed, "
194 "SC reported wp error"));
196 } else if (dat1
== BP_DAT1_VPP_ERR
) {
197 (void) fprintf(stderr
, "\n%s\n\n",
198 gettext("scadm: download failed, "
199 "SC reported vpp error"));
201 (void) fprintf(stderr
, "%s 0x%08x\n",
202 gettext("scadm: SC returned fatal error"), dat1
);
204 } else if (cmd
== BP_RSC_BOOTACK
) {
205 if (dat1
== BP_DAT1_SRECORD_ACK
) {
206 (void) fprintf(stderr
, "\n%s\n\n",
207 gettext("scadm: download failed"));
209 (void) fprintf(stderr
, "%s 0x%08x\n",
210 gettext("scadm: SC returned fatal error"), dat1
);
213 (void) fprintf(stderr
, "%s 0x%08x:0x%08x\n",
214 gettext("scadm: SC returned unknown error"), cmd
, dat1
);