Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
White Rabbit Switch - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
86
Issues
86
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
White Rabbit Switch - Software
Commits
5ca6e20c
Commit
5ca6e20c
authored
Jun 21, 2012
by
Benoit Rat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
usb-loader: adding NAND, DDR, multiple files support & clean the code
parent
ffd8d8de
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
494 additions
and
297 deletions
+494
-297
flash-wrs
build/flash-wrs
+122
-34
mch_flasher.c
usb-loader/mch_flasher.c
+372
-263
No files found.
build/flash-wrs
View file @
5ca6e20c
#!/bin/sh
#!/bin/sh
# A script to compile the usb loader, possibly changing the mac address
# A script to compile the usb loader, possibly changing the mac address
showhelp
()
{
echo
"Usage:
$0
[options] MAC [DEV]
\n
"
echo
"MAC:
\t
MAC address in hexadecimal seperated by ':' (i.e, AB:CD:EF:01:23:45)"
echo
"DEV:
\t
The usb device (by default it is /dev/ttyACM0)"
echo
"Options: "
echo
"
\t
-h|--help
\t\t
Show this help message"
echo
"
\t
-m|--memmode
\t\t
can be: default, df (dataflash), nf (nandflash), test."
echo
"
\t
-e
\t\t\t
Completely erase the memory (Can erase your configuration)"
echo
"
\t
--build
\t\t\t
Use file that you have build in the WRS_OUTPUT_DIR"
echo
"
\t
--test
\t\t\t
Use file for testing the switch (not available)"
echo
"
\t
--silent
\t\t
Don't ask MAC or S/N and use default 02:0B:AD:C0:FF:EE"
echo
""
exit
0
}
checkExit
()
{
err
=
0
;
if
[
$1
]
;
then
if
[
-f
$1
]
;
then
return
0
;
else
echo
"Can't find
$1
"
>
& 2
;
fi
else
echo
"varname not set"
fi
exit
1
}
modifyMAC
()
{
origin
=
$1
new
=
$2
cp
$origin
$new
# check & change mac address
X
=
"[0-9a-fA-F][0-9a-fA-F]"
while
true
;
do
if
echo
$MAC
|
grep
"^
${
X
}
:
${
X
}
:
${
X
}
:
${
X
}
:
${
X
}
:
${
X
}
\$
"
>
/dev/null
;
then
sed
-i
"s/02:0B:AD:C0:FF:EE/
$MAC
/"
$new
echo
"MAC is now:
$MAC
"
return
0
else
if
[
"x
$MAC
"
!=
"x"
]
;
then
echo
"
$0
: Invalid MAC address
\"
$MAC
\"
"
>
&2
;
fi
if
[
$silent
]
;
then
return
1
;
fi
read
-p
"Enter MAC (XX:XX:XX:XX:XX:XX): "
MAC
fi
done
}
# Sanity checks
# Sanity checks
if
[
-d
./usb-loader
]
;
then
true
;
else
if
[
-d
./usb-loader
]
;
then
true
;
else
...
@@ -8,62 +67,91 @@ if [ -d ./usb-loader ]; then true; else
...
@@ -8,62 +67,91 @@ if [ -d ./usb-loader ]; then true; else
exit
1
exit
1
fi
fi
# build flasher itself
if
CC
=
cc make
-s
-C
usb-loader
;
then
true
;
else
echo
"
$0
: Error compiling usb-loader"
>
&2
;
exit
1
;
fi
# Check if atmel sam-ba is find by lusb
# Check if atmel sam-ba is find by lusb
lsusb |
grep
"at91sam SAMBA"
&
> /dev/null
lsusb |
grep
"at91sam SAMBA"
>
/dev/null
if
[
$?
-gt
"0"
]
;
then
if
[
$?
-gt
"0"
]
;
then
echo
"Did not find the sam-ba
bootloader in lsu
b....
\n
Please check that the Dataflash is short-circuited!"
echo
"Did not find the sam-ba
monitor in lsus
b....
\n
Please check that the Dataflash is short-circuited!"
exit
1
;
exit
1
;
fi
fi
err
=
0
;
if
[
-f
./binaries/at91bootstrap.bin
]
;
then
true
;
else
err
=
1
;
fi
if
[
-f
./binaries/barebox.bin
]
;
then
true
;
else
err
=
1
;
fi
if
[
$err
-eq
1
]
;
then
echo
"
$0
: Can't find either ./binaries/at91bootstrap.bin"
>
& 2
echo
"
$0
: or ./binaries/barebox.bin"
>
& 2
exit
1
fi
# parse command line
# parse command line
MAC
=
""
MAC
=
""
DEV
=
""
DEV
=
""
FLAGS
=
""
FLAGS
=
""
at91bs
=
"./binaries/at91bootstrap.bin"
barebox
=
"./binaries/barebox.bin"
kernel
=
"
${
WRS_OUTPUT_DIR
}
/images/zImage"
rootfs
=
"
${
WRS_OUTPUT_DIR
}
/images/wrs-image.jffs2.img"
while
[
$#
-ge
1
]
;
do
while
[
$#
-ge
1
]
;
do
case
$1
in
case
$1
in
--help
|
-h
)
echo
"Usage :
\t
$0
[options] MAC
\n
Options:
\t
same as mch_flasher
\n\n
"
;
-b
|
--build
)
echo
">
\$
usb-loader/mch_flasher -h"
;
usb-loader/mch_flasher
-h
;
at91bs
=
${
WRS_OUTPUT_DIR
}
/images/at91bootstrap.bin
;
exit
0
;;
barebox
=
${
WRS_OUTPUT_DIR
}
/images/barebox.bin
kernel
=
${
WRS_OUTPUT_DIR
}
/images/zImage
rootfs
=
${
WRS_OUTPUT_DIR
}
/images/wrs-image.jffs2.img
shift
;;
-h
|
--help
)
showhelp
;
shift
;;
-m
|
--memmode
)
memmode
=
"
$2
"
;
shift
;
shift
;;
--silent
)
silent
=
1
;
shift
;;
/
*
)
DEV
=
"-s
$1
"
;
shift
;;
/
*
)
DEV
=
"-s
$1
"
;
shift
;;
*
:
*
)
MAC
=
"
$1
"
;
shift
;;
*
:
*
)
MAC
=
"
$1
"
;
shift
;;
-
*
)
FLAGS
=
"
${
FLAGS
}
$1
"
;
shift
;;
-
*
)
FLAGS
=
"
${
FLAGS
}
$1
"
;
shift
;;
*
)
echo
"
$0
: Invalid argument
\"
$1
\"
"
>
&2
;
exit
1
;;
*
)
echo
"
$0
: Invalid argument
\"
$1
\"
"
>
&2
;
exit
1
;;
esac
esac
done
done
## Selecting the running memmode
if
[
"x
$memmode
"
=
"xdf"
]
;
then
df
=
1
elif
[
"x
$memmode
"
=
"xnf"
]
;
then
nf
=
1
elif
[
"x
$memmode
"
=
"xtest"
]
;
then
test
=
1
else
df
=
1
nf
=
1
fi
# build flasher itself
## Flashing DataFlash
if
CC
=
cc make
-s
-C
usb-loader
;
then
true
;
else
if
[
$df
]
;
then
echo
"
$0
: Error compiling usb-loader"
>
&2
;
exit
1
;
checkExit
$at91bs
checkExit
$barebox
Tbarebox
=
$(
mktemp
/tmp/barebox.XXXXXX
)
modifyMAC
${
barebox
}
${
Tbarebox
}
./usb-loader/mch_flasher
-m
df
$FLAGS
$DEV
${
at91bs
}
0
${
Tbarebox
}
33792
fi
fi
# check & change mac address
## Flashing NANDFlash
if
[
"x
$MAC
"
!=
"x"
]
;
then
if
[
$nf
]
;
then
X
=
"[0-9a-fA-F][0-9a-fA-F]"
if
echo
$MAC
|
grep
"^
${
X
}
:
${
X
}
:
${
X
}
:
${
X
}
:
${
X
}
:
${
X
}
\$
"
>
/dev/null
;
then
checkExit
$kernel
sed
-i
"s/02:0B:AD:C0:FF:EE/
$MAC
/"
$T
checkExit
$rootfs
echo
"MAC is now:
$MAC
"
else
./usb-loader/mch_flasher
-m
nand
$FLAGS
$DEV
${
kernel
}
0x00100000
${
rootfs
}
0x04000000
echo
"
$0
: Invalid MAC address
\"
$MAC
\"
"
>
&2
;
exit
1
;
fi
fi
fi
# cat binaries to temp file. Increase size of at91boot (0x8400)
## Loading in DDR
T
=
$(
mktemp
/tmp/wrs-flash.XXXXXX
)
if
[
$test
]
;
then
cp
./binaries/at91bootstrap.bin
$T
dd
if
=
./binaries/barebox.bin
of
=
$T
conv
=
notrunc
bs
=
1
seek
=
33792 2> /dev/null
checkExit
$barebox
checkExit
$kernel
checkExit
$rootfs
Tbarebox
=
$(
mktemp
/tmp/barebox.XXXXXX
)
modifyMAC
${
barebox
}
${
Tbarebox
}
./usb-loader/mch_flasher
-m
ddr
$FLAGS
$DEV
${
Tbarebox
}
0x0
${
kernel
}
0x1000000
${
rootfs
}
0x2000000
fi
# flash it (msc...)
(
cd
usb-loader
&&
./mch_flasher
$FLAGS
$DEV
$T
)
#rm -f $T
usb-loader/mch_flasher.c
View file @
5ca6e20c
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment