From a8d7e2bd7c36ffd7a0040aed52520d40c458a5b2 Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Sun, 16 Aug 2026 14:14:56 -0500 Subject: [PATCH] feat: [libapa] only reset __common and after partitions on format for xosd variant --- iop/hdd/apa/src/apa-opt.h | 1 + iop/hdd/apa/src/hdd_fio.c | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/iop/hdd/apa/src/apa-opt.h b/iop/hdd/apa/src/apa-opt.h index 1bd97e6a4878..e2e91434f214 100644 --- a/iop/hdd/apa/src/apa-opt.h +++ b/iop/hdd/apa/src/apa-opt.h @@ -25,6 +25,7 @@ #ifdef APA_XOSD_VER #define APA_OSD_VER #define APA_SUPPORT_BHDD +#define APA_FORMAT_WIPE_COMMON_ONLY #endif #ifdef APA_OSD_VER diff --git a/iop/hdd/apa/src/hdd_fio.c b/iop/hdd/apa/src/hdd_fio.c index 76de6bbea293..71ca955726a8 100644 --- a/iop/hdd/apa/src/hdd_fio.c +++ b/iop/hdd/apa/src/hdd_fio.c @@ -40,9 +40,17 @@ extern apa_device_t hddDevices[]; #ifdef APA_FORMAT_MAKE_PARTITIONS // TODO: For DVRP firmware 48-bit, __xdata and __xcontents partitions are created +#ifndef APA_FORMAT_WIPE_COMMON_ONLY static const char *formatPartList[] = { "__net", "__system", "__sysconf", "__common", NULL}; #endif +#endif + +#ifdef APA_FORMAT_WIPE_COMMON_ONLY +#define APA_WIPE_CHUNK_START (8 + 256) +#else +#define APA_WIPE_CHUNK_START 8 +#endif #ifndef APA_8MB_PARTITION_SIZE #define APA_NUMBER_OF_SIZES 9 @@ -340,7 +348,9 @@ int hddFormat(iomanX_iop_file_t *f, const char *dev, const char *blockdev, void // clear apa headers // TODO: Why does DVRP firmware start clearing at 1024 * 4104 when not 48-bit? // TODO: DVRP firmware 48-bit clears offset_24+0x2000, offset_24+0x42000, offset_24+0x242000 - for (i = 1024 * 8; i < hddDevices[f->unit].totalLBA; i += (1024 * 256)) { + for (i = 1024 * APA_WIPE_CHUNK_START; i < hddDevices[f->unit].totalLBA; i += (1024 * 256)) { + // NOTE: XOSD variant traps on LBA 0 if __mbr detected: + // "hdd: __mbr will be unformated or destroyed." blkIoDmaTransfer(f->unit, clink->header, i, sizeof(apa_header_t) / 512, BLKIO_DIR_WRITE); } @@ -348,6 +358,7 @@ int hddFormat(iomanX_iop_file_t *f, const char *dev, const char *blockdev, void if ((rv = apaJournalReset(f->unit)) != 0) return rv; +#ifndef APA_FORMAT_WIPE_COMMON_ONLY // set up mbr :) if ((clink = apaCacheGetHeader(f->unit, APA_SECTOR_MBR, APA_IO_MODE_WRITE, &rv))) { apa_header_t *header = clink->header; @@ -393,6 +404,7 @@ int hddFormat(iomanX_iop_file_t *f, const char *dev, const char *blockdev, void hddDevices[f->unit].status = 0; hddDevices[f->unit].format = APA_MBR_VERSION; } +#endif // TODO: DVRP firmware 48-bit creates __extend partition at offset_24_bit, with same params as __mbr except content is empty #ifdef APA_FORMAT_MAKE_PARTITIONS memset(&emptyBlocks, 0, sizeof(emptyBlocks)); @@ -403,6 +415,17 @@ int hddFormat(iomanX_iop_file_t *f, const char *dev, const char *blockdev, void // TODO: For DVRP firmware 48-bit, __xdata is created with size 1024 * 2048 // TODO: For DVRP firmware 48-bit, __xcontents is created with size (offset_48_bit - offset_24_bit) - 0x240000 & 0xfffff7ff // add __net, __system.... +#ifdef APA_FORMAT_WIPE_COMMON_ONLY + memset(params.id, 0, sizeof(params.id)); + strcpy(params.id, "__sysconf"); + if ( !(clink = apaFindPartition(f->unit, params.id, &rv)) ) + return rv; + apaCacheFree(clink); + memset(params.id, 0, APA_IDMAX); + strcpy(params.id, "__common"); + if ( !hddAddPartitionHere(f->unit, ¶ms, emptyBlocks, clink->sector, &rv) ) + return rv; +#else for (i = 0; formatPartList[i]; i++) { memset(params.id, 0, APA_IDMAX); strcpy(params.id, formatPartList[i]); @@ -414,6 +437,7 @@ int hddFormat(iomanX_iop_file_t *f, const char *dev, const char *blockdev, void if (hddDevices[f->unit].partitionMaxSize < params.size) params.size = hddDevices[f->unit].partitionMaxSize; } +#endif #endif return rv; }