2004-05-21 12:42:40 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
2004-12-24 23:01:14 +00:00
|
|
|
#include <getopt.h>
|
2004-05-21 12:42:40 +00:00
|
|
|
|
2004-12-10 00:28:35 +00:00
|
|
|
#include "libemile.h"
|
2004-05-21 12:42:40 +00:00
|
|
|
|
2004-12-24 23:01:14 +00:00
|
|
|
enum {
|
|
|
|
ARG_NONE = 0,
|
|
|
|
ARG_HELP ='h',
|
|
|
|
ARG_DRIVE = 'd',
|
|
|
|
ARG_OFFSET ='o',
|
|
|
|
ARG_SIZE = 's',
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct option long_options[] =
|
|
|
|
{
|
|
|
|
{"help", 0, NULL, ARG_HELP },
|
|
|
|
{"drive", 1, NULL, ARG_DRIVE },
|
|
|
|
{"offset", 1, NULL, ARG_OFFSET },
|
|
|
|
{"size", 1, NULL, ARG_SIZE },
|
|
|
|
{NULL, 0, NULL, 0 },
|
|
|
|
};
|
|
|
|
|
2004-05-21 12:42:40 +00:00
|
|
|
static void usage(int argc, char** argv)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: %s [-d <drive>][-o <offset>][-s <size>] <image>\n", argv[0]);
|
2004-12-24 23:01:14 +00:00
|
|
|
fprintf(stderr, "Set EMILE first level boot block info\n");
|
|
|
|
fprintf(stderr, " -d, --drive <drive> set the drive number (default 1)\n");
|
|
|
|
fprintf(stderr, " -o, --offset <offset> set offset of second level in bytes\n");
|
|
|
|
fprintf(stderr, " -s, --size <size> set size of second level in bytes\n");
|
2004-05-21 12:42:40 +00:00
|
|
|
fprintf(stderr, "Display current values if no flags provided\n");
|
2004-06-03 11:09:28 +00:00
|
|
|
fprintf(stderr, "\nbuild: \n%s\n", SIGNATURE);
|
2004-05-21 12:42:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int first_tune( char* image, unsigned short tune_mask, int drive_num,
|
2004-12-10 00:28:35 +00:00
|
|
|
int second_offset, int second_size)
|
2004-05-21 12:42:40 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
fd = open(image, O_RDWR);
|
|
|
|
if (fd == -1)
|
|
|
|
{
|
|
|
|
perror("Cannot open image file");
|
|
|
|
return 2;
|
|
|
|
}
|
2004-12-24 23:01:14 +00:00
|
|
|
if (tune_mask == 0)
|
|
|
|
{
|
|
|
|
ret = emile_first_get_param(fd, &drive_num, &second_offset,
|
|
|
|
&second_size);
|
|
|
|
if (ret == 0)
|
|
|
|
{
|
|
|
|
printf("EMILE boot block identified\n\n");
|
|
|
|
printf("Drive number: %d\n", drive_num);
|
|
|
|
printf("Second level offset: %d\n", second_offset);
|
|
|
|
printf("Second level size: %d\n", second_size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("EMILE is not installed in this bootblock\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2004-05-21 12:42:40 +00:00
|
|
|
|
2004-12-10 00:28:35 +00:00
|
|
|
ret = emile_first_set_param(fd, tune_mask, drive_num, second_offset, second_size);
|
2004-05-21 12:42:40 +00:00
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
int ret;
|
2004-12-24 23:01:14 +00:00
|
|
|
int option_index;
|
|
|
|
int c;
|
|
|
|
char* image = NULL;
|
|
|
|
unsigned short tune_mask = 0;
|
2004-12-10 00:28:35 +00:00
|
|
|
int drive_num, second_offset, second_size;
|
2004-05-21 12:42:40 +00:00
|
|
|
|
2004-12-24 23:01:14 +00:00
|
|
|
while(1)
|
2004-05-21 12:42:40 +00:00
|
|
|
{
|
2004-12-24 23:01:14 +00:00
|
|
|
c = getopt_long(argc, argv, "hd:o:f:", long_options,
|
|
|
|
&option_index);
|
|
|
|
if (c == EOF)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch(c)
|
2004-05-21 12:42:40 +00:00
|
|
|
{
|
2004-12-24 23:01:14 +00:00
|
|
|
case ARG_HELP:
|
|
|
|
usage(argc, argv);
|
|
|
|
return 0;
|
|
|
|
case ARG_DRIVE:
|
2004-12-10 00:28:35 +00:00
|
|
|
tune_mask |= EMILE_FIRST_TUNE_DRIVE;
|
2004-12-24 23:01:14 +00:00
|
|
|
drive_num = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case ARG_OFFSET:
|
2004-12-10 00:28:35 +00:00
|
|
|
tune_mask |= EMILE_FIRST_TUNE_OFFSET;
|
2004-12-24 23:01:14 +00:00
|
|
|
second_offset = atoi(optarg);
|
2004-05-26 21:30:23 +00:00
|
|
|
second_offset = (second_offset + 0x1FF) & 0xFFFFFE00;
|
2004-12-24 23:01:14 +00:00
|
|
|
break;
|
|
|
|
case ARG_SIZE:
|
2004-12-10 00:28:35 +00:00
|
|
|
tune_mask |= EMILE_FIRST_TUNE_SIZE;
|
2004-12-24 23:01:14 +00:00
|
|
|
second_size = atoi(optarg);
|
2004-05-26 21:30:23 +00:00
|
|
|
second_size = (second_size + 0x1FF) & 0xFFFFFE00;
|
2004-12-24 23:01:14 +00:00
|
|
|
break;
|
2004-05-21 12:42:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-24 23:01:14 +00:00
|
|
|
if (optind < argc)
|
|
|
|
image = argv[optind];
|
|
|
|
|
2004-05-21 12:42:40 +00:00
|
|
|
if (image == NULL)
|
|
|
|
{
|
2004-12-24 23:01:14 +00:00
|
|
|
fprintf(stderr, "ERROR: Missing filename to apply tuning\n");
|
2004-05-21 12:42:40 +00:00
|
|
|
usage(argc, argv);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-12-10 00:28:35 +00:00
|
|
|
ret = first_tune( image, tune_mask, drive_num, second_offset, second_size);
|
2004-12-24 23:01:14 +00:00
|
|
|
switch(ret)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case EEMILE_CANNOT_WRITE_FIRST:
|
|
|
|
fprintf(stderr, "ERROR: cannot write to file\n");
|
|
|
|
break;
|
|
|
|
case EEMILE_UNKNOWN_FIRST:
|
|
|
|
fprintf(stderr, "ERROR: unknown file format\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "ERROR: unknowm error :-P\n");
|
|
|
|
break;
|
|
|
|
}
|
2004-05-21 12:42:40 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|