get rid of start from pongo

This commit is contained in:
Nick Chan committed 2023-02-01 20:10:18 +08:00
1 parent 72e3fde894
commit 72acd82f9f
6 files changed
+58 -34

No files matched your search

+3 -2
View File
@@ -117,9 +117,9 @@ extern pthread_mutex_t log_mutex;
extern pthread_mutex_t spin_mutex, found_pongo_mutex, ecid_dfu_wait_mutex;
extern int enable_rootful, do_pongo_sleep, demote;
extern int enable_rootful, demote;
extern int pongo_thr_running, dfuhelper_thr_running;
extern bool ohio, start_from_pongo, pongo_full;
extern bool ohio, pongo_full, device_has_booted;
extern char xargs_cmd[0x270];
extern char checkrain_flags_cmd[0x20];
extern char palerain_flags_cmd[0x20];
@@ -164,6 +164,7 @@ int optparse(int argc, char* argv[]);
bool get_spin();
bool set_spin(bool val);
bool get_found_pongo();
void* pongo_helper(void* _);
bool set_found_pongo(bool val);
uint64_t get_ecid_wait_for_dfu();
uint64_t set_ecid_wait_for_dfu(uint64_t ecid);
+13
View File
@@ -32,6 +32,8 @@
#define NOHOME (cpid == 0x8015 || (cpid == 0x8010 && (bdid == 0x08 || bdid == 0x0a || bdid == 0x0c || bdid == 0x0e)))
int dfuhelper_thr_running = false;
void step(int time, int time2, char *text, bool (*cond)(uint64_t), uint64_t cond_arg) {
for (int i = time2; i < time; i++) {
printf(CYN "\r\e[K%s (%d)" CRESET, text, time - i + time2);
@@ -89,6 +91,9 @@ void* connected_recovery_mode(struct irecv_device_info* info) {
cpid = info->cpid;
ecid = info->ecid;
bdid = info->bdid;
#if defined(__APPLE__) || defined(__linux__)
pthread_setname_np("in.palera.recovery-mode-handler");
#endif
if (!cpid_is_arm64(info->cpid)) {
LOG(LOG_WARNING, "Ignoring non-arm64 device...");
return NULL;
@@ -136,6 +141,9 @@ void* connected_recovery_mode(struct irecv_device_info* info) {
}
void* connected_dfu_mode(struct irecv_device_info* info) {
#if defined(__APPLE__) || defined(__linux__)
pthread_setname_np("in.palera.dfu-mode-handler");
#endif
if (get_ecid_wait_for_dfu() == info->ecid) {
set_ecid_wait_for_dfu(0);
puts("");
@@ -180,10 +188,15 @@ void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
}
void *dfuhelper(void* ptr) {
dfuhelper_thr_running = true;
#if defined(__APPLE__) || defined(__linux__)
pthread_setname_np("in.palera.dfu-helper");
#endif
subscribe_cmd(device_event_cb, irecv_device_event_cb);
set_spin(1);
while (get_spin()) {
sleep(1);
};
dfuhelper_thr_running = false;
return 0;
}
+16 -13
View File
@@ -33,7 +33,7 @@
#define OVERRIDE_MAGIC 0xd803b376
unsigned int verbose = 0;
int enable_rootful = 0, do_pongo_sleep = 0, demote = 0;
int enable_rootful = 0, demote = 0;
bool ohio = true;
char xargs_cmd[0x270] = "xargs", checkrain_flags_cmd[0x20] = "deadbeef", palerain_flags_cmd[0x20] = "deadbeef";
char kpf_flags_cmd[0x20] = "deadbeef", dtpatch_cmd[0x20] = "deadbeef", rootfs_cmd[512] = "deadbeef";
@@ -53,6 +53,11 @@ override_file_t override_ramdisk, override_kpf, override_overlay;
uint32_t checkrain_flags = 0, palerain_flags = 0, kpf_flags = 0;
pthread_mutex_t log_mutex;
pthread_t dfuhelper_thread, pongo_thread;
void thr_cleanup(void* ptr) {
*(int*)ptr = 0;
}
int build_checks() {
#if defined(__APPLE__)
@@ -80,13 +85,16 @@ int build_checks() {
return 0;
}
bool dfuhelper_only = false, pongo_exit = false, start_from_pongo = false, palerain_version = false;
bool dfuhelper_only = false, pongo_exit = false, palerain_version = false;
#ifdef DEV_BUILD
bool use_tui = false;
#endif
int palera1n(int argc, char *argv[]) {
int ret = 0;
#if defined(__APPLE__) || defined(__linux__)
pthread_setname_np("in.palera.main-thread");
#endif
pthread_mutex_init(&log_mutex, NULL);
pthread_mutex_init(&spin_mutex, NULL);
pthread_mutex_init(&found_pongo_mutex, NULL);
@@ -94,8 +102,6 @@ int palera1n(int argc, char *argv[]) {
if ((ret = build_checks())) return ret;
if ((ret = optparse(argc, argv))) goto cleanup;
if (palerain_version) goto normal_exit;
if (start_from_pongo == true)
goto pongo;
#ifdef DEV_BUILD
if (use_tui) {
ret = tui();
@@ -104,22 +110,19 @@ int palera1n(int argc, char *argv[]) {
}
#endif
LOG(LOG_INFO, "Waiting for devices");
do_pongo_sleep = 1;
pthread_t dfuhelper_thread;
pthread_create(&pongo_thread, NULL, pongo_helper, NULL);
pthread_create(&dfuhelper_thread, NULL, dfuhelper, NULL);
pthread_join(dfuhelper_thread, NULL);
if (dfuhelper_only)
set_spin(0);
if (dfuhelper_only || device_has_booted)
goto normal_exit;
exec_checkra1n();
if (pongo_exit || demote)
goto normal_exit;
pongo:
set_spin(1);
if (do_pongo_sleep)
sleep(2);
else
LOG(LOG_INFO, "Waiting for PongoOS devices...");
wait_for_pongo();
sleep(2);
pthread_create(&pongo_thread, NULL, pongo_helper, NULL);
pthread_join(pongo_thread, NULL);
while (get_spin())
{
sleep(1);
+11 -17
View File
@@ -19,8 +19,7 @@ static struct option longopts[] = {
{"dfuhelper", no_argument, NULL, 'D'},
{"help", no_argument, NULL, 'h'},
{"pongo-shell", no_argument, NULL, 'p'},
{"pongo-full", no_argument, NULL, 'F'},
{"start-from-pongo", no_argument, NULL, 'P'},
{"pongo-full", no_argument, NULL, 'P'},
{"debug-logging", no_argument, NULL, 'v'},
{"verbose-boot", no_argument, NULL, 'V'},
{"boot-args", required_argument, NULL, 'e'},
@@ -46,9 +45,9 @@ static int usage(int e, char* prog_name)
{
fprintf(stderr,
#ifdef DEV_BUILD
"Usage: %s [-cCDhpvVldsOLtfF]"
"Usage: %s [-cCDhpvVldsOLtf]"
#else
"Usage: %s [-cCDhpvVldsOLfF]"
"Usage: %s [-cCDhpvVldsOLf]"
#endif
" [-e boot arguments] [-k Pongo image] [-o overlay file] [-r ramdisk file] [-K KPF file]\n"
"Copyright (C) 2023, palera1n team, All Rights Reserved.\n\n"
@@ -60,8 +59,7 @@ static int usage(int e, char* prog_name)
"\t-D, --dfuhelper-only\t\t\tExit after entering DFU\n"
"\t-h, --help\t\t\t\tShow this help\n"
"\t-p, --pongo-shell\t\t\tBoots to PongoOS shell\n"
"\t-P, --start-from-pongo\t\t\tStart with a PongoOS USB Device attached\n"
"\t-F, --pongo-full\t\t\tBoots to a PongoOS shell with default images already uploaded\n"
"\t-P, --pongo-full\t\t\tBoots to a PongoOS shell with default images already uploaded\n"
"\t-v, --debug-logging\t\t\tEnable debug logging\n"
"\t\tThis option can be repeated for extra verbosity.\n"
"\t-V, --verbose-boot\t\t\tVerbose boot\n"
@@ -89,9 +87,9 @@ int optparse(int argc, char* argv[]) {
int index;
while ((opt = getopt_long(argc, argv,
#ifdef DEV_BUILD
"cCDhpvVldsOLtfFe:o:r:K:k:",
"cCDhpvVldsOLtfPe:o:r:K:k:",
#else
"cCDhpvVldsOLfFe:o:r:K:k:",
"cCDhpvVldsOLfPe:o:r:K:k:",
#endif
longopts, NULL)) != -1)
{
@@ -109,7 +107,7 @@ int optparse(int argc, char* argv[]) {
pongo_exit = true;
break;
case 'P':
start_from_pongo = true;
pongo_full = 1;
break;
case 'D':
dfuhelper_only = true;
@@ -138,9 +136,6 @@ int optparse(int argc, char* argv[]) {
snprintf(dtpatch_cmd, 0x20, "dtpatch %s", optarg);
enable_rootful = 1;
break;
case 'F':
pongo_full = 1;
break;
case 'l':
enable_rootful = 0;
break;
@@ -212,6 +207,10 @@ int optparse(int argc, char* argv[]) {
palerain_flags |= palerain_option_rootful;
}
if (checkrain_option_enabled(checkrain_flags, checkrain_option_force_revert) && checkrain_option_enabled(palerain_flags, palerain_option_setup_rootful)) {
LOG(LOG_WARNING, "force revert and setup rootful requested at the same time, behaviour here is undefined");
}
snprintf(checkrain_flags_cmd, 0x20, "checkra1n_flags 0x%x", checkrain_flags);
snprintf(palerain_flags_cmd, 0x20, "palera1n_flags 0x%x", palerain_flags);
snprintf(kpf_flags_cmd, 0x20, "kpf_flags 0x%x", kpf_flags);
@@ -238,11 +237,6 @@ int optparse(int argc, char* argv[]) {
}
}
if (dfuhelper_only && start_from_pongo) {
LOG(LOG_FATAL, "cannot start from pongo while being dfuhelper only");
return -1;
}
for (index = optind; index < argc; index++)
{
if (!strcmp("windows", argv[index]))
+13 -1
View File
@@ -12,11 +12,15 @@
#include <common.h>
bool pongo_full = 0;
bool pongo_full, device_has_booted = 0;
int pongo_thr_running = 0;
void* pongo_helper(void* ptr) {
pongo_thr_running = 1;
pthread_cleanup_push(thr_cleanup, &pongo_thr_running);
#if defined(__APPLE__) || defined(__linux__)
pthread_setname_np("in.palera.pongo-helper");
#endif
wait_for_pongo();
while (get_spin()) {
sleep(1);
@@ -29,6 +33,9 @@ void *pongo_usb_callback(void *arg) {
if (get_found_pongo())
return NULL;
set_found_pongo(1);
#if defined(__APPLE__) || defined(__linux__)
pthread_setname_np("in.palera.pongo-handler");
#endif
strncat(xargs_cmd, " rootdev=md0", 0x270 - strlen(xargs_cmd) - 1);
if (checkrain_option_enabled(palerain_flags, palerain_option_setup_rootful)) {
strncat(xargs_cmd, " wdt=-1", 0x270 - strlen(xargs_cmd) - 1);
@@ -55,7 +62,12 @@ void *pongo_usb_callback(void *arg) {
if (pongo_full) goto done;
issue_pongo_command(handle, "bootx");
LOG(LOG_INFO, "Booting Kernel...");
if (dfuhelper_thr_running) {
pthread_cancel(dfuhelper_thread);
dfuhelper_thr_running = false;
}
done:
device_has_booted = true;
set_spin(0);
return NULL;
}
+2 -1
View File
@@ -278,7 +278,7 @@ int wait_for_pongo(void)
}
libusb_exit(NULL);
return -1;
return 0;
}
@@ -400,3 +400,4 @@ int upload_pongo_file(usb_device_handle_t handle, unsigned char *buf, unsigned i
}
return ret;
}