1 /* This utility makes a bootblock suitable for the SRM console/miniloader */
4 * mkbb <device> <lxboot>
6 * Where <device> is the name of the device to install the bootblock on,
7 * and <lxboot> is the name of a bootblock to merge in. This bootblock
8 * contains the offset and size of the bootloader. It must be exactly
16 /* Minimal definition of disklabel, so we don't have to include
17 * asm/disklabel.h (confuses make)
20 #define MAXPARTITIONS 8 /* max. # of partitions */
24 #define u8 unsigned char
28 #define u16 unsigned short
32 #define u32 unsigned int
36 u32 d_magic; /* must be DISKLABELMAGIC */
37 u16 d_type, d_subtype;
49 u16 d_rpm, d_interleave, d_trackskew, d_cylskew;
50 u32 d_headswitch, d_trkseek, d_flags;
53 u32 d_magic2; /* must be DISKLABELMAGIC */
56 u32 d_bbsize, d_sbsize;
64 } d_partitions[MAXPARTITIONS];
68 typedef union __bootblock {
71 struct disklabel __label;
74 unsigned long __pad2[63];
75 unsigned long __checksum;
77 char bootblock_bytes[512];
78 unsigned long bootblock_quadwords[64];
81 #define bootblock_label __u1.__label
82 #define bootblock_checksum __u2.__checksum
84 int main(int argc, char ** argv)
86 bootblock bootblock_from_disk;
87 bootblock bootloader_image;
92 /* Make sure of the arg count */
94 fprintf(stderr, "Usage: %s device lxboot\n", argv[0]);
98 /* First, open the device and make sure it's accessible */
99 dev = open(argv[1], O_RDWR);
105 /* Now open the lxboot and make sure it's reasonable */
106 fd = open(argv[2], O_RDONLY);
113 /* Read in the lxboot */
114 nread = read(fd, &bootloader_image, sizeof(bootblock));
115 if(nread != sizeof(bootblock)) {
116 perror("lxboot read");
117 fprintf(stderr, "expected %d, got %d\n", sizeof(bootblock), nread);
121 /* Read in the bootblock from disk. */
122 nread = read(dev, &bootblock_from_disk, sizeof(bootblock));
123 if(nread != sizeof(bootblock)) {
124 perror("bootblock read");
125 fprintf(stderr, "expected %d, got %d\n", sizeof(bootblock), nread);
129 /* Swap the bootblock's disklabel into the bootloader */
130 bootloader_image.bootblock_label = bootblock_from_disk.bootblock_label;
132 /* Calculate the bootblock checksum */
133 bootloader_image.bootblock_checksum = 0;
134 for(i = 0; i < 63; i++) {
135 bootloader_image.bootblock_checksum +=
136 bootloader_image.bootblock_quadwords[i];
139 /* Write the whole thing out! */
140 lseek(dev, 0L, SEEK_SET);
141 if(write(dev, &bootloader_image, sizeof(bootblock)) != sizeof(bootblock)) {
142 perror("bootblock write");