summaryrefslogtreecommitdiffstats
path: root/usr/share/olpc-utils/olpc-utils-functions
blob: 23291118ddde91b1e2ffb1e1c1a9ac312da98c8b (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
# Bash functions shared across olpc-utils utilities

get_xo_version()
{
	XO_VERSION=;

        if [ -e "/proc/device-tree/banner-name" ]; then
		# requires new device-tree location
                case "$(</proc/device-tree/banner-name)" in 
                        OLPC\ [BC][0-9])
                                XO_VERSION="1"
                                ;;
                        OLPC\ D[0-9])
                                XO_VERSION="1.5"
                                ;;
                        OLPC\ 1[ABC][0-9])
                                XO_VERSION="1.75"
                                ;;
                esac
        elif [ -e "/sys/class/dmi/id/product_name" ]; then
        	# requires an OFW that runs setup-smbios at boot.
                local name=$(</sys/class/dmi/id/product_name)
                if [ "${name}" == "XO" ]; then
                        local version=$(</sys/class/dmi/id/product_version)
                        if [ "${version}" == "1" ]; then
                                XO_VERSION="1"
                        elif [ "${version}" == "1.5" ]; then
                                XO_VERSION="1.5"
                        fi
                fi
        elif [ -e "/ofw/banner-name" ]; then
        	# uses the old /ofw contents
                case "$(</ofw/banner-name)" in 
                        OLPC\ [BC][1-9]*)
                                XO_VERSION="1"
                                ;;
                esac
        fi

        echo -n $XO_VERSION
}


get_xo_mfg_tag()
{
        tag="$1"
        if [ -d /proc/device-tree/mfg-data ]
        then
                mfgdata=/proc/device-tree/mfg-data
        elif [ -d /ofw/mfg-data ]
        then
                mfgdata=/ofw/mfg-data
        fi

 	# do we need to strip leading nulls here?
	# ie: cat $mfgdata/$tag | tr -d '\000' 2>/dev/null	
        cat $mfgdata/$tag 2>/dev/null
}

# Work around for typo in Ethiopian mfg-data
# http://dev.laptop.org/ticket/6945#comment:16
get_xo_mfg_tag_stripspaces() {
        get_xo_mfg_tag $1 | tr -d [:space:] | tr -d '\000' 2>/dev/null
}

get_ofw_file()
{
	fpath=$1
	if [ -e "/proc/device-tree/$fpath" ]
	then
		cat "/proc/device-tree/$fpath"  2>/dev/null
	else
		cat "/ofw/$fpath"  2>/dev/null
	fi
}