From 9faa95af562091644986d3ccf47500c7d65c74e6 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 29 Jan 2022 18:42:45 +0100 Subject: [PATCH] Add support for reading the seeprom. --- Makefile | 2 +- include/iosuhax.h | 2 ++ source/iosuhax.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 03af789..c5b9f50 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ TOPDIR ?= $(CURDIR) include $(DEVKITPRO)/wut/share/wut_rules export VER_MAJOR := 1 -export VER_MINOR := 0 +export VER_MINOR := 1 export VER_PATCH := 0 VERSION := $(VER_MAJOR).$(VER_MINOR).$(VER_PATCH) diff --git a/include/iosuhax.h b/include/iosuhax.h index b3a2559..82c1e9e 100644 --- a/include/iosuhax.h +++ b/include/iosuhax.h @@ -72,6 +72,8 @@ int IOSUHAX_kern_read32(uint32_t address, uint32_t *out_buffer, uint32_t count); int IOSUHAX_read_otp(uint8_t * out_buffer, uint32_t size); +int IOSUHAX_read_seeprom(uint8_t * out_buffer, uint32_t offset, uint32_t size); + int IOSUHAX_ODM_GetDiscKey(uint8_t * discKey); int IOSUHAX_SVC(uint32_t svc_id, uint32_t *args, uint32_t arg_cnt); diff --git a/source/iosuhax.c b/source/iosuhax.c index 66ea8fb..3026329 100644 --- a/source/iosuhax.c +++ b/source/iosuhax.c @@ -199,6 +199,37 @@ int IOSUHAX_read_otp(uint8_t * out_buffer, uint32_t size) { return res; } +extern int bspRead(const char*, uint32_t, const char*, uint32_t, uint16_t*); + +int IOSUHAX_read_seeprom(uint8_t * out_buffer, uint32_t offset, uint32_t size) { + if(out_buffer == NULL || offset > 0x200 || offset & 0x01) { + return -1; + } + + uint32_t sizeInShorts = size >> 1; + uint32_t offsetInShorts = offset >> 1; + int32_t maxReadCount = 0x100 - offsetInShorts; + + if(maxReadCount <= 0){ + return 0; + } + + uint32_t count = sizeInShorts > maxReadCount ? maxReadCount : sizeInShorts; + uint16_t *ptr = (uint16_t *) out_buffer; + + int res = 0; + + for(int i = 0; i < count; i++) { + if(bspRead("EE", offsetInShorts + i, "access", 2, ptr) != 0) { + return -2; + } + res += 2; + ptr++; + } + + return res; +} + int IOSUHAX_kern_read32(uint32_t address, uint32_t *out_buffer, uint32_t count) { if (iosuhaxHandle < 0) return iosuhaxHandle;