first and last commit

This commit is contained in:
Chris Nutter committed 2023-07-08 13:03:17 -07:00
commit 1bf4efd552
2612 files changed
+636500

No files matched your search

@@ -0,0 +1,256 @@
/*
* Copyright (c) 2008-2009 Apple Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#include "ANDTypes.h"
#include "WMROAM.h"
#include "VFLBuffer.h"
#include "FPart.h"
#include "WMRConfig.h"
#include "WhimoryBoot.h"
#include "ANDStats.h"
#include "FTL.h"
#include "VFL.h"
static VFLFunctions *stVflFunctions;
static FTLFunctions *stFtlFunctions;
typedef BOOL32 (*GetStructFunc)(UInt32 dwStructType, void * pvoidStructBuffer, UInt32 * pdwStructSize);
typedef struct {
UInt32 dwStructLayer;
UInt32 dwStructType;
UInt32 dwStructVersion;
} ExportStructParameters;
static ExportStructParameters astrStructsToExport[] =
{
// header (must be first)
{ 0, AND_STRUCT_WMR_EXPORT_ALL, AND_EXPORT_STRUCTURE_VERSION},
// WMR Version (FTL & VFL types)
{AND_STRUCT_LAYER_WMR, AND_STRUCT_WMR_VERSION, 0},
// VFL_type
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_GET_TYPE, 0},
// FTL_type ( FTL/yaFTL)
{AND_STRUCT_LAYER_FTL, AND_STRUCT_FTL_GET_TYPE, 0},
// All VFL Meta
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 0, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 1, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 2, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 3, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 4, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 5, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 6, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 7, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 8, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 9, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 10, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 11, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 12, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 13, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 14, 0},
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_VFLMETA | 15, 0},
//FTL geometry
{AND_STRUCT_LAYER_FTL,AND_STRUCT_FTL_GET_FTL_DEVICEINFO, 0},
// FTL
{AND_STRUCT_LAYER_FTL, AND_STRUCT_FTL_FTLCXT, 0},
// FTL counters
{AND_STRUCT_LAYER_FTL, AND_STRUCT_FTL_GET_FTL_EC_BINS, 1},
{AND_STRUCT_LAYER_FTL, AND_STRUCT_FTL_GET_FTL_RC_BINS, 1},
// FTL - Stat
{AND_STRUCT_LAYER_FTL, AND_STRUCT_FTL_STATISTICS, 0},
// VFL - Stat
{AND_STRUCT_LAYER_VFL, AND_STRUCT_VFL_STATISTICS, 0},
// FIL - Device Info
{AND_STRUCT_LAYER_FIL, AND_STRUCT_FIL_DEVICE_INFO, 0},
// FIL - Stat
{AND_STRUCT_LAYER_FIL, AND_STRUCT_FIL_STATISTICS, 0},
// footer (must be last)
{0, AND_STRUCT_WMR_EXPORT_ALL_END, AND_EXPORT_STRUCTURE_VERSION},
};
#define AND_DUMP_DEBUG (0)
#if AND_DUMP_DEBUG
#define DUMP_VAR(variable) WMR_PRINT(ALWAYS, "%s : %u\n", #variable, (UInt32)(variable))
static void
hexdump(UInt8 *bytes, int count)
{
int i, j;
for (i = 0; i < count; i += 16) {
kprintf("%04x:", i);
for (j = 0; (j < 16) && ((i + j) < count); j++)
kprintf(" %02.2x", *bytes++);
kprintf("\n");
}
}
#else
#define DUMP_VAR(variable)
#endif //AND_DUMP_DEBUG
static GetStructFunc _translateStructLayer (UInt32 dwStructLayer)
{
switch (dwStructLayer)
{
case AND_STRUCT_LAYER_FTL:
return stFtlFunctions->GetStruct;
case AND_STRUCT_LAYER_VFL:
return stVflFunctions->GetStruct;
case AND_STRUCT_LAYER_FIL:
return FIL_GetStruct;
case AND_STRUCT_LAYER_WMR:
return WMR_PPNGetStruct;
default:
return NULL;
}
}
static BOOL32 _appendStructToBuffer(void *pvoidExportBuffer,
UInt32 *pdwBufferSize,
UInt32 dwStructLayer,
UInt32 dwStructType,
UInt32 dwStructVersion)
{
UInt32 dwDataSize;
BOOL32 boolResult;
GetStructFunc fGetStruct = _translateStructLayer(dwStructLayer);
UInt8 *cursor = (UInt8*) pvoidExportBuffer;
DUMP_VAR(pvoidExportBuffer);
if (pdwBufferSize)
{
DUMP_VAR(*pdwBufferSize);
}
DUMP_VAR(dwStructLayer);
DUMP_VAR(dwStructType);
DUMP_VAR(dwStructVersion);
if (fGetStruct)
{
if (pvoidExportBuffer)
{
// leave room for the struct header
cursor += sizeof(ANDExportStruct);
}
dwDataSize = pdwBufferSize ? (*pdwBufferSize - sizeof(ANDExportStruct)) : 0;
boolResult = fGetStruct(dwStructType, cursor, &dwDataSize);
DUMP_VAR(dwDataSize);
}
else
{
// for header and footer
boolResult = TRUE32;
dwDataSize = 0;
}
if (boolResult)
{
#if AND_DUMP_DEBUG
if (pvoidExportBuffer)
{
hexdump(pvoidExportBuffer, dwDataSize);
}
#endif
if (pdwBufferSize)
{
*pdwBufferSize = dwDataSize + sizeof(ANDExportStruct);
}
if (pvoidExportBuffer)
{
ANDExportStruct strExport;
strExport.dwStructID = dwStructType;
strExport.dwStructureVersion = dwStructVersion;
strExport.dwDataSize = dwDataSize;
strExport.dwIndex = 0; // What is this?
WMR_MEMCPY(pvoidExportBuffer, &strExport, sizeof(ANDExportStruct));
}
}
else if (pdwBufferSize)
{
*pdwBufferSize = 0;
}
DUMP_VAR(boolResult);
return boolResult;
}
#define SUB_MIN_ZERO(minuend, subtrahend) (((minuend) > (subtrahend)) ? ((minuend) - (subtrahend)) : 0)
BOOL32 ANDExportAllStructs(void * pvoidDataBuffer, UInt32 * pdwDataSize)
{
UInt32 idx;
ExportStructParameters *nextStruct;
const UInt32 dwNumStructures = sizeof(astrStructsToExport) / sizeof(astrStructsToExport[0]);
const UInt32 dwBufferSize = pdwDataSize ? *pdwDataSize : 0;
UInt8 *cursor = (UInt8*) pvoidDataBuffer;
UInt32 dwBufferRead = 0;
UInt32 dwTmpStructSize;
if (!pdwDataSize)
{
return FALSE32;
}
// Update globals
stVflFunctions = WMR_PPN_GetVFL();
stFtlFunctions = WMR_PPN_GetFTL();
nextStruct = &astrStructsToExport[0];
for (idx = 0; idx < dwNumStructures; ++idx)
{
dwTmpStructSize = SUB_MIN_ZERO(dwBufferSize, dwBufferRead);
_appendStructToBuffer(cursor,
&dwTmpStructSize,
nextStruct->dwStructLayer,
nextStruct->dwStructType,
nextStruct->dwStructVersion);
nextStruct++;
if (cursor)
{
cursor += dwTmpStructSize;
}
dwBufferRead += dwTmpStructSize;
}
if (pdwDataSize)
{
*pdwDataSize = dwBufferRead;
}
// pdwDataSize tells the whole story, always pass
return TRUE32;
}
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2008-2009 Apple Inc. All rights reserved.
*
* This document is the property of Apple Inc.
* It is considered confidential and proprietary.
*
* This document may not be reproduced or transmitted in any form,
* in whole or in part, without the express written permission of
* Apple Inc.
*/
#include "WMRTypes.h"
#ifndef _ANDSTATS_H_
#define _ANDSTATS_H_
BOOL32 ANDExportAllStructs(void * pvoidDataBuffer, UInt32 * pdwDataSize);
#endif //_ANDSTATS_H_
@@ -0,0 +1,28 @@
// Copyright (C) 2010 Apple Inc. All rights reserved.
//
// This document is the property of Apple Inc.
// It is considered confidential and proprietary.
//
// This document may not be reproduced or transmitted in any form,
// in whole or in part, without the express written permission of
// Apple Inc.
#include "WhimoryBoot.h"
#include "WhimoryBootTypes.h"
#include "FTL.h"
#include "VFL.h"
Boot_FTL_Registry_t g_ftl_registry[] =
{
{ SFTL_PPN_MAJOR_VER, SFTL_PPN_Register },
{ YAFTL_PPN_MAJOR_VER, YAFTL_PPN_Register },
{ 0, NULL },
};
Boot_VFL_Registry_t g_vfl_registry[] =
{
{ PPN_SVFL_MAJOR_VER, PPN_SVFL_GetFunctions },
{ PPN_VFL_MAJOR_VER, PPN_VFL_GetFunctions },
{ 0, NULL },
};
@@ -0,0 +1,26 @@
// Copyright (C) 2010 Apple Inc. All rights reserved.
//
// This document is the property of Apple Inc.
// It is considered confidential and proprietary.
//
// This document may not be reproduced or transmitted in any form,
// in whole or in part, without the express written permission of
// Apple Inc.
#include "WhimoryBoot.h"
#include "WhimoryBootTypes.h"
#include "FTL.h"
#include "VFL.h"
Boot_FTL_Registry_t g_ftl_registry[] =
{
{ SFTL_PPN_MAJOR_VER, SFTL_PPN_Register },
{ 0, NULL },
};
Boot_VFL_Registry_t g_vfl_registry[] =
{
{ PPN_SVFL_MAJOR_VER, PPN_SVFL_GetFunctions },
{ 0, NULL },
};
@@ -0,0 +1,26 @@
// Copyright (C) 2010 Apple Inc. All rights reserved.
//
// This document is the property of Apple Inc.
// It is considered confidential and proprietary.
//
// This document may not be reproduced or transmitted in any form,
// in whole or in part, without the express written permission of
// Apple Inc.
#include "WhimoryBoot.h"
#include "WhimoryBootTypes.h"
#include "FTL.h"
#include "VFL.h"
Boot_FTL_Registry_t g_ftl_registry[] =
{
{ YAFTL_PPN_MAJOR_VER, YAFTL_PPN_Register },
{ 0, NULL },
};
Boot_VFL_Registry_t g_vfl_registry[] =
{
{ PPN_VFL_MAJOR_VER, PPN_VFL_GetFunctions },
{ 0, NULL },
};
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,208 @@
// Copyright (C) 2010 Apple Inc. All rights reserved.
//
// This document is the property of Apple Inc.
// It is considered confidential and proprietary.
//
// This document may not be reproduced or transmitted in any form,
// in whole or in part, without the express written permission of
// Apple Inc.
//
//
#ifndef _WHIMORY_BOOT_H_
#define _WHIMORY_BOOT_H_
#include "WMRTypes.h"
#include "FTL.h"
#include "VFL.h"
#include "FPart.h"
#ifdef __cplusplus
extern "C" {
#endif //__cplusplus
////////////////////////////////////////////////////////////////////////////////
// Public structure definitions
////////////////////////////////////////////////////////////////////////////////
typedef enum _WhimoryBootCode
{
kWhimoryOk = 0,
kWhimoryWarning = (1 << 29),
kWhimoryWarningUnformatted,
kWhimoryEpochMismatch_Deprecated,
kWhimoryMinorVersionMismatch,
kWhimoryMajorVersionNotAvailable,
kWhimoryBirthVersionTooNew,
kWhimoryError = (1 << 30),
kWhimoryErrMissingHardware,
kWhimoryErrOutOfMemory,
kWhimoryErrUnsupportedVersion,
kWhimoryErrSetup,
kWhimoryErrUnitTestFailed,
kWhimoryErrCorruptedFormat,
} WhimoryBootCode;
#define kWhimoryBootOptionLowPower (1 << 0)
#define kWhimoryBootOptionForceFtlRecovery (1 << 1)
#define kWhimoryBootOptionFreshOffFTLFormat (1 << 2)
#define kWhimoryBootOptionDisableGCInTrim (1 << 3)
#define kWhimorySetIndexCacheSize (1 << 4)
#define kWhimoryBootOptionReadOnly (1 << 16) // Must align with WMR_INIT_OPEN_READONLY @ bit 16.
////////////////////////////////////////////////////////////////////////////////
// Public function declarations
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// WMR_Start
//
// WMR_Start will attempt to locate a signature. It will call OAM_Init()
// and FIL_Init(), so those fuctions should be idempotent.
// Possible non-fatal outcomes:
// kWhimoryWarningUnformatted - Run WMR_Initial_Format()
//
// On kWhimoryOk or warnings, callers can request WMR_PPN_GetFPart()
//
////////////////////////////////////////////////////////////////////////////////
WhimoryBootCode
WMR_Start
(UInt32 fpart_major_ver,
UInt32 fpart_options,
UInt32 boot_options);
////////////////////////////////////////////////////////////////////////////////
// WMR_Open
//
// WMR_Open will open a block device if the media is properly formatted
// and return appropriate warnings if the device needs to be formatted or
// repaired.
//
////////////////////////////////////////////////////////////////////////////////
WhimoryBootCode
WMR_Open
(UInt32 *total_sectors,
UInt32 *sector_size,
UInt32 *index_cache,
UInt32 boot_options);
////////////////////////////////////////////////////////////////////////////////
// WMR_Format
//
// Format the media with a given set of preferred versions
//
////////////////////////////////////////////////////////////////////////////////
WhimoryBootCode
WMR_Initial_Format
(UInt32 fpart_major_ver,
UInt32 fpart_options,
UInt32 fpart_format_options,
UInt32 vfl_major_ver,
UInt32 vfl_options,
UInt32 ftl_major_ver,
UInt32 ftl_options,
UInt32 num_keepout_blocks,
UInt32 megabytes_for_ftl);
////////////////////////////////////////////////////////////////////////////////
// WMR_Partition
//
// Re-size the portion of the VFL that is visible to FTL.
// A value of 0 gives the entire media to FTL.
//
////////////////////////////////////////////////////////////////////////////////
WhimoryBootCode
WMR_Partition
(UInt32 megabytes_for_ftl);
////////////////////////////////////////////////////////////////////////////////
// WMR_Update
//
// Update the physical format if newer format is supported by this software.
// Optionally require backward compatiblity and saving user data
//
////////////////////////////////////////////////////////////////////////////////
WhimoryBootCode
WMR_Update
(const BOOL32 keep_backward_compatibility,
const BOOL32 save_data,
UInt32 vfl_major_ver,
UInt32 vfl_options,
UInt32 ftl_major_ver,
UInt32 ftl_options,
UInt32 num_keepout_blocks);
////////////////////////////////////////////////////////////////////////////////
// WMR_Close
//
// Gracefully shut down the block device, deallocate all buffers, and return
// static variables to initial state such that WMR_Open can be called again.
//
////////////////////////////////////////////////////////////////////////////////
void
WMR_Close
(void);
////////////////////////////////////////////////////////////////////////////////
// WMR_PPN_CtrlIO
//
// Generic IOCtl interface to all layers of whimory. Caller must specifiy data
// buffer size in incoming size pointer.
//
////////////////////////////////////////////////////////////////////////////////
BOOL32
WMR_PPN_CtrlIO
(UInt32 ctrlio_type,
void *data,
UInt32 *size);
////////////////////////////////////////////////////////////////////////////////
// WMR_PPNGetStruct
//
// Get a parameter from RAM
//
////////////////////////////////////////////////////////////////////////////////
BOOL32
WMR_PPNGetStruct
(UInt32 ctrlio_type,
void *data,
UInt32 *size);
////////////////////////////////////////////////////////////////////////////////
// WMR_PPNGetCurrentSignature
//
// Get the signature representing the current software state
//
////////////////////////////////////////////////////////////////////////////////
const struct WhimorySignature *
WMR_PPNGetSignature
(void);
////////////////////////////////////////////////////////////////////////////////
// Accessors
//
// Get a parameter from RAM
//
////////////////////////////////////////////////////////////////////////////////
FTLFunctions *WMR_PPN_GetFTL
(void);
VFLFunctions *WMR_PPN_GetVFL
(void);
FPartFunctions *WMR_PPN_GetFPart
(void);
#ifdef __cplusplus
}
#endif //__cplusplus
#endif //_WHIMORY_BOOT_H_
@@ -0,0 +1,78 @@
// Copyright (C) 2010 Apple Inc. All rights reserved.
//
// This document is the property of Apple Inc.
// It is considered confidential and proprietary.
//
// This document may not be reproduced or transmitted in any form,
// in whole or in part, without the express written permission of
// Apple Inc.
//
//
#ifndef _WHIMORY_BOOT_TYPES_H_
#define _WHIMORY_BOOT_TYPES_H_
#define WHIMORY_SIGNATURE_SIZE (3 * 512)
struct WhimorySignature
{
UInt32 magic;
#define WHIMORY_SIGNATURE_MAGIC (0x776D7278) // 'wmrx'
UInt32 _deprecated_epoch; // 0 for new devices
UInt32 whimory_ver_at_birth; // SW older than birth epoch may not open this drive
#define WHIMORY_SIGNATURE_VER_PPN_CUR (6)
UInt32 ftl_major_ver;
UInt32 ftl_minor_ver;
UInt32 ftl_options;
UInt32 vfl_major_ver;
UInt32 vfl_minor_ver;
UInt32 vfl_options;
UInt32 fpart_major_ver;
UInt32 fpart_minor_ver;
UInt32 fpart_options; // debug-only: need these to find signature
UInt32 num_keepout_blocks;
UInt32 num_chip_enables;
// Informational
#define WHIMORY_SW_VER_MAX_LENGTH (128)
UInt8 sw_ver_str[WHIMORY_SW_VER_MAX_LENGTH];
UInt32 fpart_format_options; // options used for initial format
#define WHIMORY_FTL_PARTITION_VALID_BIT (1UL << 31)
#define WHIMORY_FTL_PARTITION_SIZE_MASK (0x7fffffffUL)
UInt32 megabytes_for_ftl;
// Reserve to 1.5KB
UInt8 reserved[WHIMORY_SIGNATURE_SIZE - (16 * sizeof(UInt32)) - 128];
};
struct WhimoryDeviceInfo
{
UInt32 num_ce;
UInt32 main_bytes_per_page;
UInt32 total_meta_per_page;
UInt32 lba_per_page;
};
typedef FTLFunctions * (*FTL_Registrar)(void);
typedef struct
{
UInt32 major_ver;
FTL_Registrar registrar;
} Boot_FTL_Registry_t;
typedef VFLFunctions * (*VFL_Registrar)(void);
typedef struct
{
UInt32 major_ver;
VFL_Registrar registrar;
} Boot_VFL_Registry_t;
typedef FPartFunctions * (*FPart_Registrar)(void);
typedef struct
{
UInt32 major_ver;
FPart_Registrar registrar;
} Boot_FPart_Registry_t;
#endif //_WHIMORY_BOOT_TYPES_H_