aboutsummaryrefslogtreecommitdiff
path: root/testing/DMBootloader/test.sh
blob: fccfdbe20c23c810108e3817217bc1bfe7457a8a (plain)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash

. ./atprogram.sh

. ../utils.sh
. ../yup_comm.sh


TMPDIR=/tmp/testing
COM_PORT=COM5
DMBOOTLOADER_HEX="../../impl/DMBootloader/DMBootloader/Release/DMBootloader.hex"

test_command_properties()
{
    info "Testing basic command properties"
    
    list_commands_and_replies 1_basic | test $TMPDIR

    check_retval $?
    info "OK"
}

test_write_all_pages()
{
    info "Testing writing of all pages in virtual page space"
    
    list_commands_and_replies 2_cmd_write_all_pages | test $TMPDIR

    check_retval $?
    info "OK"
}

test_read_all_pages()
{
    info "Testing reading of all pages in virtual page space"

    basedir=3_cmd_read_all_pages
    
    list_commands_and_replies $basedir | test $TMPDIR
    check_retval $?

    # Check memory content by HW programmer
    atprogram_read_flash $TMPDIR/memory_image 32 992
    compare_files $TMPDIR/memory_image $basedir/memory_image
    [ $? -ne 0 ] && error "JTAGICE3 HW programmer has read a different FLASH content"

    info "OK"
}

test_erase_random_pages()
{
    info "Testing erasing of random pages in virtual page space"

    basedir=4_erase_random_pages

    for i in $(seq 1 16); do
	cmd_dir=$basedir/${i}_erase
	
	list_commands_and_replies $cmd_dir | test $TMPDIR
	check_retval $?

	# Check memory content by HW programmer
	atprogram_read_flash $TMPDIR/memory_image 32 992
	compare_files $TMPDIR/memory_image $cmd_dir/memory_image
	[ $? -ne 0 ] && error "JTAGICE3 HW programmer has read a different FLASH content"
    done
    
    info "OK"
}

test_erase_even_pages()
{
    info "Testing erasing of even pages in virtual page space"

    basedir=5_erase_even_pages
    
    list_commands_and_replies $basedir | test $TMPDIR
    check_retval $?

    # Check memory content by HW programmer
    atprogram_read_flash $TMPDIR/memory_image 32 992
    compare_files $TMPDIR/memory_image $basedir/memory_image
    [ $? -ne 0 ] && error "JTAGICE3 HW programmer has read a different FLASH content"

    info "OK"
}

test_erase_odd_pages()
{
    info "Testing erasing of odd pages in virtual page space"

    basedir=6_erase_odd_pages
    
    list_commands_and_replies $basedir | test $TMPDIR
    check_retval $?
    
    # Check memory content by HW programmer
    atprogram_read_flash $TMPDIR/memory_image 32 992
    compare_files $TMPDIR/memory_image $basedir/memory_image
    [ $? -ne 0 ] && error "JTAGICE3 HW programmer has read a different FLASH content"

    info "OK"
}

test_write_DMAppFpgaProg()
{
    info "Testing writing of DMAppFpgaProg"
    
    list_commands_and_replies 7_write_DMAppFpgaProg | test $TMPDIR

    check_retval $?
    info "OK"
}


test_execute_DMAppFpgaProg()
{
    info "Testing execution of DMAppFpgaProg"

    list_commands_and_replies 8_exec_DMAppFpgaProg | test $TMPDIR
    check_retval $?
    
    # It's needed to wait for DMAppFpgaProg initialization to complete
    sleep 4

    list_commands_and_replies 9_check_DMAppFpgaProg | test $TMPDIR

    check_retval $?
    info "OK"
}


#-----------------------------------------------------------------------------
# MAIN
#-----------------------------------------------------------------------------

info "Programming DMBootloader into the MCU"
atprogram_write_bootloader $DMBOOTLOADER_HEX
check_retval $? "Cannot program DMBootloader into the FLASH memory of the MCU"
info "OK"

info "Locking FLASH pages of DMBootloader's memory area through BOOTPROT fuses"
atprogram_protect_bootloader
check_retval $? "Cannot lock FLASH pages of the DMBootloader's memory area"
info "OK"

# Wait for DMBootloader to complete initialization of DM
sleep 4

yup_comm_start_server $COM_PORT
check_retval $? "Cannot start YUP communication utility server"

init_tmp_dir $TMPDIR

test_command_properties
test_write_all_pages
test_read_all_pages
test_erase_random_pages
# Restore the virtual address space data
test_write_all_pages
test_erase_even_pages
# Restore the virtual address space data
test_write_all_pages
test_erase_odd_pages
test_write_DMAppFpgaProg
test_execute_DMAppFpgaProg

yup_comm_stop_server

info "Setting security bit to improve DMBootloader's protection"
atprogram_set_security_bit
check_retval $? "Cannot set the security bit"
info "OK"

exit 0