Skip to content

Commit

Permalink
Use custom script to set bootloader fuses
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Jan 16, 2017
1 parent b27d2a9 commit 0192f44
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ b: burn
l: logs

burn: all
node scripts/dbgtool.js fuses
node scripts/dbgtool.js $(BUILD_PATH)/$(NAME).bin

run: burn wait logs
Expand Down
12 changes: 10 additions & 2 deletions scripts/dbgtool.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function main() {
if (/\.map$/.test(fileName)) mode = "map"
else if (/\.bin$/.test(fileName)) mode = "bin"
else if (/^server?$/.test(fileName)) mode = "server"
else if (/^fuses?$/.test(fileName)) mode = "fuses"
else {
console.log("usage: node " + process.argv[1] + " file.bin # to burn")
console.log("usage: node " + process.argv[1] + " file.map # to dump logs")
Expand Down Expand Up @@ -76,7 +77,7 @@ function main() {
if (mode == "map")
cmd += `set M(0) 0; mem2array M 8 ${addr} ${logSize}; resume; parray M; shutdown`
else
cmd += `at91samd bootloader 0; program ${fileName} verify reset; shutdown`
cmd += `program ${fileName} verify reset; shutdown`

let args = ["-d2",
"-s", openocdPath + "/share/openocd/scripts/",
Expand All @@ -88,7 +89,14 @@ function main() {
args.pop()
}

console.log("Starting " + openocdBin)
if (mode == "fuses") {
args.pop()
args.pop()
args.push("-f")
args.push("scripts/fuses.tcl")
}

console.log("Starting " + openocdBin + " " + args.join(" "))
if (mode == "map")
child_process.execFile(openocdBin, args, {
maxBuffer: 1 * 1024 * 1024,
Expand Down
61 changes: 61 additions & 0 deletions scripts/fuses.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# change forceupdate to 1 to update the fuses to values specified below
set forceupdate 0
set v0 0xD8E0C7FF
set v1 0xFFFFFC5D

init

set CPU_MAX_ADDRESS 0xFFFFFFFF
source [find bitsbytes.tcl]
source [find memory.tcl]

set fuse0 0x00804000
set fuse1 0x00804004
set nvmctrl 0x41004000

set cmd_ear 0x5
set cmd_pbc 0x44
set cmd_wap 0x6

proc cmd {C} {
global nvmctrl
global fuse0
memwrite32 [expr $nvmctrl + 0x1C] [expr $fuse0 / 2]
memwrite16 $nvmctrl [expr 0xA500 | $C]
}

set f0 [memread32 $fuse0]
set f1 [memread32 $fuse1]

puts "Fuses:"
puts [format %x $f0]
puts [format %x $f1]

set updatefuses 0

if { $forceupdate } then {
set updatefuses 1
} else {
if { ($f0 & 0x7) != 0x7 } then {
set updatefuses 1
set v0 [expr $f0 | 0x7]
set v1 $f1
}
}

if { $updatefuses } then {
puts "*** Updating fuses! ***"
puts [format %x $v0]
puts [format %x $v1]
cmd $cmd_pbc
cmd $cmd_ear

memwrite32 $fuse0 $v0
memwrite32 $fuse1 $v1

cmd $cmd_wap

reset
}

shutdown

0 comments on commit 0192f44

Please sign in to comment.