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
17 /* Minimal definition of disklabel, so we don't have to include
18 * asm/disklabel.h (confuses make)
21 #define MAXPARTITIONS 8 /* max. # of partitions */
25 #define u8 unsigned char
29 #define u16 unsigned short
33 #define u32 unsigned int
37 u32 d_magic; /* must be DISKLABELMAGIC */
38 u16 d_type, d_subtype;
50 u16 d_rpm, d_interleave, d_trackskew, d_cylskew;
51 u32 d_headswitch, d_trkseek, d_flags;
54 u32 d_magic2; /* must be DISKLABELMAGIC */
57 u32 d_bbsize, d_sbsize;
65 } d_partitions[MAXPARTITIONS];
69 typedef union __bootblock {
72 struct disklabel __label;
75 unsigned long __pad2[63];
76 unsigned long __checksum;
78 char bootblock_bytes[512];
79 unsigned long bootblock_quadwords[64];
82 #define bootblock_label __u1.__label
83 #define bootblock_checksum __u2.__checksum
85 int main(int argc, char ** argv)
87 bootblock bootblock_from_disk;
88 bootblock bootloader_image;
93 /* Make sure of the arg count */
95 fprintf(stderr, "Usage: %s device lxboot\n", argv[0]);
99 /* First, open the device and make sure it's accessible */
100 dev = open(argv[1], O_RDWR);
106 /* Now open the lxboot and make sure it's reasonable */
107 fd = open(argv[2], O_RDONLY);
114 /* Read in the lxboot */
115 nread = read(fd, &bootloader_image, sizeof(bootblock));
116 if(nread != sizeof(bootblock)) {
117 perror("lxboot read");
118 fprintf(stderr, "expected %zd, got %d\n", sizeof(bootblock), nread);
122 /* Read in the bootblock from disk. */
123 nread = read(dev, &bootblock_from_disk, sizeof(bootblock));
124 if(nread != sizeof(bootblock)) {
125 perror("bootblock read");
126 fprintf(stderr, "expected %zd, got %d\n", sizeof(bootblock), nread);
130 /* Swap the bootblock's disklabel into the bootloader */
131 bootloader_image.bootblock_label = bootblock_from_disk.bootblock_label;
133 /* Calculate the bootblock checksum */
134 bootloader_image.bootblock_checksum = 0;
135 for(i = 0; i < 63; i++) {
136 bootloader_image.bootblock_checksum +=
137 bootloader_image.bootblock_quadwords[i];
140 /* Write the whole thing out! */
141 lseek(dev, 0L, SEEK_SET);
142 if(write(dev, &bootloader_image, sizeof(bootblock)) != sizeof(bootblock)) {
143 perror("bootblock write");