From: Michael Tremer Date: Sun, 4 Sep 2011 12:48:44 +0000 (+0000) Subject: Support ARM in fireinfo. X-Git-Tag: v2.1.0~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f4e98ab1969c119a9dac8a7c07182682bae67b6;p=oddments%2Ffireinfo.git Support ARM in fireinfo. --- diff --git a/fireinfo/cpu.py b/fireinfo/cpu.py index 87193cf..ed63177 100644 --- a/fireinfo/cpu.py +++ b/fireinfo/cpu.py @@ -21,6 +21,8 @@ import os.path +import system + PROC_CPUINFO = "/proc/cpuinfo" SYS_CLASS_CPUID = "/sys/class/cpuid/cpu%d" @@ -38,13 +40,20 @@ class CPU(object): """ Initialize this class by reading all data from /proc/cpuinfo. """ - self.read_cpuinfo() + self.__cpuinfo = self.read_cpuinfo() + + @property + def system(self): + return system.System() - def read_cpuinfo(self): + @staticmethod + def read_cpuinfo(): """ Read information from PROC_CPUINFO and store - it into a dictionary self.__cpuinfo. + it into a dictionary cpuinfo. """ + cpuinfo = {} + f = open(PROC_CPUINFO) while True: line = f.readline() @@ -61,65 +70,105 @@ class CPU(object): key = key.strip().replace(" ", "_") val = val.strip() - self.__cpuinfo[key] = val + cpuinfo[key] = val f.close() + return cpuinfo + @property def bogomips(self): """ Return the bogomips of this CPU. """ - return float(self.__cpuinfo["bogomips"]) + try: + bogomips = self.__cpuinfo["bogomips"] + except KeyError: + bogomips = self.__cpuinfo["BogoMIPS"] + + return float(bogomips) @property def model(self): """ Return the model id of this CPU. """ - return int(self.__cpuinfo["model"]) + try: + model = int(self.__cpuinfo["model"]) + except KeyError: + model = None + + return model @property def model_string(self): """ Return the model string of this CPU. """ - return self.__cpuinfo["model_name"] + return self.__cpuinfo["Processor"] @property def vendor(self): """ Return the vendor string of this CPU. """ - return self.__cpuinfo["vendor_id"] + try: + vendor = self.__cpuinfo["vendor_id"] + except KeyError: + if self.system.arch.startswith("arm"): + vendor = "ARM" + else: + vendor = "" + + return vendor @property def stepping(self): """ Return the stepping id of this CPU. """ - return int(self.__cpuinfo["stepping"]) + try: + stepping = int(self.__cpuinfo["stepping"]) + except KeyError: + stepping = None + + return stepping @property def flags(self): """ Return all flags of this CPU. """ - return self.__cpuinfo["flags"].split() + try: + flags = self.__cpuinfo["flags"] + except KeyError: + flags = self.__cpuinfo["Features"] + + return flags.split() @property def speed(self): """ Return the speed (in MHz) of this CPU. """ - return float(self.__cpuinfo["cpu_MHz"]) + try: + speed = float(self.__cpuinfo["cpu_MHz"]) + except KeyError: + speed = 0 + + return speed @property def family(self): """ Return the family id of this CPU. """ - return int(self.__cpuinfo["cpu_family"]) + try: + family = int(self.__cpuinfo["cpu_family"]) + except KeyError: + family = None + + return family @property def count(self): @@ -129,7 +178,8 @@ class CPU(object): i = 0 while (os.path.exists(SYS_CLASS_CPUID % i)): i += 1 - return i + + return i or 1 if __name__ == "__main__": diff --git a/fireinfo/system.py b/fireinfo/system.py index bce87f1..efd4352 100644 --- a/fireinfo/system.py +++ b/fireinfo/system.py @@ -83,6 +83,9 @@ class System(object): self.cpu = cpu.CPU() self.hypervisor = hypervisor.Hypervisor() + # Read /proc/cpuinfo for vendor information. + self.__cpuinfo = self.cpu.read_cpuinfo() + def profile(self): p = {} p["system"] = { @@ -273,7 +276,7 @@ class System(object): """ Return the system release string. """ - return read_from_file("/etc/system-release") + return read_from_file("/etc/system-release") or "unknown" @property def bios_vendor(self): @@ -282,6 +285,19 @@ class System(object): """ return read_from_file("/sys/class/dmi/id/bios_vendor") + def vendor_model_tuple(self): + try: + s = self.__cpuinfo["Hardware"] + except KeyError: + return (None, None) + + if s.startswith("ARM-Versatile"): + return ("ARM", s) + + v, m = s.split(maxsplit=1) + + return v, m + @property def vendor(self): """ @@ -293,6 +309,10 @@ class System(object): if ret: break + if ret is None: + v, m = self.vendor_model_tuple() + ret = v + return ret @property @@ -306,6 +326,10 @@ class System(object): if ret: break + if ret is None: + v, m = self.vendor_model_tuple() + ret = m + return ret @property diff --git a/sendprofile b/sendprofile index 55b02ba..da480ce 100644 --- a/sendprofile +++ b/sendprofile @@ -48,7 +48,7 @@ PROFILE_URL = "http://fireinfo.ipfire.org/send/%(public_id)s" def get_upstream_proxy(): if not os.path.exists(PROXY_SETTINGS): - return + return {"host" : ""} proxy_settings = {} with open(PROXY_SETTINGS) as f: diff --git a/src/fireinfo.c b/src/fireinfo.c index 5310c06..25b5333 100644 --- a/src/fireinfo.c +++ b/src/fireinfo.c @@ -263,6 +263,7 @@ read_harddisk_serial(char *device, char *serial) { } } +#if defined(__x86_64__) || defined(__i386__) static bool is_virtualized() { unsigned int eax, ebx, ecx, edx; @@ -305,6 +306,22 @@ hypervisor_port(unsigned int cmd, unsigned int *eax, unsigned int *ebx, : "memory" ); } +#else +static bool +is_virtualized() { + /* + Always return false, because other architectures + do not support the virtualization bit. + */ + return false; +} + +void +hypervisor_port(unsigned int cmd, unsigned int *eax, unsigned int *ebx, + unsigned int *ecx, unsigned int *edx) +{ +} +#endif int hypervisor_port_check(void) {