Module Name: src Committed By: tsutsui Date: Mon May 6 18:08:49 UTC 2024
Modified Files: src/sys/arch/hp300/stand/mkboot: mkboot.c Log Message: Misc cosmetic changes for mostly readability. - KNF and add some newlines per blocks - define and use proper bintobcd() macro - make local functions and variables static The same uboot.lif binaries are generated. To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/sys/arch/hp300/stand/mkboot/mkboot.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/hp300/stand/mkboot/mkboot.c diff -u src/sys/arch/hp300/stand/mkboot/mkboot.c:1.17 src/sys/arch/hp300/stand/mkboot/mkboot.c:1.18 --- src/sys/arch/hp300/stand/mkboot/mkboot.c:1.17 Sun May 5 07:36:37 2024 +++ src/sys/arch/hp300/stand/mkboot/mkboot.c Mon May 6 18:08:49 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: mkboot.c,v 1.17 2024/05/05 07:36:37 tsutsui Exp $ */ +/* $NetBSD: mkboot.c,v 1.18 2024/05/06 18:08:49 tsutsui Exp $ */ /* * Copyright (c) 1990, 1993 @@ -46,7 +46,7 @@ The Regents of the University of Califor #ifdef notdef static char sccsid[] = "@(#)mkboot.c 7.2 (Berkeley) 12/16/90"; #endif -__RCSID("$NetBSD: mkboot.c,v 1.17 2024/05/05 07:36:37 tsutsui Exp $"); +__RCSID("$NetBSD: mkboot.c,v 1.18 2024/05/06 18:08:49 tsutsui Exp $"); #endif /* not lint */ #include <sys/param.h> @@ -78,17 +78,20 @@ __RCSID("$NetBSD: mkboot.c,v 1.17 2024/0 #define btolifs(b) (((b) + (SECTSIZE - 1)) / SECTSIZE) #define lifstob(s) ((s) * SECTSIZE) -uint32_t loadpoint = ULONG_MAX; -struct load ld; -struct lifvol lifv; -struct lifdir lifd[LIF_NUMDIR]; -time_t repro_epoch = 0; +#define bintobcd(bin) ((((bin) / 10) << 4) | ((bin) % 10)) + +static uint32_t loadpoint = ULONG_MAX; +static struct load ld; +static struct lifvol lifv; +static struct lifdir lifd[LIF_NUMDIR]; +static time_t repro_epoch = 0; int main(int, char **); -void bcddate(char *, char *); -char *lifname(char *); -int putfile(char *, int); -void usage(void); + +static void bcddate(char *, char *); +static char *lifname(char *); +static int putfile(char *, int); +static void usage(void); #ifndef __CTASSERT #define __CTASSERT(X) @@ -121,7 +124,6 @@ main(int argc, char **argv) int n, to, ch; int count; - while ((ch = getopt(argc, argv, "l:t:")) != -1) switch (ch) { case 'l': @@ -158,14 +160,16 @@ main(int argc, char **argv) if ((to = open(argv[0], O_WRONLY | O_TRUNC | O_CREAT, 0644)) == -1) err(1, "Can't open `%s'", argv[0]); + /* clear possibly unused directory entries */ CLEAR(lifd[1].dir_name, " ", sizeof(lifd[1].dir_name)); - lifd[1].dir_type = htobe16(-1); + lifd[1].dir_type = htobe16(0xFFFF); lifd[1].dir_addr = htobe32(0); lifd[1].dir_length = htobe32(0); - lifd[1].dir_flag = htobe16(0xFF); + lifd[1].dir_flag = htobe16(0x00FF); lifd[1].dir_exec = htobe32(0); lifd[7] = lifd[6] = lifd[5] = lifd[4] = lifd[3] = lifd[2] = lifd[1]; + /* record volume info */ lifv.vol_id = htobe16(VOL_ID); CLEAR(lifv.vol_label, "BOOT43", sizeof(lifv.vol_label)); @@ -173,6 +177,7 @@ main(int argc, char **argv) lifv.vol_oct = htobe16(VOL_OCT); lifv.vol_dirsize = htobe32(btolifs(LIF_DIRSIZE)); lifv.vol_version = htobe16(1); + /* output bootfile one */ lseek(to, LIF_FILESTART, SEEK_SET); count = putfile(n1, to); @@ -185,10 +190,11 @@ main(int argc, char **argv) lifd[0].dir_flag = htobe16(DIR_FLAG); lifd[0].dir_exec = htobe32(loadpoint); lifv.vol_length = htobe32(be32toh(lifd[0].dir_addr) + - be32toh(lifd[0].dir_length)); + be32toh(lifd[0].dir_length)); + /* if there is an optional second boot program, output it */ - if (n2) { - lseek(to, LIF_FILESTART+lifstob(n), SEEK_SET); + if (n2 != NULL) { + lseek(to, LIF_FILESTART + lifstob(n), SEEK_SET); count = putfile(n2, to); n = btolifs(count); strcpy(lifd[1].dir_name, lifname(n2)); @@ -199,12 +205,13 @@ main(int argc, char **argv) lifd[1].dir_flag = htobe16(DIR_FLAG); lifd[1].dir_exec = htobe32(loadpoint); lifv.vol_length = htobe32(be32toh(lifd[1].dir_addr) + - be32toh(lifd[1].dir_length)); + be32toh(lifd[1].dir_length)); } + /* ditto for three */ - if (n3) { - lseek(to, LIF_FILESTART+lifstob(lifd[0].dir_length+n), - SEEK_SET); + if (n3 != NULL) { + lseek(to, LIF_FILESTART + lifstob(lifd[0].dir_length + n), + SEEK_SET); count = putfile(n3, to); n = btolifs(count); strcpy(lifd[2].dir_name, lifname(n3)); @@ -215,17 +222,19 @@ main(int argc, char **argv) lifd[2].dir_flag = htobe16(DIR_FLAG); lifd[2].dir_exec = htobe32(loadpoint); lifv.vol_length = htobe32(be32toh(lifd[2].dir_addr) + - be32toh(lifd[2].dir_length)); + be32toh(lifd[2].dir_length)); } + /* output volume/directory header info */ lseek(to, LIF_VOLSTART, SEEK_SET); write(to, &lifv, LIF_VOLSIZE); lseek(to, LIF_DIRSTART, SEEK_SET); write(to, lifd, LIF_DIRSIZE); + return EXIT_SUCCESS; } -int +static int putfile(char *from, int to) { int fd; @@ -245,10 +254,11 @@ putfile(char *from, int to) write(to, &ld, sizeof(ld)); write(to, bp, statb.st_size); free(bp); - return (statb.st_size + sizeof(ld)); + + return statb.st_size + sizeof(ld); } -void +static void usage(void) { @@ -257,7 +267,7 @@ usage(void) exit(EXIT_FAILURE); } -char * +static char * lifname(char *str) { static char lname[10] = "SYS_XXXXX"; @@ -275,33 +285,28 @@ lifname(char *str) break; str++; } - for ( ; i < 10; i++) + for (; i < 10; i++) lname[i] = '\0'; - return(lname); + + return lname; } -void +static void bcddate(char *name, char *toc) { struct stat statb; struct tm *tm; - if (repro_epoch) + if (repro_epoch != 0) tm = gmtime(&repro_epoch); else { stat(name, &statb); tm = localtime(&statb.st_ctime); } - *toc = ((tm->tm_mon+1) / 10) << 4; - *toc++ |= (tm->tm_mon+1) % 10; - *toc = (tm->tm_mday / 10) << 4; - *toc++ |= tm->tm_mday % 10; - *toc = (tm->tm_year / 10) << 4; - *toc++ |= tm->tm_year % 10; - *toc = (tm->tm_hour / 10) << 4; - *toc++ |= tm->tm_hour % 10; - *toc = (tm->tm_min / 10) << 4; - *toc++ |= tm->tm_min % 10; - *toc = (tm->tm_sec / 10) << 4; - *toc |= tm->tm_sec % 10; + *toc++ = bintobcd(tm->tm_mon + 1); + *toc++ = bintobcd(tm->tm_mday); + *toc++ = bintobcd(tm->tm_year); + *toc++ = bintobcd(tm->tm_hour); + *toc++ = bintobcd(tm->tm_min); + *toc = bintobcd(tm->tm_sec); }