summaryrefslogtreecommitdiffstats
path: root/tests/setenv.kermit
blob: 3fab9ec30f60494975d8a9a33bb41ac4b70dc793 (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

define setenv_uboot_v1 {
	run \%1/make_uboot_env \%2
	ptx_check_fail "Could not generate new environment"

	ptx_test_start "Setting new environment"

	# Open the file with the new environment
	open read \%2
	ptx_check_fail "Could not open \%2."

	clear input
	ptx_lineout "printenv"

	declare \&c[1000]
	# array with entries to skip
	declare \&s = ethaddr stdin stdout stderr baudrate
	.\%i = 0

	while true {
		# wait for newline or u-boot-prompt
		minput 5 {\10} \m(uboot_prompt)
		ptx_check_fail "Did not get old environment"
		# quit on u-boot-prompt
		if = \v(minput) 2 break
		# Remove all CR, they just cause trouble
		assign input \freplace(\v(input),\13,,)
		# if no '=' then continue
		if not match \m(input) *=* goto out
		# extract part before '=' (from \m(input) the first word, allow '_-')
		assign envvar \fword(\m(input),1,,_-)
		# skip special keywords
		if not = \farraylook(^\m(envvar)$,&s) -1 goto out
		# put setenv-command into array
		assign \&c[\%i] setenv \m(envvar)
		incr \%i
	:out
		clear input
	}

	# clear old vars
	for \%j 0 \%i-1 1 {
		ptx_uboot_exec 5 "\&c[\%j]"
	}

	# set new ones from file
	while true {
		read \%l
		if fail break
		ptx_uboot_exec 5 "\%l"
	}

	close read

	ptx_uboot_exec 5 "printenv"
	ptx_uboot_exec 30 "saveenv"

	ptx_test_end
}

define setenv_uboot_v2 {
	if eq \m(uboot_prompt) "barebox:" { 
		run \%1/make_barebox_env \%2
	} else {
		run \%1/make_uboot_v2_env \%2
	}

	ptx_check_fail "Could not generate new environment"
	.imagename := \fbasename(\%2)

	ptx_test_start "Setting initial environment"
	ptx_uboot_exec 3 "eth0.ipaddr=\m(PTXCONF_BOARDSETUP_TARGETIP)"
	ptx_uboot_exec 3 "eth0.serverip=\m(PTXCONF_BOARDSETUP_SERVERIP)"
	ptx_uboot_exec 3 "eth0.gateway=\m(PTXCONF_BOARDSETUP_GATEWAY)"
	ptx_uboot_exec 3 "eth0.netmask=\m(PTXCONF_BOARDSETUP_NETMASK)"
	ptx_test_end

	ptx_test_start "Getting default environment"
	ptx_uboot_exec 15 "ping $eth0.serverip"
	# in current versions of barebox tftp returns the filesize it has
	# fetched. The return value will eventually intepreted as failure by
	# ptx_uboot_exec. We call an empty echo to set $? to 0 if the return
	# value of tftp is not 1 to work around this. (tftp returns 1 if it
	# can't get the file. An successfully fetched image will mostly
	# impossibly have the size 1) 
	ptx_uboot_exec 15 "tftp \m(imagename); [ $? -ne 1 ] && echo"
	ptx_test_end

	ptx_test_start "Flashing default environment"
	ptx_uboot_exec 3  "unprotect /dev/env0"
	ptx_uboot_exec 10 "erase /dev/env0"
	ptx_uboot_exec 20 "cp \m(imagename) /dev/env0"
	ptx_test_end

	ptx_uboot_exec_single "Reloading new environment" 10 "loadenv"

	ptx_test_start "Restoring MAC address"
	ptx_uboot_exec 5 "echo -a /env/config eth0.ethaddr=$eth0.ethaddr"
	ptx_uboot_exec 10 "saveenv"
	ptx_uboot_exec 3  "protect /dev/env0"
	ptx_test_end
}

# Read the library
take \%1/libptxdisttest.kermit

# Set up the line
ptx_init \%2

ptx_uboot_enter_shell

setenv_uboot_v\m(uboot_version) \%1 \%3

ptx_exit