* ========== Copyright Header Begin ==========================================
* Hypervisor Software File: makedi.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: @(#)makedi.c 1.12 06/02/16
* copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
* copyright: Use is subject to license terms.
#define MAX_DI (4*1048*1024)
static int group_mode
= 0;
int comp(unsigned char *src
, int size
, unsigned char *dest
);
"%s: [-c] [-v] input1 name1 .. inputn namen\n"
" -g : group mode using src,dropin-name pairs\n"
" -a : create level2 using existing dropins\n"
" -c : compress dropins\n"
" -d : list dependancies\n"
" -o : create a dropin from data\n"
" -O : overwrite any existing header\n"
"for compress mode, each input will produce a file input.di\n"
"group mode changes the format of the args a little\n"
"-g <output> name input0 name0 .. intputn namen\n"
"-a <output> name input0 input1 .. inputn\n"
"-o <output> <srcfile> <diname>\n";
fprintf(stderr
, msg
, name
);
make_dropin(char *name
, unsigned char *prom
, unsigned char *buffer
, int size
)
int crc
, i
, clen
, dlen
, compressed
;
obmd_t
*di
= (obmd_t
*)prom
;
unsigned char *dataptr
= prom
+OBMD_HDR
;
memset((void *) prom
, 0, OBMD_HDR
);
compresshdr
*chdr
= (compresshdr
*) dataptr
;
/* The magic number is always COMP */
chdr
->magic
= COMP_MAGIC
;
* This is the compression type
* currently COMP for compress
chdr
->decomp_size
= size
;
clen
= comp(buffer
, size
, dataptr
+sizeof (compresshdr
));
/* Now adjust the data size */
clen
+= sizeof (compresshdr
);
* Compression didn't help this and in fact
* has added some bytes, so we undo the compression.
memcpy((void *) dataptr
, (void *) buffer
, size
);
memcpy((void *) dataptr
, (void *) buffer
, size
);
strncpy(di
->magic
, "OBMD", 4);
fprintf(stderr
, "Error: dropin name > 15 characters\n");
fprintf(stderr
, "Error: -> %s\n", name
);
strncpy(di
->name
, name
, 15);
crc
= checksum((ushort_t
*)di
, clen
+OBMD_HDR
);
printf(" Name: %s size = %lx", di
->name
, di
->size
);
printf(" (-%d%%)", ((size
-clen
)*100)/size
);
printf(" checksum = %x ", di
->chksum
);
if (verbose
) printf("(+%d)", (dlen
&3));
for (i
= (3-(dlen
&3)); i
>= 0; i
--, dlen
++) *(pptr
+i
) = 1;
if (verbose
) printf("\n");
make_dropin_name(char *name
)
dot
= strrchr(name
, '/');
dot
= strrchr(outname
, '.');
write_dropin(char *argv
[], char *name
, unsigned char *prom
, int dlen
)
ofd
= open(name
, O_CREAT
|O_TRUNC
|O_RDWR
, 0666);
fprintf(stderr
, "%s: Can't open output file %s\n",
fprintf(stderr
, "%s: Output %s exceeds %d bytes\n",
if (write(ofd
, prom
, dlen
) != dlen
) {
fprintf(stderr
, "%s: Short write on %s\n",
* makedi [-c] <source> <dropin-name> [<source> <dropin-name>]
main(int argc
, char **argv
)
char *group_file
, *outfile
= NULL
;
uchar_t
*holding
, *insert_pt
;
while ((c
= getopt(argc
, argv
, "acCOvstdgGo:")) != EOF
)
if (list
) compress
= 0, verbose
= 0;
insert_pt
= prom
= (uchar_t
*)malloc(MAX_DI
);
fprintf(stderr
, "Malloc failed for dropin image\n");
holding
= (uchar_t
*)malloc(MAX_DI
);
fprintf(stderr
, "Malloc failed for holding buffer\n");
memset((void *) prom
, 0xff, MAX_DI
);
if (group_mode
|| append_mode
) {
if (argv
[optind
] == NULL
) {
fprintf(stderr
, "%s: Missing group name\n", argv
[0]);
group_file
= strdup(make_dropin_name(argv
[optind
]));
group_name
= argv
[optind
+1];
if (argv
[optind
+1] == NULL
) {
fprintf(stderr
, "%s: Missing dropin name for %s\n",
* reserve space for the dropin header and marker
insert_pt
+= sizeof (obme_t
);
for (i
= optind
; i
< argc
; i
+= arg_step
) {
if ((!append_mode
) && (argv
[i
+1] == NULL
)) {
fprintf(stderr
, "%s: Missing dropin name for %s\n",
outname
= make_dropin_name(argv
[i
]);
printf("%s ", group_file
);
if (group_mode
|| append_mode
)
printf("%s: %s\n", outname
, argv
[i
]);
if (verbose
> 1) printf("Loading: %s\n", argv
[i
]);
ifd
= open(argv
[i
], O_RDONLY
);
"%s: Can't open input file %s\n",
fprintf(stderr
, "%s: Input %s exceeds %d bytes\n",
argv
[0], argv
[i
], MAX_DI
);
memset((void *) holding
, 0xff, MAX_DI
);
tmp
= read(ifd
, holding
, len
);
fprintf(stderr
, "%s: Short read on %s\n",
if (group_mode
|| append_mode
)
printf("Including: %s,", argv
[i
]);
printf("Writing: %s,", outname
);
if (diupdate
&& (strncmp(di
->magic
, "OBMD", 4) == 0)) {
dataptr
= (uint_t
*)((uchar_t
*)di
+ sizeof (obmd_t
));
if ((dataptr
[0] == COMP_MAGIC
) &&
(dataptr
[1] == di
->size
)) {
* We can do nothing with dropins that are
printf(" Name: %s size = %lx (COMP)",
printf(" checksum = %x\n", di
->chksum
);
if ((group_mode
) || (append_mode
)) {
memcpy((void *) insert_pt
,
* Strip the dropin header off to leave the
* raw data and then compress it
diname
= strdup(di
->name
);
(void *) (holding
+OBMD_HDR
),
dlen
= make_dropin(diname
,
insert_pt
, holding
, len
);
"%s: append_mode requires you to provide"
dlen
= make_dropin(argv
[i
+1],
insert_pt
, (holding
+ OBMD_HDR
),
dlen
= make_dropin(argv
[i
+1],
insert_pt
, holding
, len
);
if (group_mode
|| append_mode
) {
insert_pt
+= (dlen
+ 3) & ~3;
write_dropin(argv
, outname
, prom
, dlen
);
if (group_mode
|| append_mode
) {
bytes
= insert_pt
- prom
;
for (i
= (4-(bytes
&3)); i
> 0; i
--, bytes
++)
for (i
= 4; i
> 0; i
--, bytes
++) *insert_pt
++ = 0xff;
if (verbose
) printf("Writing: %s,", group_file
);
strncpy((char *)prom
, "OBME", 4);
memcpy((void *)holding
, (void *)prom
, bytes
);
flen
= make_dropin(group_name
, prom
, holding
, bytes
);
write_dropin(argv
, group_file
, prom
, flen
);