2 * s390-tools/zipl/src/zipl.c
3 * zSeries Initial Program Loader tool.
5 * Copyright IBM Corp. 2001, 2009.
7 * Author(s): Carsten Otte <cotte@de.ibm.com>
8 * Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>
18 #include <sys/types.h>
28 #include "zt_common.h"
31 /* Flag deciding the level of verbosity */
34 /* Flag deciding whether confirmation questions are asked */
37 /* Flag deciding whether actions should only be simulated */
41 static const char tool_name
[] = "zipl: zSeries Initial Program Loader";
43 /* Copyright notice */
44 static const char copyright_notice
[] = "Copyright IBM Corp. 2001, 2009";
46 /* Usage information */
47 static const char* usage_text
[] = {
48 "Usage: zipl [OPTIONS] [SECTION]",
50 "Prepare a device for initial program load. Use OPTIONS described below or ",
51 "provide the name of a SECTION defined in the zIPL configuration file.",
53 "-h, --help Print this help, then exit",
54 "-v, --version Print version information, then exit",
55 "-c, --config CONFIGFILE Read configuration from CONFIGFILE",
56 "-t, --target TARGETDIR Write bootmap file to TARGETDIR and install",
57 " bootloader on device containing TARGETDIR",
58 " --targetbase BASEDEVICE Install bootloader on BASEDEVICE",
59 " --targettype TYPE Use device type: CDL, LDL, FBA, SCSI",
60 " --targetgeometry C,H,S Use disk geometry: cylinders,heads,sectors",
61 " --targetblocksize SIZE Use number of bytes per block",
62 " --targetoffset OFFSET Use offset between logical and physical disk",
63 "-i, --image IMAGEFILE[,ADDR] Install Linux kernel image from IMAGEFILE",
64 "-r, --ramdisk RAMDISK[,ADDR] Install initial ramdisk from file RAMDISK",
65 "-p, --parmfile PARMFILE[,ADDR] Use kernel parmline stored in PARMFILE",
66 "-P, --parameters PARMLINE Use specified kernel PARMLINE",
67 "-T, --tape TAPEDEV Install bootloader on tape device TAPEDEV",
68 "-s, --segment SEGMENT,ADDR Install a segment from file SEGMENT",
69 "-d, --dumpto DUMPDEV[,SIZE] Install a system dump record on tape device",
70 " or disk partition DUMPDEV",
71 "-M, --mvdump DEVLIST[,SIZE] Install a multi-volume dump record on each",
72 " disk partition listed in file DEVLIST",
73 "-f, --force Disable sanity check while producing a",
75 "-D, --dumptofs DUMPDEV[,SIZE] Install a system dump record for dumping to",
76 " filesystem on partition identified by DUMPDEV",
77 "-m, --menu MENU Install multi-boot configuration MENU",
78 "-n, --noninteractive Answer all confirmation questions with 'yes'",
79 "-V, --verbose Provide more verbose output",
80 "-a, --add-files Add all referenced files to bootmap file",
81 " --dry-run Simulate run but don't modify IPL records"
85 /* Print usage information. */
91 for (i
=0; i
< sizeof(usage_text
) / sizeof(usage_text
[0]); i
++)
92 printf("%s\n", usage_text
[i
]);
96 /* Print version information. */
100 printf("%s version %s\n", tool_name
, RELEASE_STRING
);
101 printf("%s\n", copyright_notice
);
105 /* Check whether calling user is root. Return 0 if user is root, non-zero
110 if (geteuid() != 0) {
112 error_reason("Must be root to perform this operation");
120 main(int argc
, char* argv
[])
122 struct disk_info
* info
;
123 disk_blockptr_t program_table
;
124 disk_blockptr_t
* stage2_list
;
125 blocknum_t stage2_count
;
126 struct job_data
* job
;
130 /* Check internals */
131 rc
= boot_check_data();
133 error_text("Internal error");
137 /* Find out what we're supposed to do */
138 rc
= job_get(argc
, argv
, &job
);
143 /* Check for priority options --help and --version */
144 if (job
->id
== job_print_usage
) {
147 } else if (job
->id
== job_print_version
) {
151 /* Make sure we're running as root */
152 if (check_for_root()) {
157 /* Set global option variables */
158 verbose
= job
->verbose
;
159 interactive
= !job
->noninteractive
;
160 dry_run
= job
->dry_run
;
162 printf("Starting dry-run, target device contents will NOT be "
164 /* Make sure new files are only user-accessible */
174 rc
= bootmap_create(job
, &program_table
, &stage2_list
,
175 &stage2_count
, &device
, &info
);
178 /* Install boot loader */
179 rc
= install_bootloader(device
, &program_table
,
180 stage2_list
, stage2_count
, info
, job
);
181 if (stage2_list
!= NULL
)
183 misc_free_temp_dev(device
);
184 disk_free_info(info
);
187 rc
= install_tapeloader(job
->data
.ipl_tape
.device
,
188 job
->data
.ipl_tape
.image
,
189 job
->data
.ipl_tape
.parmline
,
190 job
->data
.ipl_tape
.ramdisk
,
191 job
->data
.ipl_tape
.image_addr
,
192 job
->data
.ipl_tape
.parm_addr
,
193 job
->data
.ipl_tape
.ramdisk_addr
);
195 case job_dump_partition
:
196 /* Retrieve target device information */
197 rc
= install_dump(job
->data
.dump
.device
, &job
->target
,
201 rc
= install_mvdump(job
->data
.mvdump
.device
,
203 job
->data
.mvdump
.device_count
,
204 job
->data
.mvdump
.mem
,
205 job
->data
.mvdump
.force
);
207 case job_print_usage
:
208 case job_print_version
:
209 /* Should not happen */
213 case 0: /* Operation completed successfully */
215 printf("Syncing disks...\n");
220 case -2: /* Operation canceled by user */
222 default: /* An error occurred */