unify agnos/neos installers (#22023)

* c2 installer

* remove old installer

* move to its own dir

* die immediately

* fix that

* init app
pull/22032/head
Adeeb Shihadeh 2021-08-23 16:01:21 -07:00 committed by GitHub
parent 3179c64f44
commit 1ebe06d1c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 31 additions and 334 deletions

View File

@ -1,121 +0,0 @@
CC = clang
CXX = clang++
PHONELIBS = ../phonelibs
WARN_FLAGS = -Werror=implicit-function-declaration \
-Werror=incompatible-pointer-types \
-Werror=int-conversion \
-Werror=return-type \
-Werror=format-extra-args
CFLAGS = -std=gnu11 -fPIC -O2 $(WARN_FLAGS)
CXXFLAGS = -std=c++1z -fPIC -O2 $(WARN_FLAGS)
NANOVG_FLAGS = -I$(PHONELIBS)/nanovg
OPENGL_LIBS = -lGLESv3
FRAMEBUFFER_LIBS = -lutils -lgui -lEGL
COMMON_OBJS = ../selfdrive/common/glutil.o \
../selfdrive/common/framebuffer.o \
../selfdrive/common/util.o \
$(PHONELIBS)/nanovg/nanovg.o \
../selfdrive/common/spinner.o \
opensans_semibold.o \
img_spinner_track.o \
img_spinner_comma.o
OPENPILOT_OBJS = installer_openpilot.o \
continue_openpilot.o \
$(COMMON_OBJS)
DASHCAM_OBJS = installer_dashcam.o \
continue_dashcam.o \
$(COMMON_OBJS)
DEPS := $(OPENPILOT_OBJS:.o=.d) $(DASHCAM_OBJS:.o=.d)
.PHONY: all
all: installers/installer_dashcam installers/installer_openpilot
installers/installer_openpilot: $(OPENPILOT_OBJS)
@echo "[ LINK ] $@"
$(CXX) -fPIC -o '$@' $^ \
-s \
$(FRAMEBUFFER_LIBS) \
-L/system/vendor/lib64 \
$(OPENGL_LIBS) \
-lm -llog
installers/installer_dashcam: $(DASHCAM_OBJS)
@echo "[ LINK ] $@"
$(CXX) -fPIC -o '$@' $^ \
-s \
$(FRAMEBUFFER_LIBS) \
-L/system/vendor/lib64 \
$(OPENGL_LIBS) \
-lm -llog
../selfdrive/common/framebuffer.o: ../selfdrive/common/framebuffer.cc
@echo "[ CXX ] $@"
$(CXX) $(CXXFLAGS) -MMD \
-I$(PHONELIBS)/android_frameworks_native/include \
-I$(PHONELIBS)/android_system_core/include \
-I$(PHONELIBS)/android_hardware_libhardware/include \
-c -o '$@' '$<'
../selfdrive/common/spinner.o: ../selfdrive/common/spinner.c
@echo "[ CXX ] $@"
$(CXX) $(CXXFLAGS) -MMD \
-I$(PHONELIBS)/android_frameworks_native/include \
-I$(PHONELIBS)/android_system_core/include \
-I$(PHONELIBS)/android_hardware_libhardware/include \
$(NANOVG_FLAGS) \
-c -o '$@' '$<'
opensans_semibold.o: ../selfdrive/assets/fonts/opensans_semibold.ttf
@echo "[ bin2o ] $@"
cd '$(dir $<)' && ld -r -b binary '$(notdir $<)' -o '$(abspath $@)'
img_spinner_track.o: ../selfdrive/assets/img_spinner_track.png
@echo "[ bin2o ] $@"
cd '$(dir $<)' && ld -r -b binary '$(notdir $<)' -o '$(abspath $@)'
img_spinner_comma.o: ../selfdrive/assets/img_spinner_comma.png
@echo "[ bin2o ] $@"
cd '$(dir $<)' && ld -r -b binary '$(notdir $<)' -o '$(abspath $@)'
installer_openpilot.o: installer.c
@echo "[ CC ] $@"
$(CC) $(CFLAGS) -MMD \
-I.. -I../selfdrive \
-DBRAND=openpilot \
-DBRANCH=release2 \
-c -o '$@' '$<'
installer_dashcam.o: installer.c
@echo "[ CC ] $@"
$(CC) $(CFLAGS) -MMD \
-I.. -I../selfdrive \
-DBRAND=dashcam \
-DBRANCH=dashcam \
-c -o '$@' '$<'
%.o: %.c
@echo "[ CC ] $@"
$(CC) $(CFLAGS) -MMD \
-I.. -I../selfdrive \
-c -o '$@' '$<'
%.o: %.sh
@echo "[ bin2o ] $@"
cd '$(dir $<)' && ld -r -b binary '$(notdir $<)' -o '$(abspath $@)'
.PHONY: clean
clean:
rm -f installer_openpilot installer_dashcam $(OPENPILOT_OBJS) $(DASHCAM_OBJS) $(DEPS)
-include $(DEPS)

View File

@ -1,164 +0,0 @@
#include <assert.h>
#include <math.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES3/gl3.h>
#include "selfdrive/common/framebuffer.h"
#include "selfdrive/common/glutil.h"
#include "selfdrive/common/mat.h"
#include "selfdrive/common/spinner.h"
#include "selfdrive/common/util.h"
#ifndef BRAND
#define BRAND openpilot
#endif
#define STR(X) #X
#define STR2(X) STR(X)
#define PASTE(A, B) A ## B
#define PASTE2(A, B) PASTE(A, B)
#define BRAND_S STR2(BRAND)
#define BRANCH_S STR2(BRANCH)
#define PRE_CHECKOUT_FOLDER "/system/comma/openpilot"
#define GIT_CLONE_COMMAND "git clone https://github.com/commaai/openpilot.git "
extern const uint8_t str_continue[] asm("_binary_continue_" BRAND_S "_sh_start");
extern const uint8_t str_continue_end[] asm("_binary_continue_" BRAND_S "_sh_end");
static bool time_valid() {
time_t rawtime;
time(&rawtime);
struct tm * sys_time = gmtime(&rawtime);
return (1900 + sys_time->tm_year) >= 2019;
}
static int use_pre_checkout() {
int err;
// Cleanup
err = system("rm -rf /tmp/openpilot");
if(err) return 1;
err = system("rm -rf /data/openpilot");
if(err) return 1;
// Copy pre checkout into tmp so we can work on it
err = system("cp -rp " PRE_CHECKOUT_FOLDER " /tmp");
if(err) return 1;
err = chdir("/tmp/openpilot");
if(err) return 1;
// Checkout correct branch
err = system("git remote set-branches --add origin " BRANCH_S);
if(err) return 1;
err = system("git fetch origin " BRANCH_S);
if(err) return 1;
err = system("git checkout " BRANCH_S);
if(err) return 1;
err = system("git reset --hard origin/" BRANCH_S);
if(err) return 1;
// Move to final location
err = system("mv /tmp/openpilot /data");
if(err) return 1;
return 0;
}
static int fresh_clone() {
int err;
// Cleanup
err = chdir("/tmp");
if(err) return 1;
err = system("rm -rf /tmp/openpilot");
if(err) return 1;
err = system(GIT_CLONE_COMMAND " -b " BRANCH_S " --depth=1 openpilot");
if(err) return 1;
// Cleanup old folder in /data
err = system("rm -rf /data/openpilot");
if(err) return 1;
// this won't move if /data/openpilot exists
err = system("mv /tmp/openpilot /data");
if(err) return 1;
return 0;
}
static int do_install() {
int err;
// Wait for valid time
while (!time_valid()){
usleep(500 * 1000);
printf("Waiting for valid time\n");
}
struct stat sb;
if (stat(PRE_CHECKOUT_FOLDER, &sb) == 0 && S_ISDIR(sb.st_mode)) {
printf("Pre-checkout found\n");
err = use_pre_checkout();
} else {
printf("Doing fresh clone\n");
err = fresh_clone();
}
if(err) return 1;
// Write continue.sh
FILE *of = fopen("/data/data/com.termux/files/continue.sh.new", "wb");
if(of == NULL) return 1;
size_t num = str_continue_end - str_continue;
size_t num_written = fwrite(str_continue, 1, num, of);
if (num != num_written) return 1;
fclose(of);
err = system("chmod +x /data/data/com.termux/files/continue.sh.new");
if(err) return 1;
err = rename("/data/data/com.termux/files/continue.sh.new", "/data/data/com.termux/files/continue.sh");
if(err == -1) return 1;
// Disable SSH
err = system("setprop persist.neos.ssh 0");
if(err) return 1;
return 0;
}
void * run_spinner(void * args) {
char *loading_msg = "Installing " BRAND_S;
char *argv[2] = {NULL, loading_msg};
spin(2, argv);
return NULL;
}
int main() {
pthread_t spinner_thread;
int err = pthread_create(&spinner_thread, NULL, run_spinner, NULL);
assert(err == 0);
int status = do_install();
return status;
}

View File

@ -1,35 +0,0 @@
#!/usr/bin/env bash
set -e
ENVIRONMENT="${1}"
if [ "${ENVIRONMENT}" != "staging" -a "${ENVIRONMENT}" != "prod" ]; then
echo "usage: $0 <env>" >&2
echo " <env> = staging or prod" >&2
exit 1
fi
SUFFIX=""
if [ "${ENVIRONMENT}" != "prod" ]; then
SUFFIX="_test"
fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [[ -z $(az account show 2>/dev/null) ]]; then
echo "$(date --rfc-3339=s) LOGIN: azure"
az login
fi
FILES=(
installer_openpilot
installer_dashcam
)
for FILE in ${FILES[@]}; do
KEY="${FILE}${SUFFIX}"
echo "$(date --rfc-3339=s) PUSHING: ${FILE} -> ${KEY}"
az storage blob upload \
--account-name commadist \
--container-name neosupdate \
--name "${KEY}" \
--file "${FILE}"
done

View File

@ -1,6 +1,8 @@
moc_*
*.moc
installer/installers/*
replay/replay
qt/text
qt/spinner
@ -8,4 +10,3 @@ qt/setup/setup
qt/setup/reset
qt/setup/wifi
qt/setup/updater
qt/setup/installer_*

View File

@ -52,7 +52,8 @@ qt_src = ["main.cc", "ui.cc", "paint.cc", "qt/sidebar.cc", "qt/onroad.cc",
qt_env.Program("_ui", qt_src, LIBS=qt_libs)
# setup, factory resetter, and installer
# setup, factory resetter, and agnos updater
if arch != 'aarch64' and GetOption('setup'):
# TODO: do this for all resources once NEOS has rcc
@ -67,20 +68,26 @@ if arch != 'aarch64' and GetOption('setup'):
qt_env.Program("qt/setup/setup", ["qt/setup/setup.cc", asset_obj],
LIBS=qt_libs + ['curl', 'common', 'json11'])
# build installers
if GetOption('setup'):
senv = qt_env.Clone()
senv['LINKFLAGS'].append('-Wl,-strip-debug')
release = "release3" if arch == 'larch64' else "release2"
dashcam = "dashcam3" if arch == 'larch64' else "dashcam"
installers = [
("openpilot", "release3"),
("openpilot_test", "release3-staging"),
("openpilot", release),
("openpilot_test", f"{release}-staging"),
("openpilot_nightly", "master-ci"),
("openpilot_internal", "master"),
("dashcam", "dashcam3"),
("dashcam_test", "dashcam3-staging"),
("dashcam", dashcam),
("dashcam_test", f"{dashcam}-staging"),
]
cont = {}
for brand in ("openpilot", "dashcam"):
cont[brand] = senv.Command(f"qt/setup/continue_{brand}.o", f"#installer/continue_{brand}.sh",
cont[brand] = senv.Command(f"installer/continue_{brand}.o", f"installer/continue_{brand}.sh",
"ld -r -b binary -o $TARGET $SOURCE")
for name, branch in installers:
brand = "dashcam" if "dashcam" in branch else "openpilot"
@ -92,8 +99,8 @@ if arch != 'aarch64' and GetOption('setup'):
r = requests.get("https://github.com/commaci2.keys")
r.raise_for_status()
d['SSH_KEYS'] = f'\\"{r.text.strip()}\\"'
obj = senv.Object(f"qt/setup/installer_{name}.o", ["qt/setup/installer.cc"], CPPDEFINES=d)
f = senv.Program(f"qt/setup/installer_{name}", [obj, cont[brand]], LIBS=qt_libs)
obj = senv.Object(f"installer/installers/installer_{name}.o", ["installer/installer.cc"], CPPDEFINES=d)
f = senv.Program(f"installer/installers/installer_{name}", [obj, cont[brand]], LIBS=qt_libs)
# keep installers small
assert f[0].get_size() < 300*1e3

View File

@ -10,21 +10,26 @@
#include <QTimer>
#include <QVBoxLayout>
#include "selfdrive/ui/installer/installer.h"
#include "selfdrive/ui/qt/util.h"
#include "selfdrive/ui/qt/qt_window.h"
#include "selfdrive/ui/qt/setup/installer.h"
#define GIT_URL "https://github.com/commaai/openpilot.git"
#define GIT_SSH_URL "git@github.com:commaai/openpilot.git"
#define CONTINUE_PATH "/data/continue.sh"
#ifdef QCOM
#define CONTINUE_PATH "/data/data/com.termux/files/continue.sh"
#define CACHE_PATH "/system/comma/openpilot"
#else
#define CONTINUE_PATH "/data/continue.sh"
#define CACHE_PATH "/usr/comma/openpilot"
#endif
#define CACHE_PATH "/usr/comma/openpilot"
#define INSTALL_PATH "/data/openpilot"
#define TMP_INSTALL_PATH "/data/tmppilot"
extern const uint8_t str_continue[] asm("_binary_installer_continue_" BRAND "_sh_start");
extern const uint8_t str_continue_end[] asm("_binary_installer_continue_" BRAND "_sh_end");
extern const uint8_t str_continue[] asm("_binary_selfdrive_ui_installer_continue_" BRAND "_sh_start");
extern const uint8_t str_continue_end[] asm("_binary_selfdrive_ui_installer_continue_" BRAND "_sh_end");
bool time_valid() {
time_t rawtime;
@ -195,8 +200,12 @@ void Installer::cloneFinished(int exitCode, QProcess::ExitStatus exitStatus) {
run("chmod +x /data/continue.sh.new");
run("mv /data/continue.sh.new " CONTINUE_PATH);
#ifdef QCOM
QTimer::singleShot(100, &QCoreApplication::quit);
#else
// wait for the installed software's UI to take over
QTimer::singleShot(60 * 1000, &QCoreApplication::quit);
#endif
}
int main(int argc, char *argv[]) {