# cat flash_00000000.bin | ./reflash -o 0x140000 -i 0x400000 -a -s 0x400000
reflash: progname>reflash<
reflash: got main_buf, 0x40138008, len, 0x1000000
reflash: process opt>o<
reflash: process opt>i<
reflash: premature EOF, read 0 of 4194304 bytes.
# cat flash_00000000.bin | ./reflash -o 0x140000 -i - -a -s 0x400000
reflash: progname>reflash<
reflash: got main_buf, 0x40138008, len, 0x1000000
reflash: process opt>o<
reflash: process opt>i<
reflash: process begin_restore():
opt>a<
reflash: Erase command, len: 0x400000, offset: 0x140000
auto erase is on
reflash: process opt>s<
reflash: segwrite, tsize: 0x400000, mb: 0x40138008, p: 0x40278008
reflash: command: 3, vaddr: 0x0, len: 0x400000, off: 0x140000
reflash: command: 1, vaddr: 0x40278008, len: 0x400000, off: 0x140000
reflash: command: 4, vaddr: 0x0, len: 0x0, off: 0x40000
Segment command, vaddr: 0x40278008, len: 0x400000, offset: 0x140000
MTD_write
# reboot


My test partition starts at:

0x140000 thru 0x540000 - 1 (4M ar old jffs location)

./reflash -o 0x140000 -a -t 0x100000 -v 0x100000

// copy a file into place
cat reflash.h | ./reflash -o 0x140000 -i - -e 0x40000 -w 1024

./reflash -o 0x140000 -e 0x40000
cat reflash.h | ./reflash -o 0x140000 -i - -w 1024


cat flash_00000000.bin | ./reflash -o 0x140000 -i 0x400000 -a -w 0x400000


# see how much data is read
cat flash_00000000.bin | ./reflash -o 0x140000 -i - -x
cat flash_00000000.bin | ./reflash -o 0x140000 -i 0x400000 -x


cat flash_00000000.bin | ./reflash -O -o 0 -i 0x400000 -a -w 0x400000

# obliterate all but bootldr
./reflash -o 0x80000 -t 0xf80000 -w 0xf80000
-or-
./reflash -o 0x80000 -b 99 -t 0xf80000 -w 0xf80000

# verify obliteration ???
./reflash -o 0x80000 -t 0xf80000 -v 0xf80000

o  Add code to unprotect boot sector.
v- Add byte compare after flashing. needs test. done. works.


----------------------
do 
fuser -v /usr
and
fuser -v /

to see if anything is opened on the file systems.


keventd - 
So, with schedule_task, comes a new kernel thread called "keventd."
Its only job is to run the scheduled tasks, so that
they all run in a well-known context

kswapd -
 process swapper outer.
 (iPAQ/familiar has no swap defined.)

kreclaimd -
 * Kreclaimd will move pages from the inactive_clean list to the
 * free list, in order to keep atomic allocations possible under
 * all circumstances.
 /skiff/davep/linux-2.4.3-rmk2-np1/kernel/mm/vmscan.c

bdflush - 
 flushes blocks to disk

kupdated -
 schedules blocks to be written

mtdblockd -

=====================================================================

My test partition starts at:

0x140000 thru 0x540000 - 1 (4M at old jffs location)
using my kernel and jffs in /skiff/davep/ipaq/install:
zImage-middle-test-partition
base.jffs2

stty erase ^H
mount -o nolock,soft highwind:/skiff /skiff
PATH="/mnt/ramfs/reflash-work:$PATH"
PATH="/skiff/davep/tools/reflash:$PATH"


stty erase ^H
mount -o nolock,soft 192.168.123.77:/skiff /skiff
PATH="/mnt/ramfs/reflash-work:$PATH"
PATH="/skiff/davep/tools/reflash:$PATH"

// copy a file into place
cat reflash.h | ./reflash -o 0x140000 -i - -e 0x40000 -w 1024

./reflash -o 0x140000 -e 0x40000
cat reflash.h | ./reflash -o 0x140000 -i - -w 1024


cat flash_00000000.bin | ./reflash -o 0x140000 -i 0x400000 -E1 -w 0x400000


# see how much data is read
cat flash_00000000.bin | ./reflash -o 0x140000 -i - -x
cat flash_00000000.bin | ./reflash -o 0x140000 -i 0x400000 -x



cat flash_00000000.bin | ./reflash -O -o 0 -i 0x400000 -E1 -w 0x400000

cat flash_00000000.bin | ./reflash  -o 0x140000 -i - -E1 -V1 -w 0x400000
cat flash*.bin | ./reflash -O -o 0x0 -i 0x1000000 -E1 -V1 -w 0x1000000


cat flash*.bin | /skiff/davep/tools/reflash/reflash -O -o 0x0 -i 0x1000000 -E1 -V1 -w 0x1000000

o  Add code to unprotect boot sector.
v- Add byte compare after flashing.
o  Add code to reboot upon successful verify


try to find entry for mount and see how it gets trashed.


--------------
boot> find 0x540000 0x1000000 mount
start: 0x00540000
end  : 0x00FFFFFB
search pattern:
C19F3CD4: 6D 6F 75 6E 74
Match at 0x00565B68 mountall.sh
Match at 0x00566D31 umountfs
Match at 0x00567A7F mountall.sh
Match at 0x00567ADA /init.d/mountall.sh 
Match at 0x0056D2D2 /proc/mounts
Match at 0x0056D404 umountfs
Match at 0x0056D45B /init.d/umountfs
Match at 0x00843E91 umount
Match at 0x008C0AE8 mount <----------looks like mount's dir entry

boot> hd 0x008C0Ac0 64
008C0AC0: 85 19 01 E0 2D 00 00 00-3A 31 4D 58 AB 01 00 00 | ....-...:1MX....
008C0AD0: 20 00 00 00 CA 01 00 00-B7 1A C8 3A 05 08 00 00 |  ..........:....
008C0AE0: 81 1E C5 C8 1E 0D CB FC-6D 6F 75 6E 74 FF FF FF | ........mount...
008C0AF0: 85 19 02 E0 A2 07 00 00-7C F3 AC 6E CA 01 00 00 | ........|..n....


load mod
unload mod
reboot --> problem

mtdblock_open
ok
jffs2_scan_dirent_node(): Name CRC failed on node at 0x003cac74: Read 0xfccb0d1e, calculated 0x6fda649e
VFS: Mounted root (jffs2 filesystem).
Mounted devfs on /dev

Why is jffs2 looking at 0x003cac74?  offset is into the mtdblock dev,
so 0x003cac74 + 0x540000 == 0x90ac74

find_encompassing_partition(), min: 0x0, max: 0xffffff
mtd: size: 0x40000		    0x00000000
mtd: size: 0x40000		    0x00040000
mtd: size: 0xc0000		    0x00080000
mtd: size: 0x400000		    0x00140000
mtd: size: 0xac0000		    0x00540000
mtd: size: 0x1000000



Why these addrs ???
Everything should start at 0x540000

JFFS2: Erase block at 0x00400000 is not formatted. It will be erased
JFFS2: Erase block at 0x00440000 is not formatted. It will be erased
JFFS2: Erase block at 0x00480000 is not formatted. It will be erased
JFFS2: Erase block at 0x004c0000 is not formatted. It will be erased
JFFS2: Erase block at 0x00500000 is not formatted. It will be erased
JFFS2: Erase block at 0x00540000 is not formatted. It will be erased
JFFS2: Erase block at 0x00580000 is not formatted. It will be erased
JFFS2: Erase block at 0x005c0000 is not formatted. It will be erased
JFFS2: Erase block at 0x00600000 is not formatted. It will be erased
JFFS2: Erase block at 0x00640000 is not formatted. It will be erased
JFFS2: Erase block at 0x00680000 is not formatted. It will be erased
JFFS2: Erase block at 0x006c0000 is not formatted. It will be erased
JFFS2: Erase block at 0x00700000 is not formatted. It will be erased
JFFS2: Erase block at 0x00740000 is not formatted. It will be erased
JFFS2: Erase block at 0x00780000 is not formatted. It will be erased
JFFS2: Erase block at 0x007c0000 is not formatted. It will be erased
JFFS2: Erase block at 0x00800000 is not formatted. It will be erased
JFFS2: Erase block at 0x00840000 is not formatted. It will be erased
JFFS2: Erase block at 0x00880000 is not formatted. It will be erased
JFFS2: Erase block at 0x008c0000 is not formatted. It will be erased
JFFS2: Erase block at 0x00900000 is not formatted. It will be erased
JFFS2: Erase block at 0x00940000 is not formatted. It will be erased
JFFS2: Erase block at 0x00980000 is not formatted. It will be erased
JFFS2: Erase block at 0x009c0000 is not formatted. It will be erased
JFFS2: Erase block at 0x00a00000 is not formatted. It will be erased
JFFS2: Erase block at 0x00a40000 is not formatted. It will be erased
JFFS2: Erase block at 0x00a80000 is not formatted. It will be erased


jffs2_scan_dirent_node(): Name CRC failed on node at 0x003cabac
jffs2_scan_dirent_node(): Name CRC failed on node at 0x003cac9c
jffs2_scan_dirent_node(): Name CRC failed on node at 0x003cac74

!!!!!!!!!!!!  It is a JFFS bug !!!!!!!!!!!!!!!!!!!!
(never mind)



Changes to add:

Add -L option which sets current_len.  Allow len parameters to be L or l
which means to use the current_len param.
Have '-i -' set current_len

Break arg processing into a separate function (with static
parameters), and add a commandline loop.  Commands are the same,
except no - in front of command letters.
Also there will be a "restore" command that issues the restore param
to the module.

./reflash -E0 -o 0x80000 -e 0xf80000 -i zImage-middle-test-partition -wl -o 0x540000 -i base.jffs2 -wl -x

./reflash -E0 -o 0x540000 -e 0xac0000 -o 0x540000 -i base.jffs2 -wl -x


cat flash*.bin | ./reflash -O -o 0x0 -i 0x1000000 -o 0x40000 -w
0xfc0000 -o 0 -l 0x40000 -u l -w l -p l


Add KMS suffixes to lens for kilo, mega and sector multipliers of the
preceding number.
Take prints out of proc file's read.  Print in do restore.
Make sure erase rounds up for len and down for offset.


Make bootldr accept set x y and x=y


make a tarball w/ module, reflash, prep and rzcat in it.
prep can drop link to rzrzcat --> rz


have prep copy a good bootldr into the ramdisk for emergency recovery?


rzCOMMAND

runs COMMAND <file-name> w/file data piped to stdin.

COMMAND cannot have its stdio redirected, but inside COMMAND that is
ok.

reflash-rz.sh:
#!/bin/sh

./reflash -O 0 -o 0 -i - -o 0x40000 -w 0xfc0000 -o 0 -l 0x40000 -u l -w l



rzXXX

          +<-- tty
    rz ===+--> tty
          +--> ???
          +------------>+
                 XXX ===+-->
                        +-->



/bin:
ash    cp    echo   gunzip    login  mv       pwd        sed    tar     vdir
cat    date  egrep  gzip      ls     netstat  rm         sh     touch   vi
chgrp  dd    false  hostname  mkdir  pidof    rmdir      sleep  true
chmod  df    fgrep  iv        mknod  ping     run-parts  stty   umount
chown  dir   grep   ln        mount  ps       rz         sync   uname


need to ln -s /bin/rz rzxxx-rz.sh and use rzxxx-rz.sh to start the
reflash process.

xxx-rz.sh:
#!/bin/sh

incoming_file_name=$1

# standard input has file data

prog=`basename $0 -rz.sh`
reflash_script=$prog.inp

./reflash -i - -c $reflash_script


# try to work w/rz
./reflash -Q1 -o 0x140000 -s ./rzcat-pipe -i re-pipe -h 80 -x

./reflash -Q1 -o 0x140000 -s ./rzcat-pipe -i re-pipe -Q0 -j -h 80 -x 2> ref.2 

./reflash -Q1 -o 0x140000 -s ./rzcat-pipe -i re-pipe -Q0 -j -h 80 -wl
2> ref.2 

./reflash -o 0x140000 -i @rz -h 80 -x 2> ref.2 
./reflash -o 0x140000 -i @rz -h 80 -wl 2> ref.2 


./reflash -o 0x140000 -i @rz -h 80 -o 0x300000 -i @rz -h 80 -x 2> ref.2 



dd if=/dev/mtdblock/3 of=blah count=100


cases


rewincing:
   need to send all of the flash_00[048c]00000.bin files.
	
1) rewince + network
   cat specified or default filenames to reflash

2) rewince + zmodem
   prompt for each file, one after the other (or one)


3) upgrade + network
4) upgrade + zmodem


[
Add "rest of flash" size code.  Interpreted by module which knows the
sizes.
]

[
Make flash_00x0000.bin file names REQUIRED (unless overridden -yogi)

Need to send the expected name to rzcat-pipe.  Use another pipe?
When invoked, cat-pipe will read its filename and compare it to $1 and
error out if incorrect.

@rz/expected-filename
snag from /+1 to (\n or \0) - 1

./reflash -o 0x140000 -i @rz/0rzfile -wl -q -x
./reflash -o 0x140000 -i @rz/0rzfile -wl -q -x >stdout 2>stderr &


./reflash -T 120 -o 0x140000 -i @rz- -wl -q -x

./reflash -T 120 -o 0x140000 -i @rz/bubba -wl -q -x
./reflash -T 120 -o 0x140000 -i @rz/0rzfile -wl -q -x

./reflash -T 120 -o 0x140000 -i @rz -wl -q -x
]

[
make locations of created files a variable.
will need to have all scripts handle the option and pass it to stuff
in utils.sh
]

test without running from reflash dir. (e.g. test paths, etc.)


--------
Two different but compatible kernels for testing kernel upgrades.

zImage-middle-test-partition-2
#11 Thu May 10 10:54:47 EDT 2001
also says "sa1100_mtd_init(): using davep's MTD partitions..."

zImage-middle-test-partition:
#8 Fri Apr 27 15:31:56 EDT 2001

--------
