Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "AppleHPMLib.h"
#include "ssops.h"
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <unistd.h>
Expand Down Expand Up @@ -115,7 +116,7 @@ uint32_t GetUnlockKey()
return (deviceName[0] << 24) | (deviceName[1] << 16) | (deviceName[2] << 8) | deviceName[3];
}

std::unique_ptr<HPMPluginInstance> FindDevice()
std::unique_ptr<HPMPluginInstance> FindDevice(int target_rid)
{
std::unique_ptr<HPMPluginInstance> ret;

Expand Down Expand Up @@ -150,8 +151,8 @@ std::unique_ptr<HPMPluginInstance> FindDevice()
CFNumberGetValue(data, kCFNumberSInt32Type, &rid);
CFRelease(data);

// RID=0 seems to always be the right port
if (rid != 0)
// RID is a fixed per-port id; default 0, override with -p <rid> to drive other ports.
if (rid != target_rid)
continue;

printf("Found: %s\n", pathName);
Expand Down Expand Up @@ -306,8 +307,14 @@ int DoDFU(HPMPluginInstance &inst, int no)

int main2(int argc, char **argv)
{
if (argc < 2) {
printf("Usage: %s <command>\n", argv[0]);
int rid = 0, base = 1;
if (argc >= 3 && std::string(argv[1]) == "-p") {
rid = atoi(argv[2]);
base = 3;
}

if (argc < base + 1) {
printf("Usage: %s [-p <rid>] <command>\n", argv[0]);
printf("Commands:\n");
printf(" serial - enter serial mode on both ends\n");
printf(" debugusb - enter debugusb mode on the target\n");
Expand All @@ -321,7 +328,7 @@ int main2(int argc, char **argv)

uint32_t key = GetUnlockKey();

auto inst = FindDevice();
auto inst = FindDevice(rid);
int no = 0;

auto t = inst->readRegister(no, 0x3f);
Expand Down Expand Up @@ -350,11 +357,11 @@ int main2(int argc, char **argv)
throw failure("Failed to enter DBMa mode");
}

std::string cmd = argv[1];
std::string cmd = argv[base];
std::string arg = "";

if (argc >= 3)
arg = argv[2];
if (argc >= base + 2)
arg = argv[base + 1];

if (cmd == "serial")
return DoSerial(*inst, no);
Expand Down