svn commit: r345066 - in head/stand: common userboot/userboot

Kyle Evans kevans at FreeBSD.org
Tue Mar 12 16:21:41 UTC 2019


Author: kevans
Date: Tue Mar 12 16:21:39 2019
New Revision: 345066
URL: https://svnweb.freebsd.org/changeset/base/345066

Log:
  stand: Improve some debugging experience
  
  Some of these files using <FOO>_DEBUG defined a DEBUG() macro to serve as a
  debug-printf. -DDEBUG is useful to enable some debugging output across
  multiple ELF/common parts, so switch the DEBUG-as-printf macros over to
  something more like DPRINTF that is more commonly used for this kind of
  thing and less likely to conflict.
  
  userboot/elf64_freebsd debugging also assumed %llx for uint64; use PRIx64
  instead.
  
  MFC after:	1 week

Modified:
  head/stand/common/bcache.c
  head/stand/common/disk.c
  head/stand/common/interp_forth.c
  head/stand/common/part.c
  head/stand/userboot/userboot/elf64_freebsd.c

Modified: head/stand/common/bcache.c
==============================================================================
--- head/stand/common/bcache.c	Tue Mar 12 15:07:47 2019	(r345065)
+++ head/stand/common/bcache.c	Tue Mar 12 16:21:39 2019	(r345066)
@@ -44,9 +44,9 @@ __FBSDID("$FreeBSD$");
 /* #define BCACHE_DEBUG */
 
 #ifdef BCACHE_DEBUG
-# define DEBUG(fmt, args...)	printf("%s: " fmt "\n" , __func__ , ## args)
+# define DPRINTF(fmt, args...)	printf("%s: " fmt "\n" , __func__ , ## args)
 #else
-# define DEBUG(fmt, args...)
+# define DPRINTF(fmt, args...)
 #endif
 
 struct bcachectl
@@ -369,7 +369,7 @@ bcache_strategy(void *devdata, int rw, daddr_t blk, si
     /* bypass large requests, or when the cache is inactive */
     if (bc == NULL ||
 	((size * 2 / bcache_blksize) > bcache_nblks)) {
-	DEBUG("bypass %zu from %qu", size / bcache_blksize, blk);
+	DPRINTF("bypass %zu from %qu", size / bcache_blksize, blk);
 	bcache_bypasses++;
 	rw &= F_MASK;
 	return (dd->dv_strategy(dd->dv_devdata, rw, blk, size, buf, rsize));
@@ -444,7 +444,7 @@ bcache_insert(struct bcache *bc, daddr_t blkno)
     
     cand = BHASH(bc, blkno);
 
-    DEBUG("insert blk %llu -> %u # %d", blkno, cand, bcache_bcount);
+    DPRINTF("insert blk %llu -> %u # %d", blkno, cand, bcache_bcount);
     bc->bcache_ctl[cand].bc_blkno = blkno;
     bc->bcache_ctl[cand].bc_count = bcache_bcount++;
 }
@@ -461,7 +461,7 @@ bcache_invalidate(struct bcache *bc, daddr_t blkno)
     if (bc->bcache_ctl[i].bc_blkno == blkno) {
 	bc->bcache_ctl[i].bc_count = -1;
 	bc->bcache_ctl[i].bc_blkno = -1;
-	DEBUG("invalidate blk %llu", blkno);
+	DPRINTF("invalidate blk %llu", blkno);
     }
 }
 

Modified: head/stand/common/disk.c
==============================================================================
--- head/stand/common/disk.c	Tue Mar 12 15:07:47 2019	(r345065)
+++ head/stand/common/disk.c	Tue Mar 12 16:21:39 2019	(r345066)
@@ -38,9 +38,9 @@ __FBSDID("$FreeBSD$");
 #include "disk.h"
 
 #ifdef DISK_DEBUG
-# define DEBUG(fmt, args...)	printf("%s: " fmt "\n" , __func__ , ## args)
+# define DPRINTF(fmt, args...)	printf("%s: " fmt "\n" , __func__ , ## args)
 #else
-# define DEBUG(fmt, args...)
+# define DPRINTF(fmt, args...)
 #endif
 
 struct open_disk {
@@ -231,7 +231,7 @@ disk_open(struct disk_devdesc *dev, uint64_t mediasize
 	rc = 0;
 	od = (struct open_disk *)malloc(sizeof(struct open_disk));
 	if (od == NULL) {
-		DEBUG("no memory");
+		DPRINTF("no memory");
 		return (ENOMEM);
 	}
 	dev->dd.d_opendata = od;
@@ -252,14 +252,14 @@ disk_open(struct disk_devdesc *dev, uint64_t mediasize
 	slice = dev->d_slice;
 	partition = dev->d_partition;
 
-	DEBUG("%s unit %d, slice %d, partition %d => %p",
+	DPRINTF("%s unit %d, slice %d, partition %d => %p",
 	    disk_fmtdev(dev), dev->dd.d_unit, dev->d_slice, dev->d_partition, od);
 
 	/* Determine disk layout. */
 	od->table = ptable_open(&partdev, mediasize / sectorsize, sectorsize,
 	    ptblread);
 	if (od->table == NULL) {
-		DEBUG("Can't read partition table");
+		DPRINTF("Can't read partition table");
 		rc = ENXIO;
 		goto out;
 	}
@@ -315,7 +315,7 @@ disk_open(struct disk_devdesc *dev, uint64_t mediasize
 		table = ptable_open(dev, part.end - part.start + 1,
 		    od->sectorsize, ptblread);
 		if (table == NULL) {
-			DEBUG("Can't read BSD label");
+			DPRINTF("Can't read BSD label");
 			rc = ENXIO;
 			goto out;
 		}
@@ -343,12 +343,12 @@ out:
 		if (od->table != NULL)
 			ptable_close(od->table);
 		free(od);
-		DEBUG("%s could not open", disk_fmtdev(dev));
+		DPRINTF("%s could not open", disk_fmtdev(dev));
 	} else {
 		/* Save the slice and partition number to the dev */
 		dev->d_slice = slice;
 		dev->d_partition = partition;
-		DEBUG("%s offset %lld => %p", disk_fmtdev(dev),
+		DPRINTF("%s offset %lld => %p", disk_fmtdev(dev),
 		    (long long)dev->d_offset, od);
 	}
 	return (rc);
@@ -360,7 +360,7 @@ disk_close(struct disk_devdesc *dev)
 	struct open_disk *od;
 
 	od = (struct open_disk *)dev->dd.d_opendata;
-	DEBUG("%s closed => %p", disk_fmtdev(dev), od);
+	DPRINTF("%s closed => %p", disk_fmtdev(dev), od);
 	ptable_close(od->table);
 	free(od);
 	return (0);

Modified: head/stand/common/interp_forth.c
==============================================================================
--- head/stand/common/interp_forth.c	Tue Mar 12 15:07:47 2019	(r345065)
+++ head/stand/common/interp_forth.c	Tue Mar 12 16:21:39 2019	(r345066)
@@ -39,9 +39,9 @@ INTERP_DEFINE("4th");
 /* #define BFORTH_DEBUG */
 
 #ifdef BFORTH_DEBUG
-#define	DEBUG(fmt, args...)	printf("%s: " fmt "\n" , __func__ , ## args)
+#define	DPRINTF(fmt, args...)	printf("%s: " fmt "\n" , __func__ , ## args)
 #else
-#define	DEBUG(fmt, args...)
+#define	DPRINTF(fmt, args...)
 #endif
 
 /*
@@ -128,7 +128,7 @@ bf_command(FICL_VM *vm)
 			vmUpdateTib(vm, tail + len);
 		}
 	}
-	DEBUG("cmd '%s'", line);
+	DPRINTF("cmd '%s'", line);
 
 	command_errmsg = command_errbuf;
 	command_errbuf[0] = 0;
@@ -305,7 +305,7 @@ bf_run(const char *line)
 	 */
 	result = ficlExec(bf_vm, __DECONST(char *, line));
 
-	DEBUG("ficlExec '%s' = %d", line, result);
+	DPRINTF("ficlExec '%s' = %d", line, result);
 	switch (result) {
 	case VM_OUTOFTEXT:
 	case VM_ABORTQ:

Modified: head/stand/common/part.c
==============================================================================
--- head/stand/common/part.c	Tue Mar 12 15:07:47 2019	(r345065)
+++ head/stand/common/part.c	Tue Mar 12 16:21:39 2019	(r345066)
@@ -44,9 +44,9 @@ __FBSDID("$FreeBSD$");
 #include <uuid.h>
 
 #ifdef PART_DEBUG
-#define	DEBUG(fmt, args...) printf("%s: " fmt "\n", __func__, ## args)
+#define	DPRINTF(fmt, args...) printf("%s: " fmt "\n", __func__, ## args)
 #else
-#define	DEBUG(fmt, args...)
+#define	DPRINTF(fmt, args...)
 #endif
 
 #ifdef LOADER_GPT_SUPPORT
@@ -155,34 +155,34 @@ gpt_checkhdr(struct gpt_hdr *hdr, uint64_t lba_self, u
 	uint32_t sz, crc;
 
 	if (memcmp(hdr->hdr_sig, GPT_HDR_SIG, sizeof(hdr->hdr_sig)) != 0) {
-		DEBUG("no GPT signature");
+		DPRINTF("no GPT signature");
 		return (NULL);
 	}
 	sz = le32toh(hdr->hdr_size);
 	if (sz < 92 || sz > sectorsize) {
-		DEBUG("invalid GPT header size: %d", sz);
+		DPRINTF("invalid GPT header size: %d", sz);
 		return (NULL);
 	}
 	crc = le32toh(hdr->hdr_crc_self);
 	hdr->hdr_crc_self = 0;
 	if (crc32(hdr, sz) != crc) {
-		DEBUG("GPT header's CRC doesn't match");
+		DPRINTF("GPT header's CRC doesn't match");
 		return (NULL);
 	}
 	hdr->hdr_crc_self = crc;
 	hdr->hdr_revision = le32toh(hdr->hdr_revision);
 	if (hdr->hdr_revision < GPT_HDR_REVISION) {
-		DEBUG("unsupported GPT revision %d", hdr->hdr_revision);
+		DPRINTF("unsupported GPT revision %d", hdr->hdr_revision);
 		return (NULL);
 	}
 	hdr->hdr_lba_self = le64toh(hdr->hdr_lba_self);
 	if (hdr->hdr_lba_self != lba_self) {
-		DEBUG("self LBA doesn't match");
+		DPRINTF("self LBA doesn't match");
 		return (NULL);
 	}
 	hdr->hdr_lba_alt = le64toh(hdr->hdr_lba_alt);
 	if (hdr->hdr_lba_alt == hdr->hdr_lba_self) {
-		DEBUG("invalid alternate LBA");
+		DPRINTF("invalid alternate LBA");
 		return (NULL);
 	}
 	hdr->hdr_entries = le32toh(hdr->hdr_entries);
@@ -190,7 +190,7 @@ gpt_checkhdr(struct gpt_hdr *hdr, uint64_t lba_self, u
 	if (hdr->hdr_entries == 0 ||
 	    hdr->hdr_entsz < sizeof(struct gpt_ent) ||
 	    sectorsize % hdr->hdr_entsz != 0) {
-		DEBUG("invalid entry size or number of entries");
+		DPRINTF("invalid entry size or number of entries");
 		return (NULL);
 	}
 	hdr->hdr_lba_start = le64toh(hdr->hdr_lba_start);
@@ -214,7 +214,7 @@ gpt_checktbl(const struct gpt_hdr *hdr, uint8_t *tbl, 
 		/* Check CRC only when buffer size is enough for table. */
 		if (hdr->hdr_crc_table !=
 		    crc32(tbl, hdr->hdr_entries * hdr->hdr_entsz)) {
-			DEBUG("GPT table's CRC doesn't match");
+			DPRINTF("GPT table's CRC doesn't match");
 			return (-1);
 		}
 	}
@@ -310,7 +310,7 @@ ptable_gptread(struct ptable *table, void *dev, diskre
 		table->type = PTABLE_NONE;
 		goto out;
 	}
-	DEBUG("GPT detected");
+	DPRINTF("GPT detected");
 	size = MIN(hdr.hdr_entries * hdr.hdr_entsz,
 	    MAXTBLSZ * table->sectorsize);
 
@@ -346,7 +346,7 @@ ptable_gptread(struct ptable *table, void *dev, diskre
 		entry->flags = le64toh(ent->ent_attr);
 		memcpy(&entry->type.gpt, &ent->ent_type, sizeof(uuid_t));
 		STAILQ_INSERT_TAIL(&table->entries, entry, entry);
-		DEBUG("new GPT partition added");
+		DPRINTF("new GPT partition added");
 	}
 out:
 	free(buf);
@@ -402,7 +402,7 @@ ptable_ebrread(struct ptable *table, void *dev, diskre
 	buf = malloc(table->sectorsize);
 	if (buf == NULL)
 		return (table);
-	DEBUG("EBR detected");
+	DPRINTF("EBR detected");
 	for (i = 0; i < MAXEBRENTRIES; i++) {
 #if 0	/* Some BIOSes return an incorrect number of sectors */
 		if (offset >= table->sectors)
@@ -430,7 +430,7 @@ ptable_ebrread(struct ptable *table, void *dev, diskre
 		entry->flags = dp[0].dp_flag;
 		entry->type.mbr = dp[0].dp_typ;
 		STAILQ_INSERT_TAIL(&table->entries, entry, entry);
-		DEBUG("new EBR partition added");
+		DPRINTF("new EBR partition added");
 		if (dp[1].dp_typ == 0)
 			break;
 		offset = e1->part.start + le32toh(dp[1].dp_start);
@@ -470,14 +470,14 @@ ptable_bsdread(struct ptable *table, void *dev, diskre
 	int i;
 
 	if (table->sectorsize < sizeof(struct disklabel)) {
-		DEBUG("Too small sectorsize");
+		DPRINTF("Too small sectorsize");
 		return (table);
 	}
 	buf = malloc(table->sectorsize);
 	if (buf == NULL)
 		return (table);
 	if (dread(dev, buf, 1, 1) != 0) {
-		DEBUG("read failed");
+		DPRINTF("read failed");
 		ptable_close(table);
 		table = NULL;
 		goto out;
@@ -487,15 +487,15 @@ ptable_bsdread(struct ptable *table, void *dev, diskre
 	    le32toh(dl->d_magic2) != DISKMAGIC)
 		goto out;
 	if (le32toh(dl->d_secsize) != table->sectorsize) {
-		DEBUG("unsupported sector size");
+		DPRINTF("unsupported sector size");
 		goto out;
 	}
 	dl->d_npartitions = le16toh(dl->d_npartitions);
 	if (dl->d_npartitions > 20 || dl->d_npartitions < 8) {
-		DEBUG("invalid number of partitions");
+		DPRINTF("invalid number of partitions");
 		goto out;
 	}
-	DEBUG("BSD detected");
+	DPRINTF("BSD detected");
 	part = &dl->d_partitions[0];
 	raw_offset = le32toh(part[RAW_PART].p_offset);
 	for (i = 0; i < dl->d_npartitions; i++, part++) {
@@ -513,7 +513,7 @@ ptable_bsdread(struct ptable *table, void *dev, diskre
 		entry->part.index = i; /* starts from zero */
 		entry->type.bsd = part->p_fstype;
 		STAILQ_INSERT_TAIL(&table->entries, entry, entry);
-		DEBUG("new BSD partition added");
+		DPRINTF("new BSD partition added");
 	}
 	table->type = PTABLE_BSD;
 out:
@@ -556,7 +556,7 @@ ptable_vtoc8read(struct ptable *table, void *dev, disk
 	if (buf == NULL)
 		return (table);
 	if (dread(dev, buf, 1, 0) != 0) {
-		DEBUG("read failed");
+		DPRINTF("read failed");
 		ptable_close(table);
 		table = NULL;
 		goto out;
@@ -566,20 +566,20 @@ ptable_vtoc8read(struct ptable *table, void *dev, disk
 	for (i = sum = 0; i < sizeof(struct vtoc8); i += sizeof(sum))
 		sum ^= be16dec(buf + i);
 	if (sum != 0) {
-		DEBUG("incorrect checksum");
+		DPRINTF("incorrect checksum");
 		goto out;
 	}
 	if (be16toh(dl->nparts) != VTOC8_NPARTS) {
-		DEBUG("invalid number of entries");
+		DPRINTF("invalid number of entries");
 		goto out;
 	}
 	sectors = be16toh(dl->nsecs);
 	heads = be16toh(dl->nheads);
 	if (sectors * heads == 0) {
-		DEBUG("invalid geometry");
+		DPRINTF("invalid geometry");
 		goto out;
 	}
-	DEBUG("VTOC8 detected");
+	DPRINTF("VTOC8 detected");
 	for (i = 0; i < VTOC8_NPARTS; i++) {
 		dl->part[i].tag = be16toh(dl->part[i].tag);
 		if (i == VTOC_RAW_PART ||
@@ -595,7 +595,7 @@ ptable_vtoc8read(struct ptable *table, void *dev, disk
 		entry->part.index = i; /* starts from zero */
 		entry->type.vtoc8 = dl->part[i].tag;
 		STAILQ_INSERT_TAIL(&table->entries, entry, entry);
-		DEBUG("new VTOC8 partition added");
+		DPRINTF("new VTOC8 partition added");
 	}
 	table->type = PTABLE_VTOC8;
 out:
@@ -619,7 +619,7 @@ ptable_iso9660read(struct ptable *table, void *dev, di
 		return (table);
 		
 	if (dread(dev, buf, 1, cdb2devb(16)) != 0) {
-		DEBUG("read failed");
+		DPRINTF("read failed");
 		ptable_close(table);
 		table = NULL;
 		goto out;
@@ -663,7 +663,7 @@ ptable_open(void *dev, uint64_t sectors, uint16_t sect
 		return (NULL);
 	/* First, read the MBR. */
 	if (dread(dev, buf, 1, DOSBBSECTOR) != 0) {
-		DEBUG("read failed");
+		DPRINTF("read failed");
 		goto out;
 	}
 
@@ -703,7 +703,7 @@ ptable_open(void *dev, uint64_t sectors, uint16_t sect
 	/* Check the MBR magic. */
 	if (buf[DOSMAGICOFFSET] != 0x55 ||
 	    buf[DOSMAGICOFFSET + 1] != 0xaa) {
-		DEBUG("magic sequence not found");
+		DPRINTF("magic sequence not found");
 #if defined(LOADER_GPT_SUPPORT)
 		/* There is no PMBR, check that we have backup GPT */
 		table->type = PTABLE_GPT;
@@ -715,13 +715,13 @@ ptable_open(void *dev, uint64_t sectors, uint16_t sect
 	dp = (struct dos_partition *)(buf + DOSPARTOFF);
 	for (i = 0, count = 0; i < NDOSPART; i++) {
 		if (dp[i].dp_flag != 0 && dp[i].dp_flag != 0x80) {
-			DEBUG("invalid partition flag %x", dp[i].dp_flag);
+			DPRINTF("invalid partition flag %x", dp[i].dp_flag);
 			goto out;
 		}
 #ifdef LOADER_GPT_SUPPORT
 		if (dp[i].dp_typ == DOSPTYP_PMBR) {
 			table->type = PTABLE_GPT;
-			DEBUG("PMBR detected");
+			DPRINTF("PMBR detected");
 		}
 #endif
 		if (dp[i].dp_typ != 0)
@@ -731,9 +731,9 @@ ptable_open(void *dev, uint64_t sectors, uint16_t sect
 	if (table->type == PTABLE_GPT && count > 1) {
 		if (dp[1].dp_typ != DOSPTYP_HFS) {
 			table->type = PTABLE_NONE;
-			DEBUG("Incorrect PMBR, ignore it");
+			DPRINTF("Incorrect PMBR, ignore it");
 		} else {
-			DEBUG("Bootcamp detected");
+			DPRINTF("Bootcamp detected");
 		}
 	}
 #ifdef LOADER_GPT_SUPPORT
@@ -744,7 +744,7 @@ ptable_open(void *dev, uint64_t sectors, uint16_t sect
 #endif
 #ifdef LOADER_MBR_SUPPORT
 	/* Read MBR. */
-	DEBUG("MBR detected");
+	DPRINTF("MBR detected");
 	table->type = PTABLE_MBR;
 	for (i = has_ext = 0; i < NDOSPART; i++) {
 		if (dp[i].dp_typ == 0)
@@ -770,7 +770,7 @@ ptable_open(void *dev, uint64_t sectors, uint16_t sect
 		entry->flags = dp[i].dp_flag;
 		entry->type.mbr = dp[i].dp_typ;
 		STAILQ_INSERT_TAIL(&table->entries, entry, entry);
-		DEBUG("new MBR partition added");
+		DPRINTF("new MBR partition added");
 	}
 	if (has_ext) {
 		table = ptable_ebrread(table, dev, dread);

Modified: head/stand/userboot/userboot/elf64_freebsd.c
==============================================================================
--- head/stand/userboot/userboot/elf64_freebsd.c	Tue Mar 12 15:07:47 2019	(r345065)
+++ head/stand/userboot/userboot/elf64_freebsd.c	Tue Mar 12 16:21:39 2019	(r345066)
@@ -31,6 +31,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/param.h>
 #include <sys/exec.h>
 #include <sys/linker.h>
+#ifdef DEBUG
+#include <machine/_inttypes.h>
+#endif
 #include <string.h>
 #include <i386/include/bootinfo.h>
 #include <machine/elf.h>
@@ -136,7 +139,7 @@ elf64_exec(struct preloaded_file *fp)
 	}
 
 #ifdef DEBUG
-	printf("Start @ %#llx ...\n", ehdr->e_entry);
+	printf("Start @ %#"PRIx64" ...\n", ehdr->e_entry);
 #endif
 
 	dev_cleanup();


More information about the svn-src-head mailing list