1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

target: add system_id

Add system_id attribute to targets. This ID is supposed unique for a
combination of hardware, kernel, and the file system, and contains
elements from each.

1. Hardware is identified by the concatenation of MAC addresses of
   'link/ether' network  interfaces on the system. This method is used,
   as DMI tables are often unimplemented on ARM targets.
2. The kernel is identified by its version.
3. The file system is identified by the concatenation of UUID's of the
   target's partitions. It would be more correct to only use UUID of
   the root partition, as system_id is not intended to be affected by
   removable, media, however, there is no straight-forward way of
   reliably identifying that without root.

system_id is intended to be used as an key for the purposes of caching
information about a particular device (e.g. so that it does not need to
be probed on each run).
This commit is contained in:
Sergei Trofimov 2018-07-13 12:18:17 +01:00 committed by Marc Bonnici
parent 8ac89fe9ed
commit 472c5a3294
3 changed files with 39 additions and 1 deletions

View File

@ -264,6 +264,20 @@ read_tree_values() {
fi
}
get_linux_system_id() {
kernel=$($BUSYBOX uname -r)
hardware=$($BUSYBOX ip a | $BUSYBOX grep 'link/ether' | $BUSYBOX sed 's/://g' | $BUSYBOX awk '{print $2}' | $BUSYBOX tr -d '\n')
filesystem=$(ls /dev/disk/by-uuid | $BUSYBOX tr '\n' '-' | $BUSYBOX sed 's/-$//')
echo "$hardware/$kernel/$filesystem"
}
get_android_system_id() {
kernel=$($BUSYBOX uname -r)
hardware=$($BUSYBOX ip a | $BUSYBOX grep 'link/ether' | $BUSYBOX sed 's/://g' | $BUSYBOX awk '{print $2}' | $BUSYBOX tr -d '\n')
filesystem=$(content query --uri content://settings/secure --projection value --where "name='android_id'" | $BUSYBOX cut -f2 -d=)
echo "$hardware/$kernel/$filesystem"
}
################################################################################
# Main Function Dispatcher
################################################################################
@ -323,6 +337,12 @@ hotplug_online_all)
read_tree_values)
read_tree_values $*
;;
get_linux_system_id)
get_linux_system_id $*
;;
get_android_system_id)
get_android_system_id $*
;;
*)
echo "Command [$CMD] not supported"
exit -1

View File

@ -59,6 +59,7 @@ class Target(object):
path = None
os = None
system_id = None
default_modules = [
'hotplug',
@ -799,6 +800,7 @@ class Target(object):
GOOGLE_DNS_SERVER_ADDRESS, attempts))
return False
class LinuxTarget(Target):
path = posixpath
@ -842,6 +844,11 @@ class LinuxTarget(Target):
return device_model_to_return.rstrip(' \t\r\n\0')
return None
@property
@memoized
def system_id(self):
return self._execute_util('get_linux_system_id').strip()
def __init__(self,
connection_settings=None,
platform=None,
@ -1020,6 +1027,11 @@ class AndroidTarget(Target):
except KeyError:
return None
@property
@memoized
def system_id(self):
return self._execute_util('get_android_system_id').strip()
@property
@memoized
def external_storage(self):

View File

@ -120,6 +120,12 @@ Target
This is a dict that contains a mapping of OS version elements to their
values. This mapping is OS-specific.
.. attribute:: Target.system_id
A unique identifier for the system running on the target. This identifier is
intended to be uninque for the combination of hardware, kernel, and file
system.
.. attribute:: Target.cpuinfo
This is a :class:`Cpuinfo` instance which contains parsed contents of