-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathROM_loader_disable.gdbscript
More file actions
82 lines (69 loc) · 2.06 KB
/
Copy pathROM_loader_disable.gdbscript
File metadata and controls
82 lines (69 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# To run the script:
# $ openocd -s "${TOOLCHAIN_PATH}/OpenOCD/scripts" -f interface/cmsis-dap.cfg -f target/max78000.cfg
# $ arm-none-eabi-gdb -batch -q -x ROM_loader_disable.gdbscript
set variable $fctl_base_addr=0x40029000
set variable $fctl_faddr=$fctl_base_addr+0x00
set variable $fctl_fcntl=$fctl_base_addr+0x08
set variable $fctl_acntl=$fctl_base_addr+0x40
set variable $fctl_fdata0=$fctl_base_addr+0x30
set variable $fctl_fdata1=$fctl_base_addr+0x34
set variable $fctl_fdata2=$fctl_base_addr+0x38
set variable $fctl_fdata3=$fctl_base_addr+0x3C
define pico
target remote 127.0.0.1:3333
set verbose off
end
define mrh
monitor reset halt
end
define MAX78000
pico
end
define lock_otp
# Write acntl to lock OTP
set *$fctl_acntl=0xdeadbeef
end
define unlock_otp
# First, put otp controller in known lock state.
lock_otp
# Write acntl to unlock OTP
set *$fctl_acntl=0x3a7f5ca3
set *$fctl_acntl=0xa1e34f20
set *$fctl_acntl=0x9608b2c1
end
# arg0 = address
# arg1 = 32-bit data
# arg2 = 32-bit data
# arg3 = 32-bit data
# arg4 = 32-bit data
define write_flash_128
# Unlock and Set width to 128 (bit 4 to zero)
set *$fctl_fcntl=*$fctl_fcntl | 0x20000000
set *$fctl_fcntl=*$fctl_fcntl & ~0x00000010
# Set address
set *$fctl_faddr=$arg0
# Set 128-bits of data
set *$fctl_fdata0=$arg1
set *$fctl_fdata1=$arg2
set *$fctl_fdata2=$arg3
set *$fctl_fdata3=$arg4
# start flash operation
set *$fctl_fcntl=*$fctl_fcntl | 0x20000001
while (0 != (*$fctl_fcntl & 0x7))
# Wait for flash write to complete
end
end
#####################################################
#################### WARNING ########################
# Executing this function permanently locks the ROM #
# bootloader. This operation cannot be reverted! ####
#####################################################
define MAX78000_write_bootloader_disable
unlock_otp
write_flash_128 0x00080130 0xFC000001 0x4116FFFF 0xFFFFFC00 0x543E0000
write_flash_128 0x00080140 0xFC000001 0x4116FFFF 0xFFFFFC00 0x543E0000
lock_otp
print "Done"
end
MAX78000
MAX78000_write_bootloader_disable