Skip to content

Commit

Permalink
9911 loader: use crc32 from libstand (libz)
Browse files Browse the repository at this point in the history
Reviewed by: Jason King <jason.king@joyent.com>
Reviewed by: Andy Fiddaman <andy@omniosce.org>
Approved by: Dan McDonald <danmcd@joyent.com>
  • Loading branch information
tsoome authored and Dan McDonald committed Oct 24, 2018
1 parent d0843a3 commit 388010d
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 154 deletions.
108 changes: 0 additions & 108 deletions usr/src/boot/sys/boot/common/crc32.c

This file was deleted.

13 changes: 0 additions & 13 deletions usr/src/boot/sys/boot/common/crc32.h

This file was deleted.

47 changes: 25 additions & 22 deletions usr/src/boot/sys/boot/common/gpt.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*-
/*
* Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
* All rights reserved.
*
Expand All @@ -25,7 +25,6 @@
*/

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <sys/param.h>
#include <sys/gpt.h>
Expand All @@ -34,7 +33,7 @@ __FBSDID("$FreeBSD$");
#error gpt.c works only for little endian architectures
#endif

#include "crc32.h"
#include "zlib.h"
#include "drv.h"
#include "util.h"
#include "gpt.h"
Expand Down Expand Up @@ -78,9 +77,11 @@ gptupdate(const char *which, struct dsk *dskp, struct gpt_hdr *hdr,
BOOTPROG, which);
return;
}
hdr->hdr_crc_table = crc32(table, hdr->hdr_entries * hdr->hdr_entsz);
hdr->hdr_crc_self = 0;
hdr->hdr_crc_self = crc32(hdr, hdr->hdr_size);
hdr->hdr_crc_table = crc32(0, Z_NULL, 0);
hdr->hdr_crc_table = crc32(hdr->hdr_crc_table, table,
hdr->hdr_entries * hdr->hdr_entsz);
hdr->hdr_crc_self = crc32(0, Z_NULL, 0);
hdr->hdr_crc_self = crc32(hdr->hdr_crc_self, hdr, hdr->hdr_size);
bzero(secbuf, DEV_BSIZE);
bcopy(hdr, secbuf, hdr->hdr_size);
if (drvwrite(dskp, secbuf, hdr->hdr_lba_self, 1)) {
Expand All @@ -101,7 +102,7 @@ gptfind(const uuid_t *uuid, struct dsk *dskp, int part)
return (-1);
}
ent = &gpttable[part - 1];
if (bcmp(&ent->ent_type, uuid, sizeof(uuid_t)) != 0) {
if (bcmp(&ent->ent_type, uuid, sizeof (uuid_t)) != 0) {
printf("%s: specified partition is not UFS\n",
BOOTPROG);
return (-1);
Expand All @@ -123,7 +124,7 @@ gptfind(const uuid_t *uuid, struct dsk *dskp, int part)
*/
for (; curent < gpthdr->hdr_entries; curent++) {
ent = &gpttable[curent];
if (bcmp(&ent->ent_type, uuid, sizeof(uuid_t)) != 0)
if (bcmp(&ent->ent_type, uuid, sizeof (uuid_t)) != 0)
continue;
if (!(ent->ent_attr & GPT_ENT_ATTR_BOOTME))
continue;
Expand All @@ -137,7 +138,7 @@ gptfind(const uuid_t *uuid, struct dsk *dskp, int part)
}
for (; curent < gpthdr->hdr_entries; curent++) {
ent = &gpttable[curent];
if (bcmp(&ent->ent_type, uuid, sizeof(uuid_t)) != 0)
if (bcmp(&ent->ent_type, uuid, sizeof (uuid_t)) != 0)
continue;
if (!(ent->ent_attr & GPT_ENT_ATTR_BOOTME))
continue;
Expand All @@ -153,7 +154,7 @@ gptfind(const uuid_t *uuid, struct dsk *dskp, int part)
*/
for (curent = 0; curent < gpthdr->hdr_entries; curent++) {
ent = &gpttable[curent];
if (bcmp(&ent->ent_type, uuid, sizeof(uuid_t)) != 0)
if (bcmp(&ent->ent_type, uuid, sizeof (uuid_t)) != 0)
continue;
/* Ok, found one. */
goto found;
Expand Down Expand Up @@ -191,17 +192,17 @@ gptread_hdr(const char *which, struct dsk *dskp, struct gpt_hdr *hdr,
printf("%s: unable to read %s GPT header\n", BOOTPROG, which);
return (-1);
}
bcopy(secbuf, hdr, sizeof(*hdr));
if (bcmp(hdr->hdr_sig, GPT_HDR_SIG, sizeof(hdr->hdr_sig)) != 0 ||
bcopy(secbuf, hdr, sizeof (*hdr));
if (bcmp(hdr->hdr_sig, GPT_HDR_SIG, sizeof (hdr->hdr_sig)) != 0 ||
hdr->hdr_lba_self != hdrlba || hdr->hdr_revision < 0x00010000 ||
hdr->hdr_entsz < sizeof(struct gpt_ent) ||
hdr->hdr_entsz < sizeof (struct gpt_ent) ||
hdr->hdr_entries > MAXTBLENTS || DEV_BSIZE % hdr->hdr_entsz != 0) {
printf("%s: invalid %s GPT header\n", BOOTPROG, which);
return (-1);
}
crc = hdr->hdr_crc_self;
hdr->hdr_crc_self = 0;
if (crc32(hdr, hdr->hdr_size) != crc) {
hdr->hdr_crc_self = crc32(0, Z_NULL, 0);
if (crc32(hdr->hdr_crc_self, hdr, hdr->hdr_size) != crc) {
printf("%s: %s GPT header checksum mismatch\n", BOOTPROG,
which);
return (-1);
Expand Down Expand Up @@ -241,8 +242,8 @@ gptbootconv(const char *which, struct dsk *dskp, struct gpt_hdr *hdr,
table_updated = 0;
entries_per_sec = DEV_BSIZE / hdr->hdr_entsz;
for (nent = 0, slba = hdr->hdr_lba_table;
slba < hdr->hdr_lba_table + hdr->hdr_entries / entries_per_sec;
slba++, nent += entries_per_sec) {
slba < hdr->hdr_lba_table + hdr->hdr_entries / entries_per_sec;
slba++, nent += entries_per_sec) {
sector_updated = 0;
for (part = 0; part < entries_per_sec; part++) {
ent = &table[nent + part];
Expand All @@ -267,9 +268,11 @@ gptbootconv(const char *which, struct dsk *dskp, struct gpt_hdr *hdr,
}
if (!table_updated)
return;
hdr->hdr_crc_table = crc32(table, hdr->hdr_entries * hdr->hdr_entsz);
hdr->hdr_crc_self = 0;
hdr->hdr_crc_self = crc32(hdr, hdr->hdr_size);
hdr->hdr_crc_table = crc32(0, Z_NULL, 0);
hdr->hdr_crc_table = crc32(hdr->hdr_crc_table, table,
hdr->hdr_entries * hdr->hdr_entsz);
hdr->hdr_crc_self = crc32(0, Z_NULL, 0);
hdr->hdr_crc_self = crc32(hdr->hdr_crc_self, hdr, hdr->hdr_size);
bzero(secbuf, DEV_BSIZE);
bcopy(hdr, secbuf, hdr->hdr_size);
if (drvwrite(dskp, secbuf, hdr->hdr_lba_self, 1))
Expand Down Expand Up @@ -299,15 +302,15 @@ gptread_table(const char *which, const uuid_t *uuid, struct dsk *dskp,
}
ent = (struct gpt_ent *)secbuf;
for (part = 0; part < entries_per_sec; part++, ent++) {
bcopy(ent, &table[nent], sizeof(table[nent]));
bcopy(ent, &table[nent], sizeof (table[nent]));
if (++nent >= hdr->hdr_entries)
break;
}
if (nent >= hdr->hdr_entries)
break;
slba++;
}
if (crc32(table, nent * hdr->hdr_entsz) != hdr->hdr_crc_table) {
if (crc32(0, table, nent * hdr->hdr_entsz) != hdr->hdr_crc_table) {
printf("%s: %s GPT table checksum mismatch\n", BOOTPROG, which);
return (-1);
}
Expand Down
4 changes: 1 addition & 3 deletions usr/src/boot/sys/boot/common/gpt.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*-
/*
* Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
* All rights reserved.
*
Expand All @@ -22,8 +22,6 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/

#ifndef _GPT_H_
Expand Down
8 changes: 4 additions & 4 deletions usr/src/boot/sys/boot/common/part.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <sys/queue.h>
#include <sys/vtoc.h>

#include <crc32.h>
#include <zlib.h>
#include <part.h>
#include <uuid.h>

Expand Down Expand Up @@ -184,8 +184,8 @@ gpt_checkhdr(struct gpt_hdr *hdr, uint64_t lba_self,
return (NULL);
}
crc = le32toh(hdr->hdr_crc_self);
hdr->hdr_crc_self = 0;
if (crc32(hdr, sz) != crc) {
hdr->hdr_crc_self = crc32(0, Z_NULL, 0);
if (crc32(hdr->hdr_crc_self, (const Bytef *)hdr, sz) != crc) {
DEBUG("GPT header's CRC doesn't match");
return (NULL);
}
Expand Down Expand Up @@ -233,7 +233,7 @@ gpt_checktbl(const struct gpt_hdr *hdr, uint8_t *tbl, size_t size,
cnt = hdr->hdr_entries;
/* Check CRC only when buffer size is enough for table. */
if (hdr->hdr_crc_table !=
crc32(tbl, hdr->hdr_entries * hdr->hdr_entsz)) {
crc32(0, tbl, hdr->hdr_entries * hdr->hdr_entsz)) {
DEBUG("GPT table's CRC doesn't match");
return (-1);
}
Expand Down
1 change: 1 addition & 0 deletions usr/src/boot/sys/boot/efi/loader/Makefile.com
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ OBJS= autoload.o bootinfo.o conf.o copy.o efi_main.o framebuffer.o main.o \
CFLAGS= -O2
CPPFLAGS= -nostdinc -I../../../../../include -I../../..../
CPPFLAGS += -I../../../../../lib/libstand
CPPFLAGS += -I../../../../../lib/libz

include ../../Makefile.inc

Expand Down
2 changes: 0 additions & 2 deletions usr/src/boot/sys/boot/efi/loader/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ OBJS += load_elf32.o load_elf32_obj.o reloc_elf32.o \
SRCS += disk.c part.c dev_net.c
OBJS += disk.o part.o dev_net.o
CFLAGS += -DLOADER_DISK_SUPPORT
SRCS += crc32.c
OBJS += crc32.o
CFLAGS += -DLOADER_GPT_SUPPORT
CFLAGS += -DLOADER_MBR_SUPPORT

Expand Down
3 changes: 2 additions & 1 deletion usr/src/boot/sys/boot/i386/gptzfsboot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ CFLAGS= -nostdinc -DBOOTPROG=\"gptzfsboot\" \
-DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
-I../../../../include \
-I../../../../lib/libstand \
-I../../../../lib/libz \
-I../../common \
-I../common \
-I../../zfs \
Expand Down Expand Up @@ -76,7 +77,7 @@ install: all $(ROOTBOOTPROG)

OBJS = multiboot.o zfsboot.o sio.o cons.o panic.o devopen.o \
part.o biosmem.o smbios.o biosdisk.o devicename.o disk.o bcache.o \
time.o crc32.o
time.o

CLEANFILES= gptzfsboot $(OBJS)

Expand Down
2 changes: 1 addition & 1 deletion usr/src/boot/sys/boot/i386/loader/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ include $(SRC)/boot/Makefile.version
CFLAGS= -O2 -fno-reorder-functions
CPPFLAGS= -D_STANDALONE -nostdinc -I../../../../include -I../../..
CPPFLAGS += -I$(SRC)/uts/intel/sys/acpi
CPPFLAGS += -I../../../../lib/libz
LOADER= loader
NEWVERSWHAT= "ZFS enabled bootstrap loader" x86

Expand Down Expand Up @@ -72,7 +73,6 @@ SRCS += dev_net.c

SRCS += disk.c part.c
CPPFLAGS += -DLOADER_DISK_SUPPORT
SRCS += crc32.c
CPPFLAGS += -DLOADER_GPT_SUPPORT
CPPFLAGS += -DLOADER_MBR_SUPPORT

Expand Down

0 comments on commit 388010d

Please sign in to comment.