-
Notifications
You must be signed in to change notification settings - Fork 2
/
prog_otp_rpi4.S
102 lines (81 loc) · 1.59 KB
/
prog_otp_rpi4.S
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
;;;
;;; Program OTP memory
;;;
;;; This program works ONLY with RPi4.
;;;
.include "mmio.inc"
.include "uart.inc"
;;; Change to the desired OTP register number:
OTP_REG = 36
;;; Change to the new value that should be programmed:
OTP_NEW_VAL = 0x20
.text
.org 0x200
.global _start
_start:
mov r0, CM_VPUCTL
bl clk_get_freq
mov r6, r0
bl uart_init
lea r0, txt_hline
bl uart_puts
bl otp_open
mov r0, OTP_REG
bl otp_read_reg
cmp r0, -1
mov r6, r0
beq err_all_set
lea r0, txt_old_value
bl uart_puts
mov r0, r6
bl uart_puthexword
bl uart_putcrlf
bl otp_enable_program
bne r0, 0, err_enable
mov r0, OTP_REG
mov r1, OTP_NEW_VAL
bl otp_write_reg
bne r0, 0, err_program
bl otp_disable_program
bne r0, 0, err_disable
bl otp_close
print_new_value:
lea r0, txt_new_value
bl uart_puts
bl otp_open
mov r0, OTP_REG
bl otp_read_reg
bl uart_puthexword
bl uart_putcrlf
bl otp_close
b led_flash
err_all_set:
lea r0, txt_err_all_set
b error
err_enable:
lea r0, txt_err_enable
b error
err_program:
lea r0, txt_err_program
b error
err_disable:
;; the bit is probably programmed anyway
lea r0, txt_err_disable
error:
bl uart_puts
b print_new_value
txt_hline:
.asciz "--------------------\r\n"
txt_old_value:
.asciz "Old OTP register value: "
txt_new_value:
.asciz "New OTP register value: "
txt_err_all_set:
.asciz "All bits are already programmed!\r\n"
txt_err_enable:
.asciz "Cannot enable OTP programming. :-(\r\n"
txt_err_program:
.asciz "Programming command failed.\r\n"
txt_err_disable:
.asciz "Cannot disable OTP programming.\r\n"
.balign 2