Skip to content

Commit

Permalink
Preliminary ARM support
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadoum committed Nov 10, 2022
1 parent 3b51880 commit 3e34315
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 46 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/cmake-cross-compile.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: aarch64 builds
name: ARM builds

on:
push:
Expand Down Expand Up @@ -46,13 +46,13 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y build-essential gcc g++ gdc ninja-build gdc-12-arm-linux-gnueabihf dub

- name: Configure CMake
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -Dbuild_sideloadipa=OFF -Dlink_libplist_dynamic=ON -DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/toolchains/rpi-2.cmake -Dbuild_anisetteserver=OFF
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -Dbuild_sideloadipa=OFF -Dlink_libplist_dynamic=ON -DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/toolchains/rpi-2.cmake

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- uses: actions/upload-artifact@v3
with:
name: retrieve-headers-armv7
name: anisette-server-armv7
path: |
${{github.workspace}}/build/retrieve_headers
${{github.workspace}}/build/anisette_server
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ if(build_anisetteserver)
add_executable(anisette_server ${ANISETTE_SERVER_D_SOURCES})
target_include_directories(anisette_server PUBLIC ${ANISETTE_SERVER_SOURCE_DIR})

target_link_libraries(anisette_server provision archttp)
target_link_libraries(anisette_server provision handy-httpd)
endif()
98 changes: 58 additions & 40 deletions anisette_server/app.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import archttp;
import handy_httpd;
import std.algorithm.searching;
import std.array;
import std.base64;
Expand All @@ -7,10 +7,10 @@ import std.path;
import std.stdio;
import provision;

void main(string[] args) {
auto app = new Archttp;
ADI* adi;
__gshared static ADI* adi;
__gshared static ulong rinfo;

void main(string[] args) {
if (args.canFind("--remember-machine")) {
adi = new ADI(expandTilde("~/.adi"));
} else {
Expand All @@ -22,7 +22,6 @@ void main(string[] args) {
adi = new ADI(expandTilde("~/.adi"), cast(char[]) id.toHexString().toLower());
}

ulong rinfo;
if (!adi.isMachineProvisioned()) {
stderr.write("Machine requires provisioning... ");
adi.provisionDevice(rinfo);
Expand All @@ -31,36 +30,37 @@ void main(string[] args) {
adi.getRoutingInformation(rinfo);
}

app.get("/reprovision", (req, res) {
writefln!"[%s >>] GET /reprovision"(req.ip);
adi.provisionDevice(rinfo);
writefln!"[>> %s] 200 OK"(req.ip);
res.code(HttpStatusCode.OK);
});

app.get("/", (req, res) {
try {
import std.datetime.systime;
import std.datetime.timezone;
import core.time;
auto time = Clock.currTime();
auto serverConfig = ServerConfig.defaultValues;
serverConfig.port = 6969;
auto s = new HttpServer(simpleHandler((ref req, ref res) {
if (req.url == "/reprovision") {
writeln("[<<] GET /reprovision");
adi.provisionDevice(rinfo);
writeln("[>>] 200 OK");
res.setStatus(200);
} else {
try {
import std.datetime.systime;
import std.datetime.timezone;
import core.time;
auto time = Clock.currTime();

writefln!"[%s >>] GET /"(req.ip);
writefln("[<<] GET /");

ubyte[] mid;
ubyte[] otp;
try {
adi.getOneTimePassword(mid, otp);
} catch {
writeln("Reprovision needed.");
adi.provisionDevice(rinfo);
adi.getOneTimePassword(mid, otp);
}
ubyte[] mid;
ubyte[] otp;
try {
adi.getOneTimePassword(mid, otp);
} catch (Throwable) {
writeln("Reprovision needed.");
adi.provisionDevice(rinfo);
adi.getOneTimePassword(mid, otp);
}

import std.conv;
import std.json;
import std.conv;
import std.json;

JSONValue response = [
JSONValue response = [
"X-Apple-I-Client-Time": time.toISOExtString.split('.')[0] ~ "Z",
"X-Apple-I-MD": Base64.encode(otp),
"X-Apple-I-MD-M": Base64.encode(mid),
Expand All @@ -71,18 +71,36 @@ void main(string[] args) {
"X-Apple-I-TimeZone": time.timezone.dstName,
"X-Apple-Locale": "en_US",
"X-Mme-Device-Id": adi.deviceId,
];
];

writefln!"[>> %s] 200 OK %s"(req.ip, response);
writefln!"[>>] 200 OK %s"(response);

res.code(HttpStatusCode.OK);
res.send(response);
} catch(Throwable t) {
res.code(HttpStatusCode.INTERNAL_SERVER_ERROR);
res.send(t.toString());
res.setStatus(200);
res.writeBody(to!string(response));
} catch(Throwable t) {
res.setStatus(500);
res.writeBody(t.toString());
}
}
});
}), serverConfig);
s.start();

/+
with (vib) {
Get("/reprovision", (req, res) => "Hello World!");
Get("", (req, res) {
});
}
// listenHTTP is called automatically
runApplication();
app.listen(6969);
scope (exit)
vib.Stop();
// +/
}

2 changes: 1 addition & 1 deletion cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ if(build_sideloadipa OR build_anisetteserver)
endif()

if(build_anisetteserver)
DubProject_Add(archttp ~1.1.0)
DubProject_Add(handy-httpd ~3.2.0)
endif()
endif()
36 changes: 36 additions & 0 deletions toolchains/rpi-2-no-suffix.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#File raspberrytoolchain.cmake for ROS and system packages to cross compile.
SET(CMAKE_SYSTEM_NAME Linux)

SET(_CMAKE_TOOLCHAIN_PREFIX "arm-linux-gnueabihf-")

SET(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
SET(CMAKE_D_COMPILER arm-linux-gnueabihf-gdc)

# Below call is necessary to avoid non-RT problem.
SET(CMAKE_LIBRARY_ARCHITECTURE arm-linux-gnueabihf)

SET(RASPBERRY_ROOT_PATH /usr/arm-linux-gnueabihf/sys-root)
SET(CMAKE_SYSROOT ${RASPBERRY_ROOT_PATH})

SET(CMAKE_FIND_ROOT_PATH ${RASPBERRY_ROOT_PATH})

#Have to set this one to BOTH, to allow CMake to find rospack
#This set of variables controls whether the CMAKE_FIND_ROOT_PATH and CMAKE_SYSROOT are used for find_xxx() operations.
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
# SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

#If you have installed cross compiler to somewhere else, please specify that path.
SET(COMPILER_ROOT ${RASPBERRY_ROOT_PATH})

SET(CMAKE_PREFIX_PATH ${RASPBERRY_ROOT_PATH})

SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -defaultlib=:libgphobos.a -fall-instantiations" CACHE INTERNAL "" FORCE)
# SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot=${RASPBERRY_ROOT_PATH}" CACHE INTERNAL "" FORCE)
# SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --sysroot=${RASPBERRY_ROOT_PATH}" CACHE INTERNAL "" FORCE)
# SET(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --sysroot=${RASPBERRY_ROOT_PATH}" CACHE INTERNAL "" FORCE)
# SET(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} --sysroot=${RASPBERRY_ROOT_PATH}" CACHE INTERNAL "" FORCE)

SET(LD_LIBRARY_PATH ${RASPBERRY_ROOT_PATH}/lib)

0 comments on commit 3e34315

Please sign in to comment.