2006-09-20 22:42:48 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) 2004-2006 Laurent Vivier <Laurent@lvivier.info>
|
|
|
|
*
|
|
|
|
* Some parts from mkisofs/apple_driver.c, (c) James Pearson 17/5/98
|
|
|
|
*
|
|
|
|
* By extracting a driver from an Apple CD, you become liable to obey
|
|
|
|
* Apple Computer, Inc. Software License Agreements.
|
|
|
|
*
|
|
|
|
*/
|
2006-10-20 07:57:29 +00:00
|
|
|
|
|
|
|
#define DRIVER_SIZE (64*1024)
|
|
|
|
|
2006-11-03 12:39:55 +00:00
|
|
|
#define FIRST_PATH "/boot/emile/first_scsi"
|
|
|
|
#define SECOND_PATH "/boot/emile/m68k-second_scsi"
|
2008-08-13 12:29:19 +00:00
|
|
|
#define DRIVER_PATH "/lib/emile/apple_driver"
|
2006-11-03 12:39:55 +00:00
|
|
|
|
2006-09-20 22:42:48 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
#include <libmap.h>
|
2006-09-20 22:42:48 +00:00
|
|
|
#include <emile.h>
|
|
|
|
#include <libemile.h>
|
|
|
|
#include <libiso9660.h>
|
|
|
|
#include <libstream.h>
|
|
|
|
|
|
|
|
#include "device.h"
|
|
|
|
|
2008-08-12 09:22:49 +00:00
|
|
|
#define COMMAND "/usr/bin/mkisofs %s -hfs -joliet -R -boot-hfs-file %s -graft-points -o %s"
|
2006-09-20 22:42:48 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_NONE = 0,
|
|
|
|
ARG_HELP ='h',
|
|
|
|
ARG_VERBOSE = 'v',
|
|
|
|
ARG_FIRST = 'f',
|
|
|
|
ARG_SECOND = 's',
|
|
|
|
ARG_KERNEL = 'k',
|
|
|
|
ARG_RAMDISK = 'r',
|
|
|
|
ARG_APPEND = 'a',
|
|
|
|
ARG_APPLEDRIVER = 'd',
|
2008-08-12 09:22:49 +00:00
|
|
|
ARG_EMILEDRIVER = 'e',
|
2008-08-12 13:51:49 +00:00
|
|
|
ARG_CONFIG = 'c',
|
2006-09-20 22:42:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
|
|
|
{"help", 0, NULL, ARG_HELP },
|
|
|
|
{"verbose", 0, NULL, ARG_VERBOSE },
|
|
|
|
{"first", 1, NULL, ARG_FIRST },
|
|
|
|
{"second", 1, NULL, ARG_SECOND },
|
|
|
|
{"kernel", 1, NULL, ARG_KERNEL },
|
|
|
|
{"ramdisk", 1, NULL, ARG_RAMDISK },
|
|
|
|
{"append", 1, NULL, ARG_APPEND },
|
|
|
|
{"appledriver", 1, NULL, ARG_APPLEDRIVER },
|
2008-08-12 09:22:49 +00:00
|
|
|
{"emiledriver", 1, NULL, ARG_EMILEDRIVER },
|
2008-08-12 13:51:49 +00:00
|
|
|
{"config", 1, NULL, ARG_CONFIG },
|
2006-09-20 22:42:48 +00:00
|
|
|
{NULL, 0, NULL, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static void usage(int argc, char** argv)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage %s [FLAGS] filename pathspec [pathspec ...]\n",
|
|
|
|
argv[0]);
|
|
|
|
fprintf(stderr, "Create and EMILE bootable CDROM\n");
|
2008-07-21 22:22:06 +00:00
|
|
|
fprintf(stderr, " -h, --help display this text\n");
|
|
|
|
fprintf(stderr, " -v, --verbose verbose mode\n");
|
|
|
|
fprintf(stderr, " -f, --first=FILE "
|
|
|
|
"first level to copy to CDROM\n");
|
|
|
|
fprintf(stderr, " -s, --second=FILE "
|
|
|
|
"second level to copy to CDROM\n");
|
|
|
|
fprintf(stderr, " -k, --kernel=PATH "
|
|
|
|
"path of the kernel on CDROM\n");
|
|
|
|
fprintf(stderr, " -r, --ramdisk=PATH "
|
|
|
|
"path of ramdisk on CDROM\n");
|
|
|
|
fprintf(stderr, " -a, --append=ARG "
|
|
|
|
"set kernel command line\n");
|
|
|
|
fprintf(stderr, " -d, --appledriver=FILE "
|
|
|
|
"appledriver to copy to CDROM\n");
|
2008-08-12 09:22:49 +00:00
|
|
|
fprintf(stderr, " -e, --emiledriver=FILE "
|
|
|
|
"emiledriver to copy to CDROM\n");
|
2008-08-12 13:51:49 +00:00
|
|
|
fprintf(stderr, " -c, --config=FILE "
|
|
|
|
"path of configuration file\n");
|
2006-09-20 22:42:48 +00:00
|
|
|
fprintf(stderr, "\nbuild: \n%s\n", SIGNATURE);
|
|
|
|
}
|
|
|
|
|
2006-09-24 22:46:26 +00:00
|
|
|
#define BLOCKSIZE (2048)
|
|
|
|
|
2006-09-20 22:42:48 +00:00
|
|
|
static int create_apple_driver(char *temp, char *appledriver, char *first_level)
|
|
|
|
{
|
|
|
|
struct DriverDescriptor block0;
|
|
|
|
struct Partition map2048;
|
|
|
|
struct Partition map512;
|
|
|
|
FILE* fd;
|
2006-09-24 22:46:26 +00:00
|
|
|
int fd_driver;
|
2006-09-20 22:42:48 +00:00
|
|
|
char *buffer;
|
2007-02-24 14:02:40 +00:00
|
|
|
unsigned char *driver;
|
2006-09-20 22:42:48 +00:00
|
|
|
int ret;
|
2006-09-24 22:46:26 +00:00
|
|
|
struct stat st;
|
2008-08-12 09:22:49 +00:00
|
|
|
int driver_size;
|
2006-09-24 22:46:26 +00:00
|
|
|
|
|
|
|
/* read apple driver */
|
|
|
|
|
|
|
|
fd_driver = open(appledriver, O_RDONLY);
|
|
|
|
if (fd_driver == -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Cannot open %s\n", appledriver);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fstat(fd_driver, &st);
|
2008-08-12 09:22:49 +00:00
|
|
|
driver_size = ((st.st_size + DRIVER_SIZE - 1) / DRIVER_SIZE) *
|
|
|
|
DRIVER_SIZE;
|
|
|
|
driver = malloc(driver_size);
|
|
|
|
memset(driver, 0, driver_size);
|
2006-09-24 22:46:26 +00:00
|
|
|
if (driver == NULL)
|
|
|
|
{
|
2008-08-13 12:29:19 +00:00
|
|
|
fprintf(stderr, "Cannot malloc %d bytes\n", driver_size);
|
2006-09-24 22:46:26 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ret = read(fd_driver, driver, st.st_size);
|
|
|
|
|
|
|
|
close(fd_driver);
|
2006-09-20 22:42:48 +00:00
|
|
|
|
|
|
|
/* HFS CD Label Block 512 bytes
|
|
|
|
* Driver Partition Map (for 2048 byte blocks) 512 bytes
|
|
|
|
* Driver Partition Map (for 512 byte blocks) 512 bytes
|
|
|
|
* Empty 512 bytes
|
|
|
|
* Driver Partition N x 2048 bytes
|
|
|
|
* HFS Partition Boot Block 1024 bytes
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
memset(&block0, 0, sizeof(block0));
|
2007-02-24 14:02:40 +00:00
|
|
|
write_short((u_int16_t*)&block0.Sig, DD_SIGNATURE);
|
|
|
|
write_short((u_int16_t*)&block0.BlkSize, BLOCKSIZE);
|
|
|
|
write_long((u_int32_t*)&block0.BlkCount, 0); // set by mkisofs
|
|
|
|
write_short((u_int16_t*)&block0.DevType, 1);
|
|
|
|
write_short((u_int16_t*)&block0.DevId, 1);
|
|
|
|
write_long((u_int32_t*)&block0.Data, 0);
|
|
|
|
write_short((u_int16_t*)&block0.DrvrCount, 1);
|
|
|
|
|
|
|
|
write_long((u_int32_t*)&block0.DrvInfo[0].Block, 0);
|
2008-08-12 09:22:49 +00:00
|
|
|
write_short((u_int16_t*)&block0.DrvInfo[0].Size, (driver_size + BLOCKSIZE - 1) / BLOCKSIZE);
|
2007-02-24 14:02:40 +00:00
|
|
|
write_short((u_int16_t*)&block0.DrvInfo[0].Type, kDriverTypeMacSCSI);
|
2006-09-20 22:42:48 +00:00
|
|
|
|
|
|
|
memset(&map512, 0, sizeof(map512));
|
2007-02-24 14:02:40 +00:00
|
|
|
write_short((u_int16_t*)&map512.Sig, MAP_SIGNATURE);
|
2008-08-12 09:22:49 +00:00
|
|
|
write_long((u_int32_t*)&map512.PartBlkCnt, (driver_size + 512 - 1) / 512);
|
2007-02-24 14:02:40 +00:00
|
|
|
write_long((u_int32_t*)&map512.PyPartStart,0);
|
2006-09-20 22:42:48 +00:00
|
|
|
strncpy(map512.PartName, "Macintosh", 32);
|
2008-08-12 09:22:49 +00:00
|
|
|
if (first_level == NULL)
|
|
|
|
strncpy(map512.PartType, APPLE_DRIVER_EMILE, 32);
|
|
|
|
else
|
|
|
|
strncpy(map512.PartType, APPLE_DRIVER43, 32);
|
2007-02-24 14:02:40 +00:00
|
|
|
write_long((u_int32_t*)&map512.LgDataStart, 0);
|
|
|
|
write_long((u_int32_t*)&map512.DataCnt, 0);
|
|
|
|
write_long((u_int32_t*)&map512.PartStatus, kPartitionAUXIsValid |
|
2006-10-16 20:01:40 +00:00
|
|
|
kPartitionAUXIsAllocated |
|
|
|
|
kPartitionAUXIsInUse |
|
|
|
|
kPartitionAUXIsBootValid |
|
|
|
|
kPartitionAUXIsReadable |
|
|
|
|
kPartitionAUXIsWriteable |
|
|
|
|
kPartitionAUXIsBootCodePositionIndependent |
|
|
|
|
kPartitionIsChainCompatible |
|
|
|
|
kPartitionIsRealDeviceDriver);
|
2007-02-24 14:02:40 +00:00
|
|
|
write_long((u_int32_t*)&map512.LgBootStart, 0);
|
|
|
|
write_long((u_int32_t*)&map512.BootSize, st.st_size);
|
|
|
|
write_long((u_int32_t*)&map512.BootAddr, 0);
|
|
|
|
write_long((u_int32_t*)&map512.BootAddr2, 0);
|
|
|
|
write_long((u_int32_t*)&map512.BootEntry, 0);
|
|
|
|
write_long((u_int32_t*)&map512.BootEntry2, 0);
|
|
|
|
write_long((u_int32_t*)&map512.BootCksum, emile_checksum(driver, st.st_size));
|
2006-09-20 22:42:48 +00:00
|
|
|
strncpy(map512.Processor, "68000", 16);
|
2006-10-16 20:01:40 +00:00
|
|
|
write_long((u_int32_t*)map512.Pad, kSCSICDDriverSignature);
|
2006-09-20 22:42:48 +00:00
|
|
|
|
|
|
|
map2048 = map512;
|
2008-08-12 09:22:49 +00:00
|
|
|
write_long((u_int32_t*)&map2048.PartBlkCnt, (driver_size + BLOCKSIZE - 1) / BLOCKSIZE);
|
2006-09-23 22:13:26 +00:00
|
|
|
|
2006-09-20 22:42:48 +00:00
|
|
|
strcpy(temp, "/tmp/emile-mkisofs-XXXXXX");
|
|
|
|
mkstemp(temp);
|
|
|
|
fd = fopen(temp, "w");
|
|
|
|
|
|
|
|
ret = fwrite(&block0, 1, sizeof(block0), fd);
|
|
|
|
ret = fwrite(&map2048, 1, sizeof(map2048), fd);
|
|
|
|
ret = fwrite(&map512, 1, sizeof(map512), fd);
|
|
|
|
memset(&map512, 0, sizeof(map512));
|
|
|
|
ret = fwrite(&map512, 1, sizeof(map512), fd);
|
|
|
|
|
2008-08-12 09:22:49 +00:00
|
|
|
fwrite(driver, driver_size, 1, fd);
|
2006-09-24 22:46:26 +00:00
|
|
|
free(driver);
|
|
|
|
|
|
|
|
/* read and write bootblock */
|
2006-09-20 22:42:48 +00:00
|
|
|
|
|
|
|
buffer = malloc(1024);
|
2008-08-12 09:22:49 +00:00
|
|
|
if (first_level == NULL) {
|
|
|
|
memset(buffer, 0, 1024);
|
|
|
|
/* genisoimage needs the bootblock signature */
|
|
|
|
buffer[0] = 0x4c;
|
|
|
|
buffer[1] = 0x4b;
|
|
|
|
} else {
|
|
|
|
fd_driver = open(first_level, O_RDONLY);
|
|
|
|
if (fd_driver == -1)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: Cannot open first level \"%s\"\n",
|
2006-11-03 12:39:55 +00:00
|
|
|
first_level);
|
2008-08-12 09:22:49 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
read(fd_driver, buffer, 1024);
|
|
|
|
close(fd_driver);
|
2006-11-03 12:39:55 +00:00
|
|
|
}
|
2008-08-12 09:22:49 +00:00
|
|
|
|
2006-09-20 22:42:48 +00:00
|
|
|
fwrite(buffer, 1024, 1, fd);
|
|
|
|
free(buffer);
|
|
|
|
fclose(fd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_second_position(char *image, char *name, int *second_offset, int *second_size)
|
|
|
|
{
|
|
|
|
device_io_t device;
|
2008-04-20 16:35:55 +00:00
|
|
|
stream_FILE* file;
|
|
|
|
stream_VOLUME *volume;
|
|
|
|
struct stream_stat st;
|
2006-09-20 22:42:48 +00:00
|
|
|
|
2007-10-09 19:29:13 +00:00
|
|
|
device_sector_size = 2048;
|
|
|
|
device.data = (void*)device_open(image, O_RDONLY);
|
2006-09-20 22:42:48 +00:00
|
|
|
device.read_sector = (stream_read_sector_t)device_read_sector;
|
|
|
|
device.close = (stream_close_t)device_close;
|
2007-10-10 16:47:03 +00:00
|
|
|
device.get_blocksize = (stream_get_blocksize_t)device_get_blocksize;
|
2006-09-20 22:42:48 +00:00
|
|
|
|
|
|
|
volume = iso9660_mount(&device);
|
|
|
|
if (volume == NULL)
|
2006-11-03 12:39:55 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Cannot open \"%s\"\n", image);
|
2006-09-20 22:42:48 +00:00
|
|
|
return 1;
|
2006-11-03 12:39:55 +00:00
|
|
|
}
|
2006-09-20 22:42:48 +00:00
|
|
|
|
|
|
|
file = iso9660_open(volume, name);
|
2006-11-03 12:39:55 +00:00
|
|
|
if (file == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Cannot locate \"%s\" in the image\n", name);
|
|
|
|
return 2;
|
|
|
|
}
|
2006-09-20 22:42:48 +00:00
|
|
|
|
2008-04-20 16:35:55 +00:00
|
|
|
iso9660_fstat(file, &st);
|
|
|
|
|
|
|
|
*second_offset = st.st_base * 4;
|
|
|
|
*second_size = st.st_size;
|
2006-09-20 22:42:48 +00:00
|
|
|
|
|
|
|
iso9660_close(file);
|
|
|
|
iso9660_umount(volume);
|
|
|
|
device_close(device.data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-12 13:51:49 +00:00
|
|
|
static int set_second(char *image, int second_offset,
|
|
|
|
char *kernel_image, char *cmdline, char *ramdisk)
|
2006-09-20 22:42:48 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
fd = open(image, O_RDWR);
|
|
|
|
lseek(fd, second_offset * 512, SEEK_SET);
|
2006-10-18 18:13:35 +00:00
|
|
|
ret = emile_second_set_param(fd, kernel_image, cmdline, ramdisk);
|
2006-09-20 22:42:48 +00:00
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-08-12 13:51:49 +00:00
|
|
|
static int set_config(char *image, int second_offset, char *config)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
char c[512];
|
|
|
|
|
|
|
|
sprintf(c, "configuration %s\n", config);
|
|
|
|
|
|
|
|
fd = open(image, O_RDWR);
|
|
|
|
lseek(fd, second_offset * 512, SEEK_SET);
|
|
|
|
emile_second_set_configuration(fd, (int8_t*)c);
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-09-20 22:42:48 +00:00
|
|
|
static int set_first(char *image, int drive_num, int second_offset, int second_size)
|
|
|
|
{
|
|
|
|
int fd;
|
2007-10-04 20:55:52 +00:00
|
|
|
map_t* map;
|
2006-09-20 22:42:48 +00:00
|
|
|
int start, count;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
int boottype;
|
|
|
|
char bootblock[BOOTBLOCK_SIZE];
|
2007-10-09 19:29:13 +00:00
|
|
|
device_io_t device;
|
|
|
|
|
|
|
|
device_sector_size = 2048;
|
|
|
|
device.data = (void*)device_open(image, O_RDONLY);
|
|
|
|
device.read_sector = (stream_read_sector_t)device_read_sector;
|
|
|
|
device.close = (stream_close_t)device_close;
|
2007-10-10 16:47:03 +00:00
|
|
|
device.get_blocksize = (stream_get_blocksize_t)device_get_blocksize;
|
2006-09-20 22:42:48 +00:00
|
|
|
|
2007-10-09 19:29:13 +00:00
|
|
|
map = map_open(&device);
|
2007-10-04 20:55:52 +00:00
|
|
|
for (i = 0; i < map_get_number(map); i++)
|
2006-09-20 22:42:48 +00:00
|
|
|
{
|
2007-10-04 20:55:52 +00:00
|
|
|
map_read(map, i);
|
|
|
|
if ( strcmp(APPLE_HFS, map_get_partition_type(map)) == 0) {
|
|
|
|
ret = map_get_partition_geometry(map, &start, &count);
|
|
|
|
map_bootblock_read(map, bootblock);
|
|
|
|
boottype = map_bootblock_get_type(bootblock);
|
2006-09-20 22:42:48 +00:00
|
|
|
if (boottype == EMILE_BOOTBLOCK)
|
|
|
|
{
|
|
|
|
printf("Bootable HFS partition found at position %d (%d * %d)\n",
|
|
|
|
i, start, count);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-04 20:55:52 +00:00
|
|
|
map_close(map);
|
2006-09-20 22:42:48 +00:00
|
|
|
|
2007-10-04 20:55:52 +00:00
|
|
|
if (i == map_get_number(map))
|
2006-09-20 22:42:48 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
fd = open(image, O_RDWR);
|
|
|
|
ret = lseek(fd, start * 512, SEEK_SET);
|
2006-10-20 17:12:30 +00:00
|
|
|
ret = emile_first_set_param_scsi_extents(fd, 3, second_offset / 4, second_size, BLOCKSIZE);
|
2006-09-20 22:42:48 +00:00
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
int verbose = 0;
|
|
|
|
int option_index = 0;
|
|
|
|
char* first_level = NULL;
|
|
|
|
char* second_level = NULL;
|
|
|
|
char* kernel_image = NULL;
|
|
|
|
char* ramdisk = NULL;
|
|
|
|
char* image = NULL;
|
|
|
|
char* appledriver = NULL;
|
2008-08-12 09:22:49 +00:00
|
|
|
char* emiledriver = NULL;
|
2006-09-20 22:42:48 +00:00
|
|
|
char *cmdline = NULL;
|
2008-08-12 13:51:49 +00:00
|
|
|
char *conffile = NULL;
|
2006-09-20 22:42:48 +00:00
|
|
|
int c;
|
|
|
|
char temp[256];
|
|
|
|
int i;
|
|
|
|
char second_on_iso[256];
|
|
|
|
int second_offset;
|
|
|
|
int second_size;
|
|
|
|
char *buffer;
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
2008-08-13 12:29:19 +00:00
|
|
|
c = getopt_long(argc, argv, "hvf:s:k:r:d:i:a:e:c:",
|
|
|
|
long_options, &option_index);
|
2006-09-20 22:42:48 +00:00
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
switch(c)
|
|
|
|
{
|
|
|
|
case ARG_HELP:
|
|
|
|
usage(argc, argv);
|
|
|
|
return 0;
|
|
|
|
case ARG_VERBOSE:
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
|
|
|
case ARG_FIRST:
|
|
|
|
first_level = optarg;
|
|
|
|
break;
|
|
|
|
case ARG_SECOND:
|
|
|
|
second_level = optarg;
|
|
|
|
break;
|
|
|
|
case ARG_KERNEL:
|
|
|
|
kernel_image = optarg;
|
|
|
|
break;
|
|
|
|
case ARG_RAMDISK:
|
|
|
|
ramdisk = optarg;
|
|
|
|
break;
|
|
|
|
case ARG_APPEND:
|
|
|
|
cmdline = optarg;
|
|
|
|
break;
|
|
|
|
case ARG_APPLEDRIVER:
|
|
|
|
appledriver = optarg;
|
|
|
|
break;
|
2008-08-12 09:22:49 +00:00
|
|
|
case ARG_EMILEDRIVER:
|
|
|
|
emiledriver = optarg;
|
|
|
|
break;
|
2008-08-12 13:51:49 +00:00
|
|
|
case ARG_CONFIG:
|
|
|
|
conffile = optarg;
|
|
|
|
break;
|
2006-09-20 22:42:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (optind < argc)
|
|
|
|
image = argv[optind++];
|
|
|
|
|
|
|
|
if (image == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"ERROR: you must provide a filename to write image\n");
|
|
|
|
usage(argc, argv);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-08-13 12:29:19 +00:00
|
|
|
if (appledriver == NULL && emiledriver == NULL)
|
|
|
|
emiledriver = DRIVER_PATH;
|
|
|
|
|
2008-08-12 13:51:49 +00:00
|
|
|
if (conffile && (kernel_image || ramdisk || cmdline)) {
|
|
|
|
fprintf(stderr, "ERROR: --config cannot be used with --kernel,"
|
|
|
|
" --ramdisk or --append\n");
|
|
|
|
usage(argc, argv);
|
|
|
|
return 1;
|
|
|
|
}
|
2008-08-12 09:22:49 +00:00
|
|
|
if (emiledriver == NULL) {
|
|
|
|
if (first_level == NULL)
|
|
|
|
first_level = FIRST_PATH;
|
|
|
|
|
|
|
|
if (second_level == NULL)
|
|
|
|
second_level = SECOND_PATH;
|
|
|
|
|
|
|
|
if (create_apple_driver(temp, appledriver, first_level))
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
if (first_level != NULL ||
|
|
|
|
second_level != NULL ||
|
|
|
|
appledriver != NULL) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"ERROR: --emiledriver cannot be used with "
|
|
|
|
"--appledriver, --first or -second\n");
|
|
|
|
usage(argc, argv);
|
|
|
|
return 1;
|
|
|
|
}
|
2006-11-03 12:39:55 +00:00
|
|
|
|
2008-08-12 13:51:49 +00:00
|
|
|
if (conffile)
|
|
|
|
set_config(emiledriver, 0, conffile);
|
|
|
|
else
|
|
|
|
set_second(emiledriver, 0,
|
|
|
|
kernel_image, cmdline, ramdisk);
|
2008-08-12 09:22:49 +00:00
|
|
|
if (create_apple_driver(temp, emiledriver, first_level))
|
|
|
|
return 1;
|
2006-11-03 12:39:55 +00:00
|
|
|
}
|
|
|
|
|
2006-09-20 22:42:48 +00:00
|
|
|
buffer = malloc(65536);
|
|
|
|
|
2008-08-12 09:22:49 +00:00
|
|
|
if (second_level) {
|
|
|
|
strcpy(second_on_iso, kernel_image);
|
|
|
|
dirname(second_on_iso);
|
|
|
|
strcat(second_on_iso, "/emile");
|
|
|
|
if (verbose)
|
|
|
|
sprintf(buffer, COMMAND " %s=%s", "",
|
|
|
|
temp, image, second_on_iso, second_level);
|
|
|
|
else
|
|
|
|
sprintf(buffer, COMMAND " %s=%s", "-quiet",
|
|
|
|
temp, image, second_on_iso, second_level);
|
|
|
|
} else {
|
|
|
|
if (verbose)
|
|
|
|
sprintf(buffer, COMMAND, "", temp, image);
|
|
|
|
else
|
|
|
|
sprintf(buffer, COMMAND, "-quiet", temp, image);
|
|
|
|
}
|
2006-09-20 22:42:48 +00:00
|
|
|
|
|
|
|
for (i = optind; i < argc; i++)
|
|
|
|
{
|
|
|
|
strcat(buffer, " ");
|
|
|
|
strcat(buffer, argv[i]);
|
|
|
|
}
|
|
|
|
printf("%s\n",buffer);
|
|
|
|
system(buffer);
|
|
|
|
|
|
|
|
free(buffer);
|
|
|
|
|
|
|
|
unlink(temp);
|
|
|
|
|
2008-08-12 09:22:49 +00:00
|
|
|
if (second_level) {
|
|
|
|
if (get_second_position(image, second_on_iso,
|
|
|
|
&second_offset, &second_size))
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
2006-09-20 22:42:48 +00:00
|
|
|
|
2008-08-12 09:22:49 +00:00
|
|
|
printf("Second is at %d * %d\n", second_offset, second_size);
|
2006-09-20 23:08:48 +00:00
|
|
|
|
2008-08-12 09:22:49 +00:00
|
|
|
set_first(image, 3, second_offset, second_size);
|
2006-09-20 22:42:48 +00:00
|
|
|
|
2008-08-12 13:51:49 +00:00
|
|
|
if (conffile)
|
|
|
|
set_config(emiledriver, second_offset, conffile);
|
|
|
|
else
|
|
|
|
set_second(image, second_offset,
|
|
|
|
kernel_image, cmdline, ramdisk);
|
2008-08-12 09:22:49 +00:00
|
|
|
}
|
2006-09-20 22:42:48 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|