I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 7469e9c6 authored by zzz's avatar zzz
Browse files

* NativeBigInteger: Workaround for Raspberry Pi to load the correct lib

parent 57abfe76
No related branches found
No related tags found
No related merge requests found
...@@ -8,18 +8,22 @@ package net.i2p.util; ...@@ -8,18 +8,22 @@ package net.i2p.util;
* *
*/ */
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.URL; import java.net.URL;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.Random; import java.util.Random;
import freenet.support.CPUInformation.AMDCPUInfo; import freenet.support.CPUInformation.AMDCPUInfo;
...@@ -627,30 +631,26 @@ public class NativeBigInteger extends BigInteger { ...@@ -627,30 +631,26 @@ public class NativeBigInteger extends BigInteger {
} }
if (_isArm) { if (_isArm) {
InputStream in = null; Map<String, String> cpuinfo = getCPUInfo();
try { int ver = 0;
in = new FileInputStream("/proc/cpuinfo"); String proc = cpuinfo.get("processor");
while (true) { String arch = cpuinfo.get("cpu architecture");
String line = DataHelper.readLine(in); if (proc != null && proc.contains("ARMv6")) {
if (line == null) // Raspberry Pi workaround
break; // Processor : ARMv6-compatible processor rev 7 (v6l)
if (!line.startsWith("CPU architecture")) // CPU architecture: 7
continue; ver = 6;
//CPU architecture: 5TEJ } else if (arch != null && arch.length() > 0) {
//CPU architecture: 7 //CPU architecture: 5TEJ
int colon = line.indexOf(": "); //CPU architecture: 7
String sver = line.substring(colon + 2, colon + 3); String sver = arch.substring(0, 1);
int ver = Integer.parseInt(sver); try {
// add libjbigi-linux-armv7.so, libjbigi-linux-armv6.so, ... ver = Integer.parseInt(sver);
for (int i = ver; i >= 3; i--) { } catch (NumberFormatException nfe) {}
rv.add(_libPrefix + getMiddleName1() + primary + 'v' + i + _libSuffix); }
} // add libjbigi-linux-armv7.so, libjbigi-linux-armv6.so, ...
break; for (int i = ver; i >= 3; i--) {
} rv.add(_libPrefix + getMiddleName1() + primary + 'v' + i + _libSuffix);
} catch (NumberFormatException nfe) {
} catch (IOException ioe) {
} finally {
if (in != null) try { in.close(); } catch (IOException ioe) {}
} }
} }
...@@ -689,6 +689,37 @@ public class NativeBigInteger extends BigInteger { ...@@ -689,6 +689,37 @@ public class NativeBigInteger extends BigInteger {
return rv; return rv;
} }
/**
* Return /proc/cpuinfo as a key-value mapping.
* All keys mapped to lower case.
* All keys and values trimmed.
* For dup keys, first one wins.
* Currently used for ARM only.
* @return non-null, empty on failure
* @since 0.9.1
*/
private static Map<String, String> getCPUInfo() {
Map<String, String> rv = new HashMap(32);
BufferedReader in = null;
try {
in = new BufferedReader(new InputStreamReader(new FileInputStream("/proc/cpuinfo"), "ISO-8859-1"), 4096);
String line = null;
while ( (line = in.readLine()) != null) {
String[] parts = line.split(":", 2);
if (parts.length < 2)
continue;
String key = parts[0].trim().toLowerCase(Locale.US);
if (!rv.containsKey(key))
rv.put(key, parts[1].trim());
}
} catch (IOException ioe) {
warn("Unable to read /proc/cpuinfo", ioe);
} finally {
if (in != null) try { in.close(); } catch (IOException ioe) {}
}
return rv;
}
/** /**
* @return may be null if optimized is true * @return may be null if optimized is true
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment