zipl: add common ipl data

Each ipl type takes at least a kernel image, parameter line and initrd
parameter. This is duplicated all over the place in the current
implementation. To simplify this, add struct job_common_ipl_data which
will hold this data.

Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Reviewed-by: Stefan Haberland <sth@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Sven Schnelle
2021-11-08 08:42:24 +01:00
committed by Jan Höppner
parent 1627c6a39f
commit e384f06014
4 changed files with 139 additions and 148 deletions

View File

@@ -39,13 +39,17 @@ struct job_target_data {
blocknum_t targetoffset;
};
struct job_ipl_data {
struct job_common_ipl_data {
char* image;
char* parmline;
char* ramdisk;
address_t image_addr;
address_t parm_addr;
address_t ramdisk_addr;
};
struct job_ipl_data {
struct job_common_ipl_data common;
address_t envblk_addr;
int is_kdump;
};
@@ -61,13 +65,8 @@ struct job_segment_data {
};
struct job_dump_data {
struct job_common_ipl_data common;
char* device;
char* image;
char* parmline;
char* ramdisk;
address_t image_addr;
address_t parm_addr;
address_t ramdisk_addr;
uint64_t mem;
};
@@ -80,13 +79,8 @@ struct job_mvdump_data {
};
struct job_ipl_tape_data {
struct job_common_ipl_data common;
char* device;
char* image;
char* parmline;
char* ramdisk;
address_t image_addr;
address_t parm_addr;
address_t ramdisk_addr;
};

View File

@@ -560,16 +560,16 @@ static int add_ipl_program(int fd, char *filename,
*/
/* initiate values for ramdisk */
stats.st_size = 0;
if (ipl->ramdisk != NULL) {
if (ipl->common.ramdisk != NULL) {
/* Add ramdisk */
if (verbose) {
printf(" initial ramdisk...: %s\n", ipl->ramdisk);
printf(" initial ramdisk...: %s\n", ipl->common.ramdisk);
}
/* Get ramdisk file size */
if (stat(ipl->ramdisk, &stats)) {
if (stat(ipl->common.ramdisk, &stats)) {
error_reason(strerror(errno));
error_text("Could not get information for file '%s'",
ipl->ramdisk);
ipl->common.ramdisk);
free(table);
return -1;
}
@@ -609,10 +609,10 @@ static int add_ipl_program(int fd, char *filename,
flags |= STAGE3_FLAG_KDUMP;
/* Get kernel file size */
if (stat(ipl->image, &stats)) {
if (stat(ipl->common.image, &stats)) {
error_reason(strerror(errno));
error_text("Could not get information for file '%s'",
ipl->image);
ipl->common.image);
free(table);
return -1;
}
@@ -669,12 +669,12 @@ static int add_ipl_program(int fd, char *filename,
/* Add stage 3 parameter to bootmap */
rc = boot_get_stage3_parms(&stage3_params, &stage3_params_size,
ipl->parm_addr, ipl->ramdisk_addr,
ipl->common.parm_addr, ipl->common.ramdisk_addr,
ramdisk_size,
ipl->is_kdump ? IMAGE_ENTRY_KDUMP :
IMAGE_ENTRY,
(info->type == disk_type_scsi) ? 0 : 1,
flags, ipl->image_addr, image_size,
flags, ipl->common.image_addr, image_size,
ipl->envblk_addr,
add_envblk ? envblk->size : 0);
if (rc) {
@@ -698,14 +698,14 @@ static int add_ipl_program(int fd, char *filename,
/* Add kernel image */
if (verbose) {
printf(" kernel image......: %s\n", ipl->image);
printf(" kernel image......: %s\n", ipl->common.image);
}
signature_size = extract_signature(ipl->image, &signature, &sig_head);
signature_size = extract_signature(ipl->common.image, &signature, &sig_head);
if (signature_size &&
(is_secure == SECURE_BOOT_ENABLED ||
(is_secure == SECURE_BOOT_AUTO && secure_boot_supported))) {
if (verbose)
printf(" signature for.....: %s\n", ipl->image);
printf(" signature for.....: %s\n", ipl->common.image);
rc = add_component_buffer(fd, signature, sig_head.length,
(component_data)sig_head,
@@ -722,7 +722,7 @@ static int add_ipl_program(int fd, char *filename,
comp_nr++;
free(signature);
check_remaining_filesize(image_size, signature_size, info,
ipl->image);
ipl->common.image);
} else if (is_secure == SECURE_BOOT_ENABLED) {
/*
* If secure boot is forced and we have failed to extract a
@@ -731,16 +731,16 @@ static int add_ipl_program(int fd, char *filename,
*/
error_text("Could not install Secure Boot IPL records");
error_reason("Missing signature in image file %s",
ipl->image);
ipl->common.image);
free(table);
return -1;
}
rc = add_component_file(fd, ipl->image, ipl->image_addr,
rc = add_component_file(fd, ipl->common.image, ipl->common.image_addr,
signature_size, VOID_ADD(table, offset),
add_files, info, target, &comp_loc[comp_nr]);
if (rc) {
error_text("Could not add image file '%s'", ipl->image);
error_text("Could not add image file '%s'", ipl->common.image);
free(table);
return rc;
}
@@ -749,19 +749,19 @@ static int add_ipl_program(int fd, char *filename,
comp_nr++;
/* Add kernel parmline */
if (ipl->parmline != NULL) {
if (ipl->common.parmline != NULL) {
if (verbose) {
printf(" kernel parmline...: '%s'\n", ipl->parmline);
printf(" kernel parmline...: '%s'\n", ipl->common.parmline);
}
rc = add_component_buffer(fd, ipl->parmline,
strlen(ipl->parmline) + 1,
(component_data) ipl->parm_addr,
rc = add_component_buffer(fd, ipl->common.parmline,
strlen(ipl->common.parmline) + 1,
(component_data) ipl->common.parm_addr,
VOID_ADD(table, offset),
info, &comp_loc[comp_nr],
component_load);
if (rc) {
error_text("Could not add parmline '%s'",
ipl->parmline);
ipl->common.parmline);
free(table);
return -1;
}
@@ -770,8 +770,8 @@ static int add_ipl_program(int fd, char *filename,
comp_nr++;
}
/* add ramdisk */
if (ipl->ramdisk != NULL) {
signature_size = extract_signature(ipl->ramdisk, &signature,
if (ipl->common.ramdisk != NULL) {
signature_size = extract_signature(ipl->common.ramdisk, &signature,
&sig_head);
if (signature_size &&
(is_secure == SECURE_BOOT_ENABLED ||
@@ -779,7 +779,7 @@ static int add_ipl_program(int fd, char *filename,
secure_boot_supported))) {
if (verbose) {
printf(" signature for.....: %s\n",
ipl->ramdisk);
ipl->common.ramdisk);
}
rc = add_component_buffer(fd, signature,
sig_head.length,
@@ -797,16 +797,16 @@ static int add_ipl_program(int fd, char *filename,
comp_nr++;
free(signature);
check_remaining_filesize(ramdisk_size, signature_size,
info, ipl->ramdisk);
info, ipl->common.ramdisk);
}
rc = add_component_file(fd, ipl->ramdisk,
ipl->ramdisk_addr, signature_size,
rc = add_component_file(fd, ipl->common.ramdisk,
ipl->common.ramdisk_addr, signature_size,
VOID_ADD(table, offset),
add_files, info, target,
&comp_loc[comp_nr]);
if (rc) {
error_text("Could not add ramdisk '%s'",
ipl->ramdisk);
ipl->common.ramdisk);
free(table);
return -1;
}
@@ -1009,17 +1009,14 @@ add_dump_program(int fd, struct job_dump_data* dump,
/* Convert fs dump job to IPL job */
memset(&ipl, 0, sizeof(ipl));
ipl.image = dump->image;
ipl.image_addr = dump->image_addr;
ipl.ramdisk = dump->ramdisk;
ipl.ramdisk_addr = dump->ramdisk_addr;
ipl.common = dump->common;
/* Get file system dump parmline */
rc = get_dump_parmline(dump->device, dump->parmline,
info, target, &ipl.parmline);
rc = get_dump_parmline(dump->device, dump->common.parmline,
info, target, &ipl.common.parmline);
if (rc)
return rc;
ipl.parm_addr = dump->parm_addr;
ipl.common.parm_addr = dump->common.parm_addr;
return add_ipl_program(fd, NULL, false, NULL, &ipl, program, verbose, 1,
type, info, target, SECURE_BOOT_DISABLED);
}
@@ -1283,14 +1280,14 @@ bootmap_create(struct job_data *job, disk_blockptr_t *program_table,
size = IMAGE_LOAD_ADDRESS;
/* Ramdisk */
if (job->data.dump.ramdisk != NULL) {
if (stat(job->data.dump.ramdisk, &st))
if (job->data.dump.common.ramdisk != NULL) {
if (stat(job->data.dump.common.ramdisk, &st))
goto out_misc_free_temp_dev;
size += DIV_ROUND_UP(st.st_size, info->phy_block_size);
size += 1; /* For ramdisk section entry */
}
/* Kernel */
if (stat(job->data.dump.image, &st))
if (stat(job->data.dump.common.image, &st))
goto out_misc_free_temp_dev;
size += DIV_ROUND_UP(st.st_size - IMAGE_LOAD_ADDRESS,
info->phy_block_size);

View File

@@ -370,12 +370,12 @@ free_envblk_data(struct job_envblk_data *data)
static void
free_ipl_data(struct job_ipl_data* data)
{
if (data->image != NULL)
free(data->image);
if (data->parmline != NULL)
free(data->parmline);
if (data->ramdisk != NULL)
free(data->ramdisk);
if (data->common.image != NULL)
free(data->common.image);
if (data->common.parmline != NULL)
free(data->common.parmline);
if (data->common.ramdisk != NULL)
free(data->common.ramdisk);
}
@@ -384,12 +384,12 @@ free_ipl_tape_data(struct job_ipl_tape_data* data)
{
if (data->device != NULL)
free(data->device);
if (data->image != NULL)
free(data->image);
if (data->parmline != NULL)
free(data->parmline);
if (data->ramdisk != NULL)
free(data->ramdisk);
if (data->common.image != NULL)
free(data->common.image);
if (data->common.parmline != NULL)
free(data->common.parmline);
if (data->common.ramdisk != NULL)
free(data->common.ramdisk);
}
@@ -406,12 +406,12 @@ free_dump_data(struct job_dump_data* data)
{
if (data->device != NULL)
free(data->device);
if (data->image != NULL)
free(data->image);
if (data->parmline != NULL)
free(data->parmline);
if (data->ramdisk != NULL)
free(data->ramdisk);
if (data->common.image != NULL)
free(data->common.image);
if (data->common.parmline != NULL)
free(data->common.parmline);
if (data->common.ramdisk != NULL)
free(data->common.ramdisk);
}
@@ -559,21 +559,21 @@ get_ipl_components(struct job_ipl_data *ipl, struct component_loc **clp,
return -1;
/* Fill in component data */
num = 0;
rc = set_cl_element(&cl[num++], "kernel image", ipl->image,
&ipl->image_addr, 0, 0,
rc = set_cl_element(&cl[num++], "kernel image", ipl->common.image,
&ipl->common.image_addr, 0, 0,
MAXIMUM_PHYSICAL_BLOCKSIZE);
if (rc)
goto error;
if (ipl->parmline) {
if (ipl->common.parmline) {
rc = set_cl_element(&cl[num++], "parmline", NULL,
&ipl->parm_addr, MAXIMUM_PARMLINE_SIZE, 0,
&ipl->common.parm_addr, MAXIMUM_PARMLINE_SIZE, 0,
MAXIMUM_PHYSICAL_BLOCKSIZE);
if (rc)
goto error;
}
if (ipl->ramdisk) {
rc = set_cl_element(&cl[num++], "initial ramdisk", ipl->ramdisk,
&ipl->ramdisk_addr, 0, 0, 0x10000);
if (ipl->common.ramdisk) {
rc = set_cl_element(&cl[num++], "initial ramdisk", ipl->common.ramdisk,
&ipl->common.ramdisk_addr, 0, 0, 0x10000);
if (rc)
goto error;
}
@@ -607,19 +607,19 @@ get_dump_components(struct job_dump_data *dump,
return -1;
/* Fill in component data */
num = 0;
rc = set_cl_element(&cl[num++], "kernel image", dump->image,
&dump->image_addr, 0, 0x0,
rc = set_cl_element(&cl[num++], "kernel image", dump->common.image,
&dump->common.image_addr, 0, 0x0,
MAXIMUM_PHYSICAL_BLOCKSIZE);
if (rc)
goto error;
rc = set_cl_element(&cl[num++], "parmline", NULL, &dump->parm_addr,
rc = set_cl_element(&cl[num++], "parmline", NULL, &dump->common.parm_addr,
MAXIMUM_PARMLINE_SIZE, 0,
MAXIMUM_PHYSICAL_BLOCKSIZE);
if (rc)
goto error;
if (dump->ramdisk) {
if (dump->common.ramdisk) {
rc = set_cl_element(&cl[num++], "initial ramdisk",
dump->ramdisk, &dump->ramdisk_addr,
dump->common.ramdisk, &dump->common.ramdisk_addr,
0, 0, 0x10000);
if (rc)
goto error;
@@ -648,23 +648,23 @@ get_ipl_tape_components(struct job_ipl_tape_data *ipl_tape,
return -1;
/* Fill in component data */
num = 0;
rc = set_cl_element(&cl[num++], "kernel image", ipl_tape->image,
&ipl_tape->image_addr, 0, 0x10000,
rc = set_cl_element(&cl[num++], "kernel image", ipl_tape->common.image,
&ipl_tape->common.image_addr, 0, 0x10000,
MAXIMUM_PHYSICAL_BLOCKSIZE);
if (rc)
goto error;
/* Enhance the image size value for tape loader specific logic */
cl[0].size = ALIGN(cl[0].size + 0x100, MAXIMUM_PHYSICAL_BLOCKSIZE);
if (ipl_tape->parmline) {
if (ipl_tape->common.parmline) {
rc = set_cl_element(&cl[num++], "parmline", NULL,
&ipl_tape->parm_addr, MAXIMUM_PARMLINE_SIZE,
&ipl_tape->common.parm_addr, MAXIMUM_PARMLINE_SIZE,
0, MAXIMUM_PHYSICAL_BLOCKSIZE);
if (rc)
goto error;
}
if (ipl_tape->ramdisk) {
if (ipl_tape->common.ramdisk) {
rc = set_cl_element(&cl[num++], "initial ramdisk",
ipl_tape->ramdisk, &ipl_tape->ramdisk_addr,
ipl_tape->common.ramdisk, &ipl_tape->common.ramdisk_addr,
0, 0, 0x10000);
if (rc)
goto error;
@@ -837,10 +837,10 @@ finalize_ipl_tape_address_data(struct job_ipl_tape_data* ipl_tape, char *name)
goto out_free;
rc = finalize_component_address_data(cl, num, ADDRESS_LIMIT);
/* The loader needs a ramdisk_addr anyway */
if (ipl_tape->ramdisk_addr == 0) {
if (ipl_tape->common.ramdisk_addr == 0) {
for (i = 0; i < num; i++) {
if (*cl[i].addrp == ipl_tape->image_addr)
ipl_tape->ramdisk_addr =
if (*cl[i].addrp == ipl_tape->common.image_addr)
ipl_tape->common.ramdisk_addr =
*cl[i].addrp + cl[i].size;
}
}
@@ -856,26 +856,26 @@ check_job_ipl_data(struct job_ipl_data *ipl, char *name,
{
int rc;
if (ipl->image != NULL) {
rc = misc_check_readable_file(ipl->image);
if (ipl->common.image != NULL) {
rc = misc_check_readable_file(ipl->common.image);
if (rc) {
if (name == NULL) {
error_text("Image file '%s'", ipl->image);
error_text("Image file '%s'", ipl->common.image);
} else {
error_text("Image file '%s' in section '%s'",
ipl->image, name);
ipl->common.image, name);
}
return rc;
}
}
if (ipl->ramdisk != NULL) {
rc = misc_check_readable_file(ipl->ramdisk);
if (ipl->common.ramdisk != NULL) {
rc = misc_check_readable_file(ipl->common.ramdisk);
if (rc) {
if (name == NULL) {
error_text("Ramdisk file '%s'", ipl->ramdisk);
error_text("Ramdisk file '%s'", ipl->common.ramdisk);
} else {
error_text("Ramdisk file '%s' in section '%s'",
ipl->ramdisk, name);
ipl->common.ramdisk, name);
}
return rc;
}
@@ -938,22 +938,22 @@ check_job_dump_images(struct job_dump_data* dump, char* name)
ZFCPDUMP_IMAGE);
return rc;
}
dump->image = misc_strdup(ZFCPDUMP_IMAGE);
if (dump->image == NULL)
dump->common.image = misc_strdup(ZFCPDUMP_IMAGE);
if (dump->common.image == NULL)
return -1;
dump->image_addr = IMAGE_LOAD_ADDRESS;
dump->common.image_addr = IMAGE_LOAD_ADDRESS;
/* Ramdisk is no longer required with new initramfs dump system */
if (misc_check_readable_file(ZFCPDUMP_INITRD))
dump->ramdisk = NULL;
dump->common.ramdisk = NULL;
else {
dump->ramdisk = misc_strdup(ZFCPDUMP_INITRD);
if (dump->ramdisk == NULL)
dump->common.ramdisk = misc_strdup(ZFCPDUMP_INITRD);
if (dump->common.ramdisk == NULL)
return -1;
dump->ramdisk_addr = UNSPECIFIED_ADDRESS;
dump->common.ramdisk_addr = UNSPECIFIED_ADDRESS;
}
dump->parm_addr = UNSPECIFIED_ADDRESS;
dump->common.parm_addr = UNSPECIFIED_ADDRESS;
return finalize_dump_address_data(dump, name);
}
@@ -1004,26 +1004,26 @@ check_job_ipl_tape_data(struct job_ipl_tape_data *ipl, char* name)
return rc;
}
}
if (ipl->image != NULL) {
rc = misc_check_readable_file(ipl->image);
if (ipl->common.image != NULL) {
rc = misc_check_readable_file(ipl->common.image);
if (rc) {
if (name == NULL) {
error_text("Image file '%s'", ipl->image);
error_text("Image file '%s'", ipl->common.image);
} else {
error_text("Image file '%s' in section '%s'",
ipl->image, name);
ipl->common.image, name);
}
return rc;
}
}
if (ipl->ramdisk != NULL) {
rc = misc_check_readable_file(ipl->ramdisk);
if (ipl->common.ramdisk != NULL) {
rc = misc_check_readable_file(ipl->common.ramdisk);
if (rc) {
if (name == NULL) {
error_text("Ramdisk file '%s'", ipl->ramdisk);
error_text("Ramdisk file '%s'", ipl->common.ramdisk);
} else {
error_text("Ramdisk file '%s' in section '%s'",
ipl->ramdisk, name);
ipl->common.ramdisk, name);
}
return rc;
}
@@ -1383,19 +1383,19 @@ get_job_from_section_data(char* data[], struct job_data* job, char* section)
atol(data[(int) scan_keyword_targetoffset]);
/* Fill in name and address of image file */
job->data.ipl.image = misc_strdup(
job->data.ipl.common.image = misc_strdup(
data[(int) scan_keyword_image]);
if (job->data.ipl.image == NULL)
if (job->data.ipl.common.image == NULL)
return -1;
if (extract_address(job->data.ipl.image,
&job->data.ipl.image_addr)) {
job->data.ipl.image_addr = IMAGE_LOAD_ADDRESS;
if (extract_address(job->data.ipl.common.image,
&job->data.ipl.common.image_addr)) {
job->data.ipl.common.image_addr = IMAGE_LOAD_ADDRESS;
}
/* Fill in parmline */
rc = get_parmline(data[(int) scan_keyword_parmfile],
data[(int) scan_keyword_parameters],
&job->data.ipl.parmline,
&job->data.ipl.parm_addr, section);
&job->data.ipl.common.parmline,
&job->data.ipl.common.parm_addr, section);
if (rc)
return rc;
/* Fill in environment block */
@@ -1403,13 +1403,13 @@ get_job_from_section_data(char* data[], struct job_data* job, char* section)
/* Fill in name and address of ramdisk file */
if (data[(int) scan_keyword_ramdisk] != NULL) {
job->data.ipl.ramdisk =
job->data.ipl.common.ramdisk =
misc_strdup(data[(int) scan_keyword_ramdisk]);
if (job->data.ipl.ramdisk == NULL)
if (job->data.ipl.common.ramdisk == NULL)
return -1;
if (extract_address(job->data.ipl.ramdisk,
&job->data.ipl.ramdisk_addr)) {
job->data.ipl.ramdisk_addr =
if (extract_address(job->data.ipl.common.ramdisk,
&job->data.ipl.common.ramdisk_addr)) {
job->data.ipl.common.ramdisk_addr =
UNSPECIFIED_ADDRESS;
}
}
@@ -1441,30 +1441,30 @@ get_job_from_section_data(char* data[], struct job_data* job, char* section)
if (job->data.ipl_tape.device == NULL)
return -1;
/* Fill in name and address of image file */
job->data.ipl_tape.image = misc_strdup(
job->data.ipl_tape.common.image = misc_strdup(
data[(int) scan_keyword_image]);
if (job->data.ipl_tape.image == NULL)
if (job->data.ipl_tape.common.image == NULL)
return -1;
if (extract_address(job->data.ipl_tape.image,
&job->data.ipl_tape.image_addr)) {
job->data.ipl_tape.image_addr = IMAGE_LOAD_ADDRESS;
if (extract_address(job->data.ipl_tape.common.image,
&job->data.ipl_tape.common.image_addr)) {
job->data.ipl_tape.common.image_addr = IMAGE_LOAD_ADDRESS;
}
/* Fill in parmline */
rc = get_parmline(data[(int) scan_keyword_parmfile],
data[(int) scan_keyword_parameters],
&job->data.ipl_tape.parmline,
&job->data.ipl_tape.parm_addr, section);
&job->data.ipl_tape.common.parmline,
&job->data.ipl_tape.common.parm_addr, section);
if (rc)
return rc;
/* Fill in name and address of ramdisk file */
if (data[(int) scan_keyword_ramdisk] != NULL) {
job->data.ipl_tape.ramdisk =
job->data.ipl_tape.common.ramdisk =
misc_strdup(data[(int) scan_keyword_ramdisk]);
if (job->data.ipl_tape.ramdisk == NULL)
if (job->data.ipl_tape.common.ramdisk == NULL)
return -1;
if (extract_address(job->data.ipl_tape.ramdisk,
&job->data.ipl_tape.ramdisk_addr)) {
job->data.ipl_tape.ramdisk_addr =
if (extract_address(job->data.ipl_tape.common.ramdisk,
&job->data.ipl_tape.common.ramdisk_addr)) {
job->data.ipl_tape.common.ramdisk_addr =
UNSPECIFIED_ADDRESS;
}
}
@@ -1801,15 +1801,15 @@ get_section_job(struct scan_token* scan, char* section, struct job_data* job,
if (extra_parmline != NULL) {
switch (job->id) {
case job_ipl:
if (job->data.ipl.parmline == NULL)
if (job->data.ipl.common.parmline == NULL)
buffer = misc_strdup(extra_parmline);
else {
buffer = append_parmline(
job->data.ipl.parmline,
job->data.ipl.common.parmline,
extra_parmline);
free(job->data.ipl.parmline);
free(job->data.ipl.common.parmline);
}
job->data.ipl.parmline = buffer;
job->data.ipl.common.parmline = buffer;
if (buffer == NULL)
return -1;
break;

View File

@@ -212,12 +212,12 @@ main(int argc, char* argv[])
break;
case job_ipl_tape:
rc = install_tapeloader(job->data.ipl_tape.device,
job->data.ipl_tape.image,
job->data.ipl_tape.parmline,
job->data.ipl_tape.ramdisk,
job->data.ipl_tape.image_addr,
job->data.ipl_tape.parm_addr,
job->data.ipl_tape.ramdisk_addr);
job->data.ipl_tape.common.image,
job->data.ipl_tape.common.parmline,
job->data.ipl_tape.common.ramdisk,
job->data.ipl_tape.common.image_addr,
job->data.ipl_tape.common.parm_addr,
job->data.ipl_tape.common.ramdisk_addr);
break;
case job_mvdump:
rc = install_mvdump(job->data.mvdump.device,