xref: /titanic_50/usr/src/cmd/fwflash/plugins/vendor/sd-GENERIC.c (revision b56bf881a9655cb27b53cba1468312f7c6dfb0a2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <sys/types.h>
31 #include <sys/sysmacros.h>
32 #include <fcntl.h>
33 #include <sys/condvar.h>
34 #include <string.h>
35 #include <strings.h>
36 
37 #include <sys/byteorder.h>
38 
39 #include <libintl.h> /* for gettext(3c) */
40 #include <fwflash/fwflash.h>
41 
42 char vendor[] = "GENERIC \0";
43 
44 /* MAXIMGSIZE = 1.4 * 1024 * 1024 bytes */
45 /* Currently the largest firmware image size is 1.4 MB */
46 /* 1468006 = 1.4 * 1024 * 1024 */
47 #define	MAXIMGSIZE	((unsigned int)(1468006))
48 
49 extern struct vrfyplugin *verifier;
50 
51 /* required functions for this plugin */
52 int vendorvrfy(struct devicelist *devicenode);
53 
54 /*
55  * Important information about how this verification plugin works
56  *
57  * Direct-attached disks (sd instances) which support firmware
58  * download accept image files up to 1.4 * 1024 * 1024 bytes in
59  * size, and do their own verification of the image, rejecting the
60  * file if it is not appropriate for them.
61  *
62  * All that we need to do here is set the various verifier fields
63  * correctly, and check that the filesize as read from the filesystem
64  * is less than 1.4 * 1024 * 1024 bytes.
65  */
66 
67 int
68 vendorvrfy(struct devicelist *devicenode)
69 {
70 	if (verifier->imgsize > MAXIMGSIZE) {
71 		logmsg(MSG_ERROR,
72 		    gettext("\nsd-GENERIC firmware image verifier: "
73 		    "supplied filename %s exceeds maximum allowable "
74 		    "size of %d bytes\n"),
75 		    verifier->imgfile, MAXIMGSIZE);
76 		return (FWFLASH_FAILURE);
77 	}
78 
79 	logmsg(MSG_INFO,
80 	    "sd-GENERIC verifier for device\n"
81 	    "vid %s, pid %s, rev %s\npath %s\n",
82 	    devicenode->ident->vid,
83 	    devicenode->ident->pid,
84 	    devicenode->ident->revid,
85 	    devicenode->addresses[0]);
86 	verifier->flashbuf = 0;
87 
88 	return (FWFLASH_SUCCESS);
89 }
90