svn commit: r334046 - head/tools/tools/intel-ucode-split

Oliver Pinter oliver.pinter at hardenedbsd.org
Tue Jun 12 22:05:28 UTC 2018


On 5/22/18, Ed Maste <emaste at freebsd.org> wrote:
> Author: emaste
> Date: Tue May 22 14:35:33 2018
> New Revision: 334046
> URL: https://svnweb.freebsd.org/changeset/base/334046
>
> Log:
>   intel-ucode-split: add -n flag to skip creating output files
>
>   Sponsored by:	The FreeBSD Foundation
>
> Modified:
>   head/tools/tools/intel-ucode-split/intel-ucode-split.c

Hi!

Could you please MFC the intel-ucode-split related commits to 11-STABLE?


Thanks,
op

>
> Modified: head/tools/tools/intel-ucode-split/intel-ucode-split.c
> ==============================================================================
> --- head/tools/tools/intel-ucode-split/intel-ucode-split.c	Tue May 22
> 14:26:58 2018	(r334045)
> +++ head/tools/tools/intel-ucode-split/intel-ucode-split.c	Tue May 22
> 14:35:33 2018	(r334046)
> @@ -112,7 +112,7 @@ static void
>  usage(void)
>  {
>
> -	printf("ucode-split [-v] microcode_file\n");
> +	printf("ucode-split [-nv] microcode_file\n");
>  	exit(1);
>  }
>
> @@ -124,11 +124,14 @@ main(int argc, char *argv[])
>  	size_t len, resid;
>  	ssize_t rv;
>  	int c, ifd, ofd;
> -	bool vflag;
> +	bool nflag, vflag;
>
> -	vflag = false;
> -	while ((c = getopt(argc, argv, "v")) != -1) {
> +	nflag = vflag = false;
> +	while ((c = getopt(argc, argv, "nv")) != -1) {
>  		switch (c) {
> +		case 'n':
> +			nflag = true;
> +			break;
>  		case 'v':
>  			vflag = true;
>  			break;
> @@ -166,40 +169,48 @@ main(int argc, char *argv[])
>  		if (vflag)
>  			dump_header(&hdr);
>
> -		sig_str = format_signature(hdr.processor_signature);
> -		asprintf(&output_file, "%s.%02x", sig_str,
> -		    hdr.processor_flags & 0xff);
> -		free(sig_str);
> -		if (output_file == NULL)
> -			err(1, "asprintf");
> -		ofd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
> -		if (ofd < 0)
> -			err(1, "open");
> -
> -		/* Write header. */
> -		rv = write(ofd, &hdr, sizeof(hdr));
> -		if (rv < (ssize_t)sizeof(hdr))
> -			err(1, "write");
> -
> -		/* Copy data. */
>  		resid = (hdr.total_size != 0 ? hdr.total_size : 2048) -
>  		    sizeof(hdr);
>  		if (resid > 1 << 24) /* Arbitrary chosen maximum size. */
>  			errx(1, "header total_size too large");
> -		while (resid > 0) {
> -			len = resid < bufsize ? resid : bufsize;
> -			rv = read(ifd, buf, len);
> -			if (rv < 0)
> -				err(1, "read");
> -			else if (rv < (ssize_t)len)
> -				errx(1, "truncated microcode data");
> -			if (write(ofd, buf, len) < (ssize_t)len)
> +
> +		if (nflag) {
> +			if (lseek(ifd, resid, SEEK_CUR) == -1)
> +				err(1, "lseek");
> +			printf("\n");
> +		} else {
> +			sig_str = format_signature(hdr.processor_signature);
> +			asprintf(&output_file, "%s.%02x", sig_str,
> +			    hdr.processor_flags & 0xff);
> +			free(sig_str);
> +			if (output_file == NULL)
> +				err(1, "asprintf");
> +			ofd = open(output_file, O_WRONLY | O_CREAT | O_TRUNC,
> +			    0600);
> +			if (ofd < 0)
> +				err(1, "open");
> +	
> +			/* Write header. */
> +			rv = write(ofd, &hdr, sizeof(hdr));
> +			if (rv < (ssize_t)sizeof(hdr))
>  				err(1, "write");
> -			resid -= len;
> +	
> +			/* Copy data. */
> +			while (resid > 0) {
> +				len = resid < bufsize ? resid : bufsize;
> +				rv = read(ifd, buf, len);
> +				if (rv < 0)
> +					err(1, "read");
> +				else if (rv < (ssize_t)len)
> +					errx(1, "truncated microcode data");
> +				if (write(ofd, buf, len) < (ssize_t)len)
> +					err(1, "write");
> +				resid -= len;
> +			}
> +			if (vflag)
> +				printf("written to %s\n\n", output_file);
> +			close(ofd);
> +			free(output_file);
>  		}
> -		if (vflag)
> -			printf("written to %s\n\n", output_file);
> -		close(ofd);
> -		free(output_file);
>  	}
>  }
> _______________________________________________
> svn-src-head at freebsd.org mailing list
> https://lists.freebsd.org/mailman/listinfo/svn-src-head
> To unsubscribe, send any mail to "svn-src-head-unsubscribe at freebsd.org"
>


More information about the svn-src-all mailing list