Added hiddbgWriteSerialFlash.

This commit is contained in:
yellows8 2019-10-19 18:42:45 -04:00
parent ecd6cd73ca
commit edcd25bdae
No known key found for this signature in database
GPG Key ID: 0AF90DA3F1E60E43
2 changed files with 41 additions and 1 deletions

View File

@ -137,6 +137,12 @@ Result hiddbgAcquireOperationEventHandle(Event* out_event, bool autoclear, u64 U
/// Only available with [6.0.0+]. /// Only available with [6.0.0+].
Result hiddbgReadSerialFlash(u32 offset, void* buffer, size_t size, u64 UniquePadId); Result hiddbgReadSerialFlash(u32 offset, void* buffer, size_t size, u64 UniquePadId);
/// Writes spi-flash for the specified controller. See hidsys.h for UniquePadId.
/// buffer and tmem_size must be page-aligned. size is the actual transfer size.
/// This also uses \ref hiddbgAcquireOperationEventHandle to wait for the operation to finish, then \ref hiddbgGetOperationResult is used.
/// Only available with [6.0.0+].
Result hiddbgWriteSerialFlash(u32 offset, void* buffer, size_t tmem_size, size_t size, u64 UniquePadId);
/// Get the Result for the Operation and handles cleanup, for the specified controller. See hidsys.h for UniquePadId. /// Get the Result for the Operation and handles cleanup, for the specified controller. See hidsys.h for UniquePadId.
/// Only available with [6.0.0+]. /// Only available with [6.0.0+].
Result hiddbgGetOperationResult(u64 UniquePadId); Result hiddbgGetOperationResult(u64 UniquePadId);

View File

@ -130,7 +130,21 @@ static Result _hiddbgReadSerialFlash(TransferMemory *tmem, u32 offset, u64 size,
); );
} }
// sdk-nso doesn't use hiddbgAcquireOperationEventHandle/hiddbgGetOperationResult in the ReadSerialFlash impl, those are used seperately by the user. static Result _hiddbgWriteSerialFlash(TransferMemory *tmem, u32 offset, u64 tmem_size, u64 size, u64 UniquePadId) {
const struct {
u32 offset;
u64 tmem_size;
u64 size;
u64 UniquePadId;
} in = { offset, tmem_size, size, UniquePadId };
return serviceDispatchIn(&g_hiddbgSrv, 230, in,
.in_num_handles = 1,
.in_handles = { tmem->handle },
);
}
// sdk-nso doesn't use hiddbgAcquireOperationEventHandle/hiddbgGetOperationResult in the *SerialFlash impl, those are used seperately by the user. [9.0.0+] sdk-nso no longer exposes *SerialFlash and related functionality.
Result hiddbgReadSerialFlash(u32 offset, void* buffer, size_t size, u64 UniquePadId) { Result hiddbgReadSerialFlash(u32 offset, void* buffer, size_t size, u64 UniquePadId) {
Result rc=0; Result rc=0;
Event tmpevent={0}; Event tmpevent={0};
@ -153,6 +167,26 @@ Result hiddbgReadSerialFlash(u32 offset, void* buffer, size_t size, u64 UniquePa
return rc; return rc;
} }
Result hiddbgWriteSerialFlash(u32 offset, void* buffer, size_t tmem_size, size_t size, u64 UniquePadId) {
Result rc=0;
Event tmpevent={0};
TransferMemory tmem;
if (hosversionBefore(6,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);
rc = tmemCreateFromMemory(&tmem, buffer, tmem_size, Perm_R);
if (R_FAILED(rc)) return rc;
rc = hiddbgAcquireOperationEventHandle(&tmpevent, true, UniquePadId); // *Must* be used before _hiddbgWriteSerialFlash.
if (R_SUCCEEDED(rc)) rc = _hiddbgWriteSerialFlash(&tmem, offset, tmem_size, size, UniquePadId);
if (R_SUCCEEDED(rc)) rc = eventWait(&tmpevent, U64_MAX);
if (R_SUCCEEDED(rc)) rc = hiddbgGetOperationResult(UniquePadId);
eventClose(&tmpevent);
tmemClose(&tmem);
return rc;
}
Result hiddbgGetOperationResult(u64 UniquePadId) { Result hiddbgGetOperationResult(u64 UniquePadId) {
if (hosversionBefore(6,0,0)) if (hosversionBefore(6,0,0))
return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer);