summaryrefslogtreecommitdiff
path: root/functions/bootloaders.sh
blob: 1898232e5a280cbf44c55c053702d3128885c41e (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
#!/bin/sh

## live-build(7) - System Build Scripts
## Copyright (C) 2016 Adrian Gibanel Lopez <adrian15sgd@gmail.com>
##
## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
## This is free software, and you are welcome to redistribute it
## under certain conditions; see COPYING for details.

Is_First_Bootloader ()
{
	EVAL_FIRST_BOOTLOADER="${1}"

	if [ "${LB_FIRST_BOOTLOADER}" = "${EVAL_FIRST_BOOTLOADER}" ]
	then
		return 0
	else
		return 1
	fi

}

Is_Bootloader ()
{
	EVAL_BOOTLOADER="${1}"
	OLDIFS="$IFS"
	IFS=","
	for BOOTLOADER in ${LB_BOOTLOADERS}
	do
		if [ "${BOOTLOADER}" = "${EVAL_BOOTLOADER}" ]
		then
			IFS="$OLDIFS"
			return 0
		fi
	done
	IFS="$OLDIFS"
	return 1
}

Is_Extra_Bootloader ()
{
	EVAL_EXTRA_BOOTLOADER="${1}"

	if Is_First_Bootloader "${EVAL_EXTRA_BOOTLOADER}"
	then
		return 1
	else
		if Is_Bootloader "${EVAL_EXTRA_BOOTLOADER}"
		then
			return 0
		fi
	fi
	return 1

}

Check_Non_First_Bootloader ()
{
	NON_FIRST_BOOTLOADER="${1}"

	if Is_First_Bootloader "${NON_FIRST_BOOTLOADER}"
	then
		Echo_error "Bootloader: ${NON_FIRST_BOOTLOADER} not supported as a first bootloader."
		exit 1
	else
		return 0
	fi
}


Check_Non_Extra_Bootloader ()
{
	NON_EXTRA_BOOTLOADER="${1}"

	if Is_Extra_Bootloader "${NON_EXTRA_BOOTLOADER}"
	then
		Echo_error "Bootloader: ${NON_EXTRA_BOOTLOADER} not supported as a extra bootloader."
		exit 1
	else
		return 0
	fi
}

Check_First_Bootloader_Role ()
{
	FIRST_BOOTLOADER_ROLE="${1}"
	Check_Non_Extra_Bootloader "${FIRST_BOOTLOADER_ROLE}"

	if Is_First_Bootloader "${FIRST_BOOTLOADER_ROLE}"
	then
		return 0
	else
		exit 0
	fi

}

Check_Extra_Bootloader_Role ()
{
	EXTRA_BOOTLOADER_ROLE="${1}"
	Check_Non_First_Bootloader "${EXTRA_BOOTLOADER_ROLE}"

	if Is_Extra_Bootloader "${EXTRA_BOOTLOADER_ROLE}"
	then
		return 0
	else
		exit 0
	fi

}

Check_Any_Bootloader_Role ()
{
	ANY_BOOTLOADER_ROLE="${1}"

	if Is_First_Bootloader "${ANY_BOOTLOADER_ROLE}"
	then
		return 0
	fi

	if Is_Extra_Bootloader "${ANY_BOOTLOADER_ROLE}"
	then
		return 0
	fi

	exit 0

}