* ========== Copyright Header Begin ==========================================
* Hypervisor Software File: makeprom.c
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* - Do no alter or remove copyright notices
* - Redistribution and use of this software in source and binary forms, with
* or without modification, are permitted provided that the following
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of Sun Microsystems, Inc. or the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
* OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
* FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or maintenance of
* ========== Copyright Header End ============================================
* id: @(#)makeprom.c 1.18 03/04/01
* Copyright 1994-2001, 2003 Sun Microsystems, Inc. All Rights Reserved
* Use is subject to license terms.
#define PROM_SIZE (8*1024*1024)
static unsigned long header
[] = {
static int recurselevel
= 0;
static int standalone
= 0;
"%s: <flags> [-o output] input1 .. inputn\n"
" -p <pad> : pad input1 to <pad>Kb boundary\n"
" -c : Append CRC at end, assumes -p\n"
" -a : add a.out header\n"
" -f : (Force) Fix checksum\n"
" -s : create output files for standalone utility\n"
" -d : descend into level2 dropins\n"
" -n : disable default pad to 512KB\n"
" -o <output> : output filename\n";
fprintf(stderr
, msg
, name
);
show_dropin_info(int level
, obmd_t
*obmdp
)
unsigned int *dptr
= (unsigned int *) ((char *)obmdp
+ OBMD_HDR
);
while (level
--) putchar(' ');
printf("Name: %s size = %lx", obmdp
->name
, obmdp
->size
);
if ((dptr
[0] == COMP_MAGIC
) && (obmdp
->size
== dptr
[1]))
unsigned int len
= dptr
[3];
strncpy(type
, (char *)&dptr
[2], 4);
printf(", %s, len %x", type
, len
);
printf(" checksum = %x", obmdp
->chksum
);
return ((strncmp(ptr
, "OBMD", 4) == 0) ||
(strncmp(ptr
, "OBME", 4) == 0));
do_dropin(int level
, obmd_t
*obmdp
, int size
)
char *start
= (char *)obmdp
;
while (is_dropin((char *)obmdp
)) {
unsigned int *dptr
= (unsigned int *) ((char *)obmdp
+OBMD_HDR
);
if (verbose
) show_dropin_info(level
, obmdp
);
crc
= checksum((ushort_t
*)obmdp
, obmdp
->size
+OBMD_HDR
);
if ((obmdp
->chksum
!= 0) && (!force
)) {
if (!verbose
) show_dropin_info(level
, obmdp
);
printf(", Bad checksum: %s (%x != %x)\n",
(verbose
? "" : obmdp
->name
),
if (verbose
) printf("\n");
if (verbose
) printf("\n ");
if (obmdp
->chksum
!= 0) {
if (verbose
) printf("Forcing");
if (verbose
) printf("Generating");
if (verbose
) printf(" checksum of %s", obmdp
->name
);
obmdp
->chksum
= checksum((ushort_t
*)obmdp
,
printf(", checksum = %x",
if ((recurselevel
> level
) && (dptr
[0] == OBME_MAGIC
)) {
do_dropin(level
+1, (obmd_t
*)(dptr
+1), 0);
if (strncmp(obmdp
->name
, "OBP", 3) == 0) {
obmdp
= (obmd_t
*)(((uchar_t
*)obmdp
) +
ROUNDUP(obmdp
->size
)+OBMD_HDR
);
if (!is_dropin((char *)obmdp
)) {
char *try = (char *)obmdp
- 16;
for (slide
= 0; slide
< 32; slide
++, try++)
prev
->chksum
= checksum((ushort_t
*)prev
,
printf("Fixing %s length (%d)\n",
printf("Fixing %s checksum (%x)\n",
prev
->name
, prev
->chksum
);
fprintf(stderr
, "%s%s\n\n",
"ERROR: Need to adjust forward by",
total
= ((char *)obmdp
) - start
;
obmdp
= (obmd_t
*)ROUNDUP(obmdp
);
if ((verify
) && (total
< size
)) {
/* Scan forward looking for more headers.. */
here
= (char *)ROUNDUP((char *)obmdp
);
while (((here
-start
) < size
) && (!is_dropin(here
)))
if ((here
-start
) < size
) {
if (verbose
) printf("Skipping to: %x\n", here
-start
);
if ((force
) && (ndropins
== 1) && ((size
-OBMD_HDR
) != prev
->size
)) {
printf("Fixing %s size (actual %lx, should be %x)\n",
prev
->name
, prev
->size
, (size
-OBMD_HDR
));
prev
->size
= size
-OBMD_HDR
;
prev
->chksum
= checksum((ushort_t
*)prev
,
return (rewrite
&& !verify
);
main(int argc
, char **argv
)
while ((c
= getopt(argc
, argv
, "asdnvfcp:o:")) != EOF
)
if ((pad
== 0) || (pad
> 1024)) {
fprintf(stderr
, "Bad pad size: %dKb\n", pad
);
"-c and -n cannot be used together\n");
if ((ofile
== NULL
) && (!verify
)) {
fprintf(stderr
, "%s: Missing output filename\n", argv
[0]);
prom
= (uchar_t
*)malloc(PROM_SIZE
);
fprintf(stderr
, "Malloc failed for prom image\n");
holding
= (uchar_t
*)malloc(PROM_SIZE
);
fprintf(stderr
, "Malloc failed for holding buffer\n");
memset((void *)prom
, 0xff, pad
*2);
for (i
= optind
; i
< argc
; i
++) {
printf("Scanning: %s @ %x\n", argv
[i
],
ifd
= open(argv
[i
], O_RDONLY
);
fprintf(stderr
, "%s: Can't open input file %s\n",
if ((statbuf
.st_size
> pad
) && (!verify
)) {
fprintf(stderr
, "%s: Individual file too large"
" for current pad size\n", argv
[0]);
memset((void *)holding
, 0xff, pad
);
rlen
= read(ifd
, holding
, statbuf
.st_size
);
if (rlen
!= statbuf
.st_size
) {
printf("Short read: %d \n", rlen
);
memcpy((void *)insert_ptr
, (void *)holding
, statbuf
.st_size
);
if (do_dropin(0, (obmd_t
*)holding
, statbuf
.st_size
)) {
memcpy((void *)insert_ptr
, (void *)holding
,
insert_ptr
+= ROUNDUP(statbuf
.st_size
);
/* If we pad we only pad the first file. */
uint32_t *cptr
= (uint32_t *)prom
;
if (nfiles
> 1) mypad
= pad
*2;
crc
= crc32(mypad
-sizeof (int32_t), prom
, -1);
if (verbose
) printf("Computed CRC32 %x\n", crc
);
cptr
[(mypad
/sizeof (uint32_t))-1] = crc
;
int ofd
= open(ofile
, (O_CREAT
|O_RDWR
|O_TRUNC
), 0666);
open_failure(argv
[0], ofile
);
if (verbose
) printf("Writing A.OUT header\n");
header
[1] = (insert_ptr
-prom
);
write(ofd
, header
, 0x20);
if (verbose
) printf("Writing binary file\n");
write(ofd
, prom
, (insert_ptr
-prom
));
* Create two files for standalone flash utility. Names
* will be <output>.openboot.bin and <output>.post.bin
printf("\nIgnoring the -a flag since the "
"-s flag was also set.\n");
for (d
= 0; d
< 2; d
++) {
(void) strcpy(buff
, ofile
);
(void) strcat(buff
, ".openboot.bin");
(void) strcat(buff
, ".post.bin");
(O_CREAT
|O_RDWR
|O_TRUNC
), 0666);
open_failure(argv
[0], ofile
);
printf("Writing binary file %s.\n", buff
);
write(ofd
, (prom
+pad
), pad
);
open_failure(char *progname
, char *ofilename
)
fprintf(stderr
, "%s: open %s for writing failed.\n",