EMILE/second/load.c

112 lines
1.9 KiB
C
Raw Normal View History

2004-05-26 21:59:06 +00:00
/*
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
*/
#include <stdio.h>
#include <malloc.h>
2005-05-22 21:14:41 +00:00
#include <string.h>
2004-07-12 21:32:44 +00:00
#include "bank.h"
#include "misc.h"
2004-05-26 21:59:06 +00:00
#include "glue.h"
2004-12-03 00:19:02 +00:00
#include "head.h"
2004-05-26 21:59:06 +00:00
#include "load.h"
#include "uncompress.h"
2004-05-26 21:59:06 +00:00
2004-12-03 00:19:02 +00:00
#ifdef SCSI_SUPPORT
#include "scsi.h"
static int load_container(struct emile_container* container, char* image)
2004-05-26 21:59:06 +00:00
{
2004-12-03 00:19:02 +00:00
int target;
int i;
2004-05-26 21:59:06 +00:00
int err;
2004-12-03 00:19:02 +00:00
target = container->unit_id;
2004-05-26 21:59:06 +00:00
2004-12-03 00:19:02 +00:00
i = 0;
while (container->blocks[i].count != 0)
2004-05-26 21:59:06 +00:00
{
2004-12-03 00:19:02 +00:00
err = scsi_READ(target, container->blocks[i].offset,
container->blocks[i].count,
image,
container->block_size * container->blocks[i].count);
if (err != noErr)
return -1;
2004-12-03 00:19:02 +00:00
image += container->block_size * container->blocks[i].count;
i++;
2004-05-26 21:59:06 +00:00
}
return 0;
2004-12-03 00:19:02 +00:00
}
#else /* SCSI_SUPPORT */
static int load_blocks(unsigned long offset, unsigned long size, char *image)
2004-12-03 00:19:02 +00:00
{
int err;
ParamBlockRec_t param_block;
2004-06-07 18:51:51 +00:00
2004-05-26 21:59:06 +00:00
memset(&param_block, 0, sizeof(param_block));
param_block.ioBuffer = (unsigned long)image;
2004-12-03 00:19:02 +00:00
param_block.ioVRefNum = 1;
2004-05-26 21:59:06 +00:00
param_block.ioRefNum = -5;
param_block.ioReqCount = size;
param_block.ioPosMode = fsFromStart;
param_block.ioPosOffset = offset;
err = PBReadSync(&param_block);
if (err != noErr)
return -1;
2004-05-26 21:59:06 +00:00
return 0;
2004-05-26 21:59:06 +00:00
}
2004-12-03 00:19:02 +00:00
#endif /* SCSI_SUPPORT */
int load_image(unsigned long offset, unsigned long size, char *image)
2004-12-03 00:19:02 +00:00
{
if (size == 0)
return -1;
2004-12-03 00:19:02 +00:00
if (image == NULL)
return -1;
2004-12-03 00:19:02 +00:00
#ifdef SCSI_SUPPORT
return load_container((struct emile_container*)offset, image);
#else
return load_blocks(offset, size, image);
#endif
}
int load_gzip(unsigned long offset, unsigned long size, char *image)
{
char* gzip_image;
int ret;
/* allocate memory for image */
gzip_image = (char*)malloc(size);
if (gzip_image == NULL)
return -1;
/* load image */
ret = load_image(offset, size, gzip_image);
if (ret == -1)
return -1;
/* uncompress */
uncompress(image, gzip_image);
printf("\n");
/* free kernel image */
free(gzip_image);
return 0;
}