mirror of
https://github.com/vivier/EMILE.git
synced 2025-08-09 13:25:29 +00:00
move to EM06
This commit is contained in:
115
libemile/emile_second_create_mapfile.c
Normal file
115
libemile/emile_second_create_mapfile.c
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* (c) 2005 Laurent Vivier <LaurentVivier@wanadoo.fr>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#include "libemile.h"
|
||||||
|
|
||||||
|
#define MAPFILE_SIZE 4096
|
||||||
|
|
||||||
|
struct emile_container *emile_second_create_mapfile(char *mapfile, char* kernel)
|
||||||
|
{
|
||||||
|
struct emile_container *container;
|
||||||
|
int fd;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
container = (struct emile_container *)malloc(MAPFILE_SIZE);
|
||||||
|
if (container == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: cannot allocate memory for container\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* create container of the kernel */
|
||||||
|
|
||||||
|
fd = open(kernel, O_RDONLY);
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
free(container);
|
||||||
|
fprintf(stderr, "ERROR: cannot open kernel\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = emile_scsi_create_container(fd, container,
|
||||||
|
(MAPFILE_SIZE - sizeof(struct emile_container)) / sizeof(struct emile_block));
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: cannot fill container\n");
|
||||||
|
free(container);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* write container to map file */
|
||||||
|
|
||||||
|
fd = open(mapfile, O_CREAT | O_EXCL | O_WRONLY);
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: cannot create map file (%s)\n", mapfile);
|
||||||
|
free(container);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = write(fd, container, MAPFILE_SIZE);
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
if (ret != MAPFILE_SIZE)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: cannot write map file (%s)\n", mapfile);
|
||||||
|
free(container);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* now, we must know where is the map file */
|
||||||
|
|
||||||
|
fd = open(mapfile, O_RDONLY);
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: cannot open map file to read (%s)\n", mapfile);
|
||||||
|
free(container);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = emile_scsi_create_container(fd, container,
|
||||||
|
(MAPFILE_SIZE - sizeof(struct emile_container)) / sizeof(struct emile_block));
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: cannot map map file...\n");
|
||||||
|
free(container);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (container->size != MAPFILE_SIZE)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: map file size is bad (%d)\n", container->size);
|
||||||
|
free(container);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (container->blocks[0].count == 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: map file is empty !\n");
|
||||||
|
free(container);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (container->blocks[1].count != 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: map file is not contiguous\n");
|
||||||
|
free(container);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return container;
|
||||||
|
}
|
@@ -1,106 +0,0 @@
|
|||||||
static __attribute__((used)) char* rcsid = "$CVSHeader$";
|
|
||||||
/*
|
|
||||||
*
|
|
||||||
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "libemile.h"
|
|
||||||
#include "emile.h"
|
|
||||||
|
|
||||||
int emile_second_set_kernel_scsi(int fd, char *kernel_name)
|
|
||||||
{
|
|
||||||
int fd_kernel;
|
|
||||||
int ret;
|
|
||||||
emile_l2_header_t header;
|
|
||||||
off_t container_offset;
|
|
||||||
struct emile_container *container;
|
|
||||||
int max_blocks;
|
|
||||||
int i;
|
|
||||||
unsigned long kernel_image_size;
|
|
||||||
|
|
||||||
ret = read(fd, &header, sizeof(header));
|
|
||||||
if (ret != sizeof(header))
|
|
||||||
return EEMILE_CANNOT_READ_SECOND;
|
|
||||||
|
|
||||||
if (!EMILE_COMPAT(EMILE_04_SIGNATURE, read_long(&header.signature)))
|
|
||||||
return EEMILE_INVALID_SECOND;
|
|
||||||
|
|
||||||
container_offset = read_long(&header.kernel_image_offset);
|
|
||||||
if (container_offset == 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
ret = lseek(fd, container_offset, SEEK_SET);
|
|
||||||
if (ret != container_offset)
|
|
||||||
return EEMILE_CANNOT_READ_SECOND;
|
|
||||||
|
|
||||||
container = (struct emile_container*)
|
|
||||||
malloc(sizeof(struct emile_container));
|
|
||||||
if (container == NULL)
|
|
||||||
return EEMILE_MALLOC_ERROR;
|
|
||||||
|
|
||||||
ret = read(fd, container, sizeof(struct emile_container));
|
|
||||||
if (ret != sizeof(struct emile_container))
|
|
||||||
return EEMILE_CANNOT_READ_SECOND;
|
|
||||||
|
|
||||||
max_blocks = container->max_blocks;
|
|
||||||
|
|
||||||
free(container);
|
|
||||||
container = (struct emile_container*)
|
|
||||||
malloc(sizeof(struct emile_container)
|
|
||||||
+ max_blocks * sizeof(struct emile_block));
|
|
||||||
if (container == NULL)
|
|
||||||
return EEMILE_MALLOC_ERROR;
|
|
||||||
|
|
||||||
container->max_blocks = max_blocks;
|
|
||||||
fd_kernel = open(kernel_name, O_RDONLY);
|
|
||||||
if (fd_kernel == -1)
|
|
||||||
return EEMILE_CANNOT_READ_KERNEL;
|
|
||||||
|
|
||||||
ret = emile_scsi_create_container(fd_kernel, container);
|
|
||||||
if (ret != 0)
|
|
||||||
return ret;
|
|
||||||
close(fd_kernel);
|
|
||||||
|
|
||||||
kernel_image_size = 0;
|
|
||||||
for(i = 0; i < max_blocks; i++)
|
|
||||||
{
|
|
||||||
if (container->blocks[i].count == 0)
|
|
||||||
break;
|
|
||||||
printf("(%d, %d) ", container->blocks[i].offset,
|
|
||||||
container->blocks[i].count);
|
|
||||||
kernel_image_size += container->blocks[i].count;
|
|
||||||
}
|
|
||||||
putchar('\n');
|
|
||||||
kernel_image_size *= container->block_size;
|
|
||||||
printf("kernel image size: %ld\n", kernel_image_size);
|
|
||||||
|
|
||||||
ret = lseek(fd, container_offset, SEEK_SET);
|
|
||||||
if (ret != container_offset)
|
|
||||||
return EEMILE_CANNOT_WRITE_SECOND;
|
|
||||||
|
|
||||||
ret = write(fd, container, sizeof(struct emile_container)
|
|
||||||
+ max_blocks * sizeof(struct emile_block));
|
|
||||||
if (ret != sizeof(struct emile_container)
|
|
||||||
+ max_blocks * sizeof(struct emile_block))
|
|
||||||
return EEMILE_CANNOT_WRITE_SECOND;
|
|
||||||
|
|
||||||
ret = lseek(fd, 0, SEEK_SET);
|
|
||||||
if (ret != 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
header.kernel_image_size = kernel_image_size;
|
|
||||||
|
|
||||||
ret = write(fd, &header, sizeof(header));
|
|
||||||
if (ret != sizeof(header))
|
|
||||||
return EEMILE_CANNOT_WRITE_SECOND;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@@ -23,6 +23,7 @@ extern void scanbus(void);
|
|||||||
static char *first_path = PREFIX "/boot/emile/first_scsi";
|
static char *first_path = PREFIX "/boot/emile/first_scsi";
|
||||||
static char *second_path = PREFIX "/boot/emile/second_scsi";
|
static char *second_path = PREFIX "/boot/emile/second_scsi";
|
||||||
static char *kernel_path = PREFIX "/boot/vmlinuz";
|
static char *kernel_path = PREFIX "/boot/vmlinuz";
|
||||||
|
static char *map_path = NULL;
|
||||||
static char *backup_path = NULL;
|
static char *backup_path = NULL;
|
||||||
static char *partition = NULL;
|
static char *partition = NULL;
|
||||||
static char *append_string = NULL;
|
static char *append_string = NULL;
|
||||||
@@ -40,6 +41,7 @@ enum {
|
|||||||
ACTION_SECOND = 0x00000080,
|
ACTION_SECOND = 0x00000080,
|
||||||
ACTION_KERNEL = 0x00000100,
|
ACTION_KERNEL = 0x00000100,
|
||||||
ACTION_PARTITION = 0x00000200,
|
ACTION_PARTITION = 0x00000200,
|
||||||
|
ACTION_MAP = 0x00000400,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -56,6 +58,7 @@ enum {
|
|||||||
ARG_KERNEL = 'k',
|
ARG_KERNEL = 'k',
|
||||||
ARG_PARTITION = 'p',
|
ARG_PARTITION = 'p',
|
||||||
ARG_HELP = 'h',
|
ARG_HELP = 'h',
|
||||||
|
ARG_MAP = 'm',
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct option long_options[] =
|
static struct option long_options[] =
|
||||||
@@ -64,6 +67,7 @@ static struct option long_options[] =
|
|||||||
{"first", 1, NULL, ARG_FIRST },
|
{"first", 1, NULL, ARG_FIRST },
|
||||||
{"second", 1, NULL, ARG_SECOND },
|
{"second", 1, NULL, ARG_SECOND },
|
||||||
{"kernel", 1, NULL, ARG_KERNEL },
|
{"kernel", 1, NULL, ARG_KERNEL },
|
||||||
|
{"map", 1, NULL, ARG_MAP },
|
||||||
{"partition", 1, NULL, ARG_PARTITION },
|
{"partition", 1, NULL, ARG_PARTITION },
|
||||||
{"help", 0, NULL, ARG_HELP },
|
{"help", 0, NULL, ARG_HELP },
|
||||||
{"scanbus", 0, NULL, ARG_SCANBUS },
|
{"scanbus", 0, NULL, ARG_SCANBUS },
|
||||||
@@ -87,6 +91,7 @@ static void usage(int argc, char** argv)
|
|||||||
fprintf(stderr," -f, --first PATH set path of EMILE first level\n");
|
fprintf(stderr," -f, --first PATH set path of EMILE first level\n");
|
||||||
fprintf(stderr," -s, --second PATH set path of EMILE second level\n");
|
fprintf(stderr," -s, --second PATH set path of EMILE second level\n");
|
||||||
fprintf(stderr," -k, --kernel PATH set path of kernel\n");
|
fprintf(stderr," -k, --kernel PATH set path of kernel\n");
|
||||||
|
fprintf(stderr," -k, --map PATH set path to the EMILE kernel map file (generated)\n");
|
||||||
fprintf(stderr," -a, --append ARG set kernel command line\n");
|
fprintf(stderr," -a, --append ARG set kernel command line\n");
|
||||||
fprintf(stderr," -p, --partition DEV define device where to install boot block\n");
|
fprintf(stderr," -p, --partition DEV define device where to install boot block\n");
|
||||||
fprintf(stderr," --restore[=FILE] save current boot block from FILE\n");
|
fprintf(stderr," --restore[=FILE] save current boot block from FILE\n");
|
||||||
@@ -382,6 +387,10 @@ int main(int argc, char **argv)
|
|||||||
action |= ACTION_KERNEL;
|
action |= ACTION_KERNEL;
|
||||||
kernel_path = optarg;
|
kernel_path = optarg;
|
||||||
break;
|
break;
|
||||||
|
case ARG_MAP:
|
||||||
|
action |= ACTION_MAP;
|
||||||
|
map_path = optarg;
|
||||||
|
break;
|
||||||
case ARG_PARTITION:
|
case ARG_PARTITION:
|
||||||
action |= ACTION_PARTITION;
|
action |= ACTION_PARTITION;
|
||||||
partition = optarg;
|
partition = optarg;
|
||||||
@@ -646,10 +655,23 @@ int main(int argc, char **argv)
|
|||||||
printf("Bootblock backup successfully done.\n");
|
printf("Bootblock backup successfully done.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (map_path == NULL)
|
||||||
|
{
|
||||||
|
map_path = (char*)malloc(strlen(kernel_path) + 5);
|
||||||
|
if (map_path == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,
|
||||||
|
"ERROR: cannot allocate memory\n");
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
sprintf(map_path, "%s.map", kernel_path);
|
||||||
|
}
|
||||||
|
|
||||||
printf("partition: %s\n", partition);
|
printf("partition: %s\n", partition);
|
||||||
printf("first: %s\n", first_path);
|
printf("first: %s\n", first_path);
|
||||||
printf("second: %s\n", second_path);
|
printf("second: %s\n", second_path);
|
||||||
printf("kernel: %s\n", kernel_path);
|
printf("kernel: %s\n", kernel_path);
|
||||||
|
printf("map file: %s\n", map_path);
|
||||||
printf("append: %s\n", append_string);
|
printf("append: %s\n", append_string);
|
||||||
printf("buffer size: %d\n", buffer_size);
|
printf("buffer size: %d\n", buffer_size);
|
||||||
|
|
||||||
@@ -660,42 +682,49 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: cannot open \"%s\"\n",
|
fprintf(stderr, "ERROR: cannot open \"%s\"\n",
|
||||||
second_path);
|
second_path);
|
||||||
return 15;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((action & ACTION_TEST) == 0)
|
if ((action & ACTION_TEST) == 0)
|
||||||
{
|
{
|
||||||
char *configuration;
|
char *configuration;
|
||||||
|
struct emile_container *container;
|
||||||
|
char map_info[64];
|
||||||
|
|
||||||
#if 0
|
container = emile_second_create_mapfile(map_path, kernel_path);
|
||||||
/* set kernel info */
|
if (container == NULL)
|
||||||
|
|
||||||
ret = emile_second_set_kernel_scsi(fd, kernel_path);
|
|
||||||
if (ret == -1)
|
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"ERROR: cannot set \"%s\" information in \"%s\".\n",
|
"ERROR: cannot set \"%s\" information in \"%s\".\n",
|
||||||
kernel_path, second_path);
|
kernel_path, map_path);
|
||||||
return 16;
|
return 17;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* set cmdline */
|
/* set second configuration */
|
||||||
|
|
||||||
lseek(fd, 0, SEEK_SET);
|
lseek(fd, 0, SEEK_SET);
|
||||||
configuration = emile_second_get_configuration(fd);
|
configuration = emile_second_get_configuration(fd);
|
||||||
|
|
||||||
|
/* set kernel info */
|
||||||
|
|
||||||
|
sprintf(map_info, "container:(sd%d)0x%x,0x%x", container->unit_id,
|
||||||
|
container->blocks[0].offset, container->blocks[0].count);
|
||||||
|
emile_second_set_property(configuration, "kernel", map_info);
|
||||||
|
|
||||||
|
/* set cmdline */
|
||||||
|
|
||||||
emile_second_set_property(configuration, "parameters", append_string);
|
emile_second_set_property(configuration, "parameters", append_string);
|
||||||
|
|
||||||
|
/* save configuration */
|
||||||
|
|
||||||
lseek(fd, 0, SEEK_SET);
|
lseek(fd, 0, SEEK_SET);
|
||||||
ret = emile_second_set_configuration(fd, configuration);
|
ret = emile_second_set_configuration(fd, configuration);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
free(configuration);
|
free(configuration);
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"ERROR: cannot set append string \"%s\" in \"%s\".\n",
|
"ERROR: cannot set configuration in %s\n", second_path);
|
||||||
append_string, second_path);
|
return 19;
|
||||||
return 18;
|
|
||||||
}
|
}
|
||||||
free(configuration);
|
free(configuration);
|
||||||
}
|
}
|
||||||
@@ -709,7 +738,7 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"ERROR: cannot open \"%s\".\n", first_path);
|
"ERROR: cannot open \"%s\".\n", first_path);
|
||||||
return 19;
|
return 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((action & ACTION_TEST) == 0)
|
if ((action & ACTION_TEST) == 0)
|
||||||
@@ -720,7 +749,7 @@ int main(int argc, char **argv)
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"ERROR: cannot set \"%s\" information into \"%s\".\n",
|
"ERROR: cannot set \"%s\" information into \"%s\".\n",
|
||||||
second_path, first_path);
|
second_path, first_path);
|
||||||
return 20;
|
return 21;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,7 +767,7 @@ int main(int argc, char **argv)
|
|||||||
first_path, partition);
|
first_path, partition);
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
" %s\n", strerror(errno));
|
" %s\n", strerror(errno));
|
||||||
return 21;
|
return 22;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set HFS if needed */
|
/* set HFS if needed */
|
||||||
@@ -751,7 +780,7 @@ int main(int argc, char **argv)
|
|||||||
fprintf( stderr,
|
fprintf( stderr,
|
||||||
"ERROR: cannot set partition type of \"%s\" to Apple_HFS.\n"
|
"ERROR: cannot set partition type of \"%s\" to Apple_HFS.\n"
|
||||||
, partition);
|
, partition);
|
||||||
return 22;
|
return 23;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user