Debian Bug report logs - #86225
corel-util: Please update flashwrite, and maybe add nettrom?

Package: nwutil; Maintainer for nwutil is (unknown);

Reported by: Adam C Powell IV <hazelsct@mit.edu>

Date: Fri, 16 Feb 2001 20:48:02 UTC

Severity: important

Tags: patch

Done: Martin Michlmayr <tbm@cyrius.com>

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Tor Slettnes <tor@slett.net>:
Bug#86225; Package corel-util. Full text and rfc822 format available.

Acknowledgement sent to Adam C Powell IV <hazelsct@mit.edu>:
New Bug report received and forwarded. Copy sent to Tor Slettnes <tor@slett.net>. Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: Adam C Powell IV <hazelsct@mit.edu>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: corel-util: Please update flashwrite, and maybe add nettrom?
Date: Fri, 16 Feb 2001 15:36:26 -0500
Package: corel-util
Version: 1.2-2
Severity: important

Greetings,

The flashwrite in corel-util is ancient, and seems to be incapable of writing
the flash, at least with newer kernels (tried 2.2.13, 2.3.99-pre8-rmk1).
Please upgrade it, and it might help to throw in a new nettrom, such as 2.3.3,
for it to write.  (Consider the second part "wishlist", but I'd say the first
constitutes pretty major breakage.)

Thank you again,

-Adam P.

GPG fingerprint: D54D 1AEE B11C CE9B A02B  C5DD 526F 01E8 564E E4B6

             Welcome to the best software in the world today cafe!

-- System Information
Debian Release: testing/unstable
Kernel Version: Linux p4-117-1 2.3.99-pre8-rmk1 #1 Mon May 15 13:46:57 EDT
2000
armv4l unknown

Versions of the packages corel-util depends on:
ii  libc6          2.2.1-1        GNU C Library: Shared libraries and Timezone






Bug reassigned from package `corel-util' to `nwutil'. Request was from Martin Michlmayr <tbm@cyrius.com> to control@bugs.debian.org. Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Philip Blundell <pb@debian.org>, nwutil@packages.qa.debian.org:
Bug#86225; Package nwutil. Full text and rfc822 format available.

Acknowledgement sent to Petter Reinholdtsen <pere@hungry.com>:
Extra info received and forwarded to list. Copy sent to Philip Blundell <pb@debian.org>, nwutil@packages.qa.debian.org. Full text and rfc822 format available.

Message #12 received at 86225@bugs.debian.org (full text, mbox):

From: Petter Reinholdtsen <pere@hungry.com>
To: 86225@bugs.debian.org
Cc: control@bugs.debian.org
Subject: Re: corel-util: Please update flashwrite, and maybe add nettrom
Date: Sun, 10 Mar 2002 22:20:22 +0100
tags 86225 + patch
thanks

The following patch adds a new binary nwflashwrite.  The source was
sent to me by Ralph Siemsen.  The only line I changed was the line
including "nwflash.h".  I renamed the source from flashwrite to
nwflashwrite to avoid future name conflicts with the 'official'
version.

diff -rNu nwutil-1.4/Makefile nwutil-1.4-pere/Makefile
--- nwutil-1.4/Makefile	Sun Mar 10 20:27:05 2002
+++ nwutil-1.4-pere/Makefile	Sun Mar 10 21:47:41 2002
@@ -2,7 +2,7 @@
 
 CC	 = gcc
 CFLAGS	 = -O2 -fsigned-char -omit-frame-pointer -Wall
-OBJS 	 = start_wdog set_therm fan_ctrl debug
+OBJS 	 = start_wdog set_therm fan_ctrl debug nwflashwrite
 MANPGS	 = start_wdog.8 set_therm.8 fan_ctrl.8 debug.8
 PREFIX	 = $(DESTDIR)/usr
 
diff -rNu nwutil-1.4/debian/changelog nwutil-1.4-pere/debian/changelog
--- nwutil-1.4/debian/changelog	Sun Mar 10 20:27:05 2002
+++ nwutil-1.4-pere/debian/changelog	Sun Mar 10 21:48:11 2002
@@ -1,3 +1,9 @@
+nwutil (1.4-3.1) unstable; urgency=low
+
+  * Add nwflashwrite.  Needed small rewrite to get it to compile.
+
+ -- Petter Reinholdtsen <pere@hungry.com>  Sun, 10 Mar 2002 21:48:11 +0100
+
 nwutil (1.4-3) unstable; urgency=low
 
   * Really change Maintainer: field this time.  Am I dumb or what?
diff -rNu nwutil-1.4/flashlogo/flashlogo.h nwutil-1.4-pere/flashlogo/flashlogo.h
--- nwutil-1.4/flashlogo/flashlogo.h	Sun Mar 10 20:27:05 2002
+++ nwutil-1.4-pere/flashlogo/flashlogo.h	Sun Mar 10 21:44:52 2002
@@ -1,9 +1,7 @@
 #ifndef _FLASHLOGO_H
 #define _FLASHLOGO_H
 
-#define CMD_WRITE_DISABLE 0 
-#define CMD_WRITE_ENABLE 0x28
-#define CMD_WRITE_BASE64K_ENABLE 0x47
+#include "nwflash.h"
 
 #define FLASH_EACCES	-100
 #define FLASH_EBADSIZE	-101
diff -rNu nwutil-1.4/flashlogo/nwflash.h nwutil-1.4-pere/flashlogo/nwflash.h
--- nwutil-1.4/flashlogo/nwflash.h	Thu Jan  1 01:00:00 1970
+++ nwutil-1.4-pere/flashlogo/nwflash.h	Sun Mar 10 21:44:40 2002
@@ -0,0 +1,8 @@
+#ifndef _NWFLASH_H
+
+#define CMD_WRITE_DISABLE 0 
+#define CMD_WRITE_ENABLE 0x28
+#define CMD_WRITE_BASE64K_ENABLE 0x47
+
+#endif /* not _NWFLASH_H */
+
diff -rNu nwutil-1.4/nwflashwrite.c nwutil-1.4-pere/nwflashwrite.c
--- nwutil-1.4/nwflashwrite.c	Thu Jan  1 01:00:00 1970
+++ nwutil-1.4-pere/nwflashwrite.c	Sun Mar 10 21:45:01 2002
@@ -0,0 +1,280 @@
+/*
+ * flashwrite.c: programming the flash memory on a NetWinder
+ * Copyright 1998, 1999  Rebel.com
+ *
+ * History
+ *	Jan 25, 2000 - Andrew E. Mileski <andrewm@netwinder.org>
+ *	Beautified and made warning free
+ *
+ *      Oct 27, 1999 - woody - reinstated interactive file info.
+ *	Fixed report for starting offset > 0
+ *	Added checking the flash size, close all files on error.
+ *
+ *	Jun 24, 1999 - Ralph Siemsen <ralphs@netwinder.org>
+ *	Added are-you-sure question and override (-yes) option.
+ *	More verbose reporting of offset range errors.
+ *
+ *	May 16, 1999 - Andrew E. Mileski <andrewm@netwinder.org>
+ * 	Cleanup and made to safely flash any amount at any offset.
+ *
+ *	?, 1998 - Woody Suwalski <woody@netwinder.org>
+ *	Original writing.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+/*
+ * Find CMD_WRITE_BASE64K_ENABLE, CMD_WRITE_ENABLE and CMD_WRITE_DISABLE
+ */
+#include "flashlogo/nwflash.h"
+
+/* These must be powers of 2 */
+#define FLASH_BANK	(64 * 1024)
+#define MAX_FLASH	(4 * 1024 * 1024)
+#define FLASH_MASK	(FLASH_BANK - 1)
+
+int flashsize(int fd)
+{
+	int size = 0;
+
+	if (lseek(fd, 4 * 1024 * 1024, SEEK_SET) > 0)
+		size = 4 * 1024 * 1024;
+	else if (lseek(fd, 1024 * 1024, SEEK_SET) > 0)
+		size = 1024 * 1024;
+	return size;
+}
+
+void fatal_error(void)
+{
+	fprintf(stderr, "Fatal error!  Try again!\n");
+}
+
+int flashwrite(char *datafile, int flash_offset, int base64_ok)
+{
+	int buf_offset, data_fd, flash_fd, flash_size, rc, written;
+	char *buf;
+
+	/* Writing to first 64k only if enabled */
+	if (!base64_ok && flash_offset < FLASH_BANK) {
+		fprintf(
+			stderr,
+			"Writing the first 64k not permitted without -base64\n"
+		);
+		return 1;
+	}
+
+	/* Writing to negative offset is illegal */
+	if (flash_offset < 0) {
+		fprintf(stderr, "Invalid offset\n");
+		return 1;
+	}
+
+	flash_fd = open("/dev/nwflash", O_RDWR);
+	if (flash_fd <= 0) {
+		perror("Error opening flash device");
+		return 1;
+	}
+
+	/* Warn if writing beyond 4MB */
+	flash_size = flashsize(flash_fd);
+	if (flash_offset >= flash_size) {
+		fprintf(
+			stderr,
+			"Error: offset above %dMB > flash size %dMB!\n",
+			(flash_offset / 1024) / 1024,
+			(flash_size / 1024) / 1024
+		);
+		close(flash_fd);
+		return 1;
+	}
+
+	if (base64_ok)
+		ioctl(flash_fd, CMD_WRITE_BASE64K_ENABLE);
+
+	buf = (char *) malloc(FLASH_BANK);
+	if (!buf) {
+		perror("Can't allocate a buffer");
+		close(flash_fd);
+		return 1;
+	}
+
+	data_fd = open(datafile, O_RDONLY);
+	if (data_fd <= 0) {
+		perror("Error opening data file");
+		close(flash_fd);
+		return 1;
+	}
+
+	/* Start at the beginning of a bank */
+	buf_offset = flash_offset & FLASH_MASK;
+	flash_offset -= buf_offset;
+	lseek(flash_fd, flash_offset, SEEK_SET);
+
+	/* Make the first bank's data complete */
+	if (buf_offset) {
+		read(flash_fd, buf, buf_offset);
+		lseek(flash_fd, flash_offset, SEEK_SET);
+	}
+	rc = read(data_fd, buf + buf_offset, FLASH_BANK - buf_offset);
+	written = rc;
+
+	/* Write complete banks of data */
+	do {
+		ioctl(flash_fd, CMD_WRITE_ENABLE);
+		rc = write(flash_fd, buf, FLASH_BANK);
+		ioctl(flash_fd, CMD_WRITE_DISABLE);
+		if (rc != FLASH_BANK) {
+			fatal_error();
+			close(flash_fd);
+			close(data_fd);
+			return 1;
+		}
+		flash_offset += FLASH_BANK;
+		rc = read(data_fd, buf, FLASH_BANK);
+		written += rc;
+	} while (rc == FLASH_BANK);
+
+	flash_size = flash_offset + rc;
+
+	/* Write the last incomplete bank (if any) */
+	if (rc > 0) {
+		lseek(flash_fd, flash_offset + rc, SEEK_SET);
+		read(flash_fd, buf + rc, FLASH_BANK - rc);
+		lseek(flash_fd, flash_offset, SEEK_SET);
+		ioctl(flash_fd, CMD_WRITE_ENABLE);
+		rc = write(flash_fd, buf, FLASH_BANK);
+		ioctl(flash_fd, CMD_WRITE_DISABLE);
+		if (rc != FLASH_BANK) {
+			fatal_error();
+			return 1;
+		}
+	}
+	close(flash_fd);
+	close(data_fd);
+
+	fprintf(stderr, "Successfully wrote %d bytes to flash.\n", written);
+	return 0;
+}
+
+int main(int argc, char **argv)
+{
+	int i, rc = 1;
+	char *our_name;
+
+	/* Command line args */
+	int base64_ok = 0;
+	int show_prompt = 1;
+	char *datafile = NULL;
+	int offset = 0;
+	int retry = 1;
+	int data_fd;
+	int data_size;
+
+	/* Get our executable's name (should be "flashwrite") */
+	our_name = (our_name = strrchr(argv[0], '/')) ? our_name + 1 : argv[0];
+
+	/* Parse the command line args */
+	for (i = 1; i < argc; i++) {
+		if (!strcmp(argv[i], "-base64")) {
+			base64_ok = 1;
+			continue;
+		}
+		if (!strcmp(argv[i], "-yes")) {
+			show_prompt = 0;
+			retry = 10;
+			continue;
+		}
+		if (!datafile) {
+			datafile = argv[i];
+			continue;
+		}
+		if (!offset) {
+			offset = strtol(argv[i], NULL, 0);
+			continue;
+		}
+	}
+	if (!datafile) {
+		fprintf(
+			stderr, "\n"
+			"NetWinder Flash Memory update program,"
+			" Rebel.com 1998,1999.\n"
+			"Usage: %s datafile [offset]\n"
+			"offset is in bytes, or 0xNNN for hex\n"
+			"optional flags:\n"
+			"  -base64   enables writing to first 64kB\n"
+			"  -yes      does not prompt for confirmation\n"
+			"\n",
+			our_name
+		);
+		return 1;
+	}
+
+	data_fd = open(datafile, O_RDONLY);
+	if (data_fd <= 0) {
+		perror("Error opening data file");
+		return 1;
+	}
+
+	data_size = lseek(data_fd, 0, 2);
+	close(data_fd);
+
+	if (!data_size) {
+		perror("Zero length data file");
+		return 1;
+	}
+
+	if (show_prompt) {
+		int ch;
+		fprintf(
+			stderr, "\n%s: ready to write into flash memory\n"
+			"  file   : \"%s\"\n"
+			"  size   : %d bytes\n"
+			"  offset : 0x%X.\n\n"
+			"Enter Y to continue, or anything else to abort...\n",
+			our_name, datafile, data_size, offset
+		);
+		ch = getchar();
+		if (!((ch == 'y') || (ch == 'Y'))) {
+			fprintf(stderr, "Not this time... aborted.\n");
+			exit(0);
+		}
+	}
+
+	fprintf(
+		stderr,
+		"\n"
+		"Please wait...\n"
+		"Yellow LED - erasing, Red LED - writing, Green LED - verifying"
+		"...\n"
+	);
+
+	/* Write to the data to the flash */
+	while (retry-- && (rc = flashwrite(datafile, offset, base64_ok))) {
+		/* Repeat */
+	}
+
+	return rc;
+}




Tags added: patch Request was from Petter Reinholdtsen <pere@hungry.com> to control@bugs.debian.org. Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Philip Blundell <pb@debian.org>, nwutil@packages.qa.debian.org:
Bug#86225; Package nwutil. Full text and rfc822 format available.

Acknowledgement sent to Petter Reinholdtsen <petter.reinholdtsen@usit.uio.no>:
Extra info received and forwarded to list. Copy sent to Philip Blundell <pb@debian.org>, nwutil@packages.qa.debian.org. Full text and rfc822 format available.

Message #19 received at 86225@bugs.debian.org (full text, mbox):

From: Petter Reinholdtsen <petter.reinholdtsen@usit.uio.no>
To: 86225@bugs.debian.org
Subject: Re: corel-util: Please update flashwrite, and maybe add nettrom?
Date: Mon, 11 Mar 2002 12:53:23 +0100
Here is the manual page for the flashwrite program.  I got it from
Raph Siemens. I applied this patch relative to upstream.

 - fix typo
 - create nwflash device using mode 0600

--- flashwrite.8.orig   Mon Mar 11 12:45:45 2002
+++ flashwrite.8        Mon Mar 11 12:45:58 2002
@@ -10,7 +10,7 @@
 .SH DESCRIPTION
 This program is used to program the Flash memory (a.k.a. firmware) on a
 NetWinder.  The JTAG boundary-scan feature is (ab)used to open a short
-window of time during which the flash memory is writable (this fauture is
+window of time during which the flash memory is writable (this feature is
 intended to make accidental flash erasure more difficult).  Since the window
 is very narrow, any unexpected interrupts or other "diversions" may cause
 the process to fail, leaving the flash memory corrupted.  The flash driver
@@ -58,7 +58,7 @@
 .I /dev/nwflash
 device node; it can be created with the command
 .TP
-.I mknod -m666 /dev/nwflash c 10 160
+.I mknod -m600 /dev/nwflash c 10 160
 .PP
 The optional string
 .B flashdebug=1

I guess all references to flashwrite should be renamed to nwflashwrite
if the binary ends up as nwflashwrite.

===File flashwrite.8==================================
.TH flashwrite 8 "November 8 1998" "Rebel.com" "NetWinder Utilities" 
.SH NAME
flashwrite \- NetWinder flash programming utility
.SH SYNOPSIS
.B flashwrite
.RB [ -base64 ]
.RB [ -yes ]
.I filename 
.RB [ offset ]
.SH DESCRIPTION
This program is used to program the Flash memory (a.k.a. firmware) on a
NetWinder.  The JTAG boundary-scan feature is (ab)used to open a short
window of time during which the flash memory is writable (this feature is
intended to make accidental flash erasure more difficult).  Since the window
is very narrow, any unexpected interrupts or other "diversions" may cause
the process to fail, leaving the flash memory corrupted.  The flash driver
will retry several times, but may give up if repeated failures occur.
.PP
Since the flash contains the NetWinder's boot code, it is imperative that
the flash writing process be repeated manually until the entire data is
written successfully.  If a failure occurs, DO NOT POWER DOWN OR RESET YOUR
MACHINE as it will very likely NEVER BE ABLE TO BOOT AGAIN.  Do not use
.I flashwrite
during a thunderstorm!  If repeated failures occur, try repositioning the
NetWinder away from the monitor or other sources of EMI.
.SH OPTIONS
.TP 10
.B -base64
Enable access to the first 64kB of flash.  Otherwise any attempts to write
with an offset 0xFFFF or less will fail. In the future the base 64kB block
should contain a fail-safe code and once factory programmed, should never
be rewritten.
.TP 10
.B -yes
Do not prompt for confirmation before writing the flash.  Intended for
use in automated scripts such as the RPM.
.TP 10
.I filename
The name of the file containing the new data you wish to program into the
flash.
.TP 10
.B offset
An offset within the flash memory indicating where the write is to begin.
Defaults value is zero, but do not rely on this behavior as it might change
in future versions.  The value should be expressed as a decimal value or as
a hexadecimal value with the prefix 0x.
.SH FILES
.I /sbin/flashwrite
.I /man/man8/flashwrite.8
.I /boot/nettrom*
.SH DIAGNOSTICS
This program is just a front-end on the kernel flash driver.  The driver
must be loaded by running
.B insmod nwflash
as root, otherwise 
.I flashwrite
will will report "Error -1 opening /dev/nwflash".  There must also exist the 
.I /dev/nwflash
device node; it can be created with the command
.TP
.I mknod -m600 /dev/nwflash c 10 160
.PP
The optional string
.B flashdebug=1
may be passed to 
.I insmod
while loading the flash driver and will enable verbose output of the writing
process.  The flash is written in blocks which are first erased and then
re-programmed with new data.  Thus a failure during the burning process will
generally leave a gap somewhere in the flash.
.SH FILE FORMAT
The following information is subject to change and may be totally wrong even
at the time of writing.  The flash data file given by
.I filename
contains several sections separated by magic numbers and/or marker strings. 
The first 64kB is reserved for low-level bootstrapping and hardware
initialization, detection of RAM, and video initialization.  This section is
known as
.BR NeTTrom .
.PP
The next 400kB (approximately) contain a compressed linux kernel that has
been stripped down to support only key features.  We call this the 
.B minikernel
and it is this code that presents the Sun-like boot configuration manager. 
This code also handles DHCP booting, fetching of the real kernel via TFTP,
and NFS booting.
.PP
Optionally, a compressed root filesystem may follow the minikernel.  The
size is limited by the Flash, currently NetWinders ship with 1 Meg of flash
memory.  Future machines may have 2 or 4 Megs.  The minikernel is able to
uncompress this filesystem into RAM and then to mount it as the root
filesystem, so it is possible to boot "diskless" and also "networkless".
.PP
Finally, the top-most 32 (or 64) kB of Flash are reserved for holding the
configuration information entered in the configuration manager.  If no valid
information is found in this area, the minikernel will supply default values
and will OVERWRITE this part of the flash.  So it is important to ensure
that any rootfs image does not extend into this region.
.SH AUTHOR
The program was originally written by Woody Suwalski <woody@netwinder.org>,
modified to its current state by Andrew E. Mileski <andrewm@netwinder.org>,
then fixed again by Woody,
and the man page was written by Ralph Siemsen <ralphs@netwinder.org>.
Both are distributed under the terms of the GPL.
============================================================



Information forwarded to debian-bugs-dist@lists.debian.org, Philip Blundell <pb@debian.org>, nwutil@packages.qa.debian.org:
Bug#86225; Package nwutil. Full text and rfc822 format available.

Acknowledgement sent to Phil Blundell <pb@nexus.co.uk>:
Extra info received and forwarded to list. Copy sent to Philip Blundell <pb@debian.org>, nwutil@packages.qa.debian.org. Full text and rfc822 format available.

Message #24 received at 86225@bugs.debian.org (full text, mbox):

From: Phil Blundell <pb@nexus.co.uk>
To: Petter Reinholdtsen <petter.reinholdtsen@usit.uio.no>
Cc: 86225@bugs.debian.org
Subject: Re: Bug#86225: corel-util: Please update flashwrite, and maybe add nettrom?
Date: 11 Mar 2002 12:12:19 +0000
On Mon, 2002-03-11 at 11:53, Petter Reinholdtsen wrote:
> I guess all references to flashwrite should be renamed to nwflashwrite
> if the binary ends up as nwflashwrite.

Thanks for the patch.

I'm more inclined to rename the binary back to "flashwrite", since it's
actually the same program and that's what users have come to expect it
to be called.

p.




Reply sent to Martin Michlmayr <tbm@cyrius.com>:
You have taken responsibility. Full text and rfc822 format available.

Notification sent to Adam C Powell IV <hazelsct@mit.edu>:
Bug acknowledged by developer. Full text and rfc822 format available.

Message #29 received at 86225-done@bugs.debian.org (full text, mbox):

From: Martin Michlmayr <tbm@cyrius.com>
To: 86225-done@bugs.debian.org
Subject: in 1.8
Date: Sat, 8 Apr 2006 13:00:04 +0200
flashwrite is in version 1.8.
-- 
Martin Michlmayr
http://www.cyrius.com/



Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Sun, 17 Jun 2007 19:56:39 GMT) Full text and rfc822 format available.

Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Fri Apr 18 11:45:53 2014; Machine Name: buxtehude.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.