2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2016 Toomas Soome <tsoome@me.com>
17 #include <sys/types.h>
21 #include <sys/sysmacros.h>
22 #include <sys/multiboot.h>
24 #include "bblk_einfo.h"
25 #include "boot_utils.h"
26 #include "mboot_extra.h"
29 * Add version to loader bootblock file. The file should have fake
30 * multiboot header and version data will be added at the end of the file.
31 * MB header is fake in sense that this bootblock is *not* MB compatible,
32 * and MB header will only include load_addr and load_end_addr components.
33 * load_addr will be set to value 0 to indicate the beginning of the file
34 * and load_end_addr will be set to the size of the original file.
35 * The flags value in header must be exactly AOUT kludge.
37 * version data is aligned by 8 bytes and whole blootblock will be padded to
40 * To use and verify version data, first find MB header, then load_end_addr
41 * will point to the end of the original file, aligned up by 8, is version
42 * data implemented as bblk einfo.
46 add_version(char *file
, char *version
)
54 multiboot_header_t
*mboot
;
59 fd
= open(file
, O_RDONLY
);
64 if (fstat(fd
, &sb
) == -1) {
71 * make sure we have enough space to append EINFO.
73 buf_size
= P2ROUNDUP(sb
.st_size
+ SECTOR_SIZE
, SECTOR_SIZE
);
74 buf
= malloc(buf_size
);
82 * read in whole file. we need to access MB header and einfo
83 * will create MD5 hash.
85 ret
= read(fd
, buf
, sb
.st_size
);
86 if (ret
!= sb
.st_size
) {
94 if (find_multiboot(buf
, MBOOT_SCAN_SIZE
, &mboot_off
)
96 printf("Unable to find multiboot header\n");
101 mboot
= (multiboot_header_t
*)(buf
+ mboot_off
);
102 mboot
->load_addr
= 0;
103 mboot
->load_end_addr
= sb
.st_size
;
106 hs
.src_buf
= (unsigned char *)buf
;
107 hs
.src_size
= sb
.st_size
;
110 * this is location for EINFO data
112 extra
= P2ROUNDUP(sb
.st_size
, 8);
113 avail_space
= buf_size
- extra
;
114 memset(buf
+sb
.st_size
, 0, buf_size
- sb
.st_size
);
115 add_einfo(buf
+ extra
, version
, &hs
, avail_space
);
117 fd
= open(file
, O_WRONLY
| O_TRUNC
);
123 ret
= write(fd
, buf
, buf_size
);