From 3e34315449134917573017677528d3cf680ebb7f Mon Sep 17 00:00:00 2001 From: Dadoum Date: Thu, 10 Nov 2022 11:12:07 +0100 Subject: [PATCH] Preliminary ARM support --- .github/workflows/cmake-cross-compile.yml | 8 +- CMakeLists.txt | 2 +- anisette_server/app.d | 98 ++++++++++++++--------- cmake/dependencies.cmake | 2 +- toolchains/rpi-2-no-suffix.cmake | 36 +++++++++ 5 files changed, 100 insertions(+), 46 deletions(-) create mode 100644 toolchains/rpi-2-no-suffix.cmake diff --git a/.github/workflows/cmake-cross-compile.yml b/.github/workflows/cmake-cross-compile.yml index 40f70aa..df3c522 100644 --- a/.github/workflows/cmake-cross-compile.yml +++ b/.github/workflows/cmake-cross-compile.yml @@ -1,4 +1,4 @@ -name: aarch64 builds +name: ARM builds on: push: @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index bf46919..521c49f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/anisette_server/app.d b/anisette_server/app.d index 89974d4..a44b9a7 100644 --- a/anisette_server/app.d +++ b/anisette_server/app.d @@ -1,4 +1,4 @@ -import archttp; +import handy_httpd; import std.algorithm.searching; import std.array; import std.base64; @@ -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 { @@ -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); @@ -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), @@ -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(); + // +/ } diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index f82feee..ea497bc 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -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() \ No newline at end of file diff --git a/toolchains/rpi-2-no-suffix.cmake b/toolchains/rpi-2-no-suffix.cmake new file mode 100644 index 0000000..1825a0b --- /dev/null +++ b/toolchains/rpi-2-no-suffix.cmake @@ -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)