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,98 @@
/*
* Copyright (c) 2010-11 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 _APPLE_EFFACEABLE_STORAGE_FORMAT_H
#define _APPLE_EFFACEABLE_STORAGE_FORMAT_H
// =============================================================================
#include <stdint.h>
// =============================================================================
#define kAppleEffaceableStorageMagic 'Face'
#define kAppleEffaceableStorageGenerationUnknown ((uint32_t)0x00000000)
#define kAppleEffaceableStorageGenerationInitial ((uint32_t)0x00000001)
#define kAppleEffaceableStorageGenerationInvalid ((uint32_t)0xFFFFFFFF)
#define kAppleEffaceableStorageVersionMajorUnknown ((uint32_t)0x00000000)
#define kAppleEffaceableStorageVersionMajorInitial ((uint32_t)0x00000001)
#define kAppleEffaceableStorageVersionMajorNonce ((uint32_t)0x00000001)
#define kAppleEffaceableStorageVersionMajorCurrent kAppleEffaceableStorageVersionMajorNonce
#define kAppleEffaceableStorageVersionMajorInvalid ((uint32_t)0xFFFFFFFF)
#define kAppleEffaceableStorageVersionMinorUnknown ((uint32_t)0x00000000)
#define kAppleEffaceableStorageVersionMinorInitial ((uint32_t)0x00000001)
#define kAppleEffaceableStorageVersionMinorNonce ((uint32_t)0x00000002)
#define kAppleEffaceableStorageVersionMinorCurrent kAppleEffaceableStorageVersionMajorNonce
#define kAppleEffaceableStorageVersionMinorInvalid ((uint32_t)0xFFFFFFFF)
#define kAppleEffaceableStorageFlagsNone ((uint32_t)0x00000000)
#define kAppleEffaceableStorageSize 1024
#define kAppleEffaceableStorageSaltSize 16
#define kAppleEffaceableStorageReservedSize 24
#define kAppleEffaceableStorageContentSize (kAppleEffaceableStorageSize - sizeof(AppleEffaceableStorageHeader))
#define kAppleEffaceableStorageLockerBase 0
#define kAppleEffaceableStorageLockerSize (kAppleEffaceableStorageContentSize - kAppleEffaceableStorageLockerBase)
// =============================================================================
// All structures defined here are on-media formats.
typedef struct
{
uint32_t magic;
uint32_t version_major;
uint32_t version_minor;
uint32_t flags;
} __attribute__((__packed__)) AppleEffaceableStorageNaked;
typedef struct
{
uint8_t reserved[kAppleEffaceableStorageReservedSize];
uint32_t generation;
uint32_t checksum;
} __attribute__((__packed__)) AppleEffaceableStorageVeiled;
typedef struct
{
AppleEffaceableStorageNaked naked;
uint8_t salt[kAppleEffaceableStorageSaltSize];
AppleEffaceableStorageVeiled veiled;
} __attribute__((__packed__)) AppleEffaceableStorageHeader;
typedef struct
{
AppleEffaceableStorageHeader header;
uint8_t content[kAppleEffaceableStorageContentSize];
} __attribute__((__packed__)) AppleEffaceableStorageClone;
typedef struct
{
uint16_t magic;
uint16_t data_size;
uint32_t type_id;
} __attribute__((__packed__)) AppleEffaceableStorageLockerHeader;
#define kAppleEffaceableStorageLockerMagic 0x4c6b // 'Lk'
#define kAppleEffaceableStorageLockerSentinel 'DONE'
// =============================================================================
#endif /* _APPLE_EFFACEABLE_STORAGE_FORMAT_H */
@@ -0,0 +1,130 @@
/*
* Copyright (c) 2010-11 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 _APPLE_EFFACEABLE_STORAGE_KEYS_H
#define _APPLE_EFFACEABLE_STORAGE_KEYS_H
__BEGIN_DECLS
// =============================================================================
// callPlatformFunction methods
//
// GetLocker
// Returns the contents of the locker type_id, if it exists.
//
// SetLocker
// Updates or creates the locker type_id.
//
// Space
// Returns the largest amount of data that could be stored in a locker
// with type_id, accounting for overwriting any current value.
//
// Efface
// Destroys the locker type_id and all its contents.
//
// GenerateNonce
// Populate private nonce locker with random 64-bit value and return its hash.
//
// type_id
// Unique identifier for the locker. Typically a four-byte ASCII value.
//
// data
// Pointer to read/write data buffer.
//
// data_size
// Buffer/operation size in bytes. Note that for GetLocker this is a
// pointer to an IOByteCount that is updated to the actual size of the
// locker, and for Space this is the amount of space available for
// a locker with type_id.
//
// untrusted
// True if the client is untrusted and should not be allowed to operate
// on protected lockers.
//
// hash
// Pointer to 20 byte buffer into which the nonce hash will be copied.
//
#define kAppleEffaceableStorageFunctionGet "GetLocker" // (type_id, *data, *data_size, untrusted)
#define kAppleEffaceableStorageFunctionSet "SetLocker" // (type_id, *data, data_size, untrusted)
#define kAppleEffaceableStorageFunctionEfface "EffaceLocker" // (type_id, untrusted)
#define kAppleEffaceableStorageFunctionGenerateNonce "GenerateNonce" // (*hash)
#define kAppleEffaceableStorageFunctionSpace "Space" // (type_id, *free_size)
// When set on a request's type_id, the locker can only be read, overwritten and
// effaced by a kernel client. Cannot be set by a user client.
#define kAppleEffaceableStorageLockerProtected (1<<31)
// Special type for manipulating nonce locker, which is permitted
// only by the effaceable storage driver
#define kAppleEffaceableStorageLockerPrivate (1<<23)
// These bits must not be set in a locker's type_id.
#define kAppleEffaceableStorageLockerReserved ((1<<15) | (1<<7))
// This type_id is considered a wildcard; passed to Efface it will cause
// every locker to be effaced.
#define kAppleEffaceableStorageLockerWildcard '****'
// =============================================================================
#define kAppleEffaceableStorageClassName "AppleEffaceableStorage"
// DeviceTree properties
#define kAppleEffaceableStoragePropertyVersionMajor "VersionMajor"
#define kAppleEffaceableStoragePropertyVersionMinor "VersionMinor"
#define kAppleEffaceableStoragePropertyIsFormatted "IsFormatted"
// UserClient methods
enum _AppleEffaceableStorageMethod
{
// Maintenance interface.
kAppleEffaceableStorageMethodGetCapacity,
kAppleEffaceableStorageMethodGetBytes,
kAppleEffaceableStorageMethodSetBytes,
kAppleEffaceableStorageMethodIsFormatted,
kAppleEffaceableStorageMethodFormatStorage,
// Userclient locker methods.
//
// The type_id argument is always passed in scalarInput[0].
//
// GetLocker returns the actual size of the locker in scalarOutput[0],
// and if structureOutput/structureOutputSize describe a buffer, as much
// of the locker data as will fit is returned into the buffer.
//
// SetLocker creates or replaces an existing locker with the contents of
// structureInput/structureInputSize.
//
// EffaceLocker destroys the locker.
//
kAppleEffaceableStorageMethodGetLocker,
kAppleEffaceableStorageMethodSetLocker,
kAppleEffaceableStorageMethodEffaceLocker,
kAppleEffaceableStorageMethodSpace,
// Debug-only interface.
kAppleEffaceableStorageMethodWipeStorage,
// Nonce support
kAppleEffaceableStorageMethodGenerateNonce,
kAppleEffaceableStorageMethodCount
};
typedef enum _AppleEffaceableStorageMethod AppleEffaceableStorageMethod;
// =============================================================================
__END_DECLS
#endif /* _APPLE_EFFACEABLE_STORAGE_KEYS_H */
@@ -0,0 +1,184 @@
/*
* Copyright (c) 2011 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 _EFFACEABLE_CONTRACT_H_
#define _EFFACEABLE_CONTRACT_H_
// =============================================================================
#include <sys/types.h>
#include <stdarg.h>
/* horrible that this is necessary */
#ifndef __cplusplus
# ifndef false
# include <stdbool.h>
# endif
#endif
// =============================================================================
enum _EffaceableReturn
{
kEffaceableReturnSuccess = 0,
kEffaceableReturnError,
kEffaceableReturnNotFound,
kEffaceableReturnUnsupported,
kEffaceableReturnNotPrivileged,
kEffaceableReturnNotPermitted,
kEffaceableReturnBadArgument,
kEffaceableReturnBadMedia,
kEffaceableReturnUnformattedMedia,
kEffaceableReturnIOError,
kEffaceableReturnNoMemory,
kEffaceableReturnNoSpace,
kEffaceableReturnInternalError,
kEffaceableReturnInvalid
};
typedef enum _EffaceableReturn EffaceableReturn;
// =============================================================================
struct _effaceable_storage;
struct _effaceable_device;
struct _effaceable_system;
struct _effaceable_nor_hal;
struct _effaceable_nand_hal;
// -----------------------------------------------------------------------------
typedef struct _effaceable_storage effaceable_storage_t;
typedef struct _effaceable_device effaceable_device_t;
typedef struct _effaceable_system effaceable_system_t;
typedef struct _effaceable_nor_hal effaceable_nor_hal_t;
typedef struct _effaceable_nand_hal effaceable_nand_hal_t;
// =============================================================================
struct _effaceable_storage
{
void * opaque;
/* client api for use externally */
EffaceableReturn (* getLocker )(effaceable_storage_t * storage, uint32_t type_id, void *data, uint32_t *data_size, bool untrusted);
EffaceableReturn (* setLocker )(effaceable_storage_t * storage, uint32_t type_id, const void *data, uint32_t data_size, bool untrusted);
EffaceableReturn (* spaceForLocker )(effaceable_storage_t * storage, uint32_t type_id, uint32_t *data_space);
EffaceableReturn (* effaceLocker )(effaceable_storage_t * storage, uint32_t type_id, bool untrusted);
EffaceableReturn (* generateNonce )(effaceable_storage_t * storage, void * hash);
EffaceableReturn (* consumeNonce )(effaceable_storage_t * storage, uint64_t * nonce);
/* management api for use externally */
EffaceableReturn (* getBytes )(effaceable_storage_t * storage, void * client_buf, uint32_t offset, uint32_t count);
EffaceableReturn (* wipeStorage )(effaceable_storage_t * storage, void * tmp_buf);
uint32_t (* getCapacity )(effaceable_storage_t * storage);
bool (* isFormatted )(effaceable_storage_t * storage);
EffaceableReturn (* formatStorage )(effaceable_storage_t * storage);
/* spi for use by device-specific controller */
uint32_t (* getCopiesPerUnit )(effaceable_storage_t * storage);
uint32_t (* getCopySize )(effaceable_storage_t * storage);
};
// -----------------------------------------------------------------------------
struct _effaceable_device
{
void * opaque;
/* device controller must provide concrete implementation of these operations */
uint32_t (* getGroupCount )(effaceable_device_t * device);
uint32_t (* getUnitsPerGroup )(effaceable_device_t * device);
uint32_t (* getUnitSize )(effaceable_device_t * device);
EffaceableReturn (* eraseGroup )(effaceable_device_t * device, uint32_t group);
EffaceableReturn (* writeUnit )(effaceable_device_t * device, const void * buf, uint32_t group, uint32_t unit);
EffaceableReturn (* readUnit )(effaceable_device_t * device, void * buf, uint32_t group, uint32_t unit);
/* device controller may optionally extend these device; if NULL, code should not call */
void (* cleanBuffers )(effaceable_device_t * device);
void (* foundCurrentCloneInGroup )(effaceable_device_t * device, uint32_t group);
void (* updateDynamicProperties )(effaceable_device_t * device);
};
// -----------------------------------------------------------------------------
struct _effaceable_system
{
void * opaque;
/* operating system specific operations must be supplied when starting device */
void * (* allocMem )(effaceable_system_t * system, uint32_t size);
void (* freeMem )(effaceable_system_t * system, void * buf, uint32_t size);
void * (* setMem )(effaceable_system_t * system, void * buf, uint8_t val, uint32_t size);
void * (* moveMem )(effaceable_system_t * system, void * dst, const void * src, uint32_t size);
int (* cmpMem )(effaceable_system_t * system, const void * lhs, const void * rhs, uint32_t size);
void (* readRandom )(effaceable_system_t * system, void * buf, uint32_t size);
void (* calcSHA1 )(effaceable_system_t * system, const void * buf, uint32_t size, void * hash);
uint32_t (* crc32 )(effaceable_system_t * system, uint32_t crc, const void * buf, uint32_t size, bool finish);
bool (* setProperty )(effaceable_system_t * system, const char * key, uint32_t value);
void (* panicSys )(effaceable_system_t * system, const char * msg);
int (* vlogf )(effaceable_system_t * system, const char * fmt, va_list ap);
};
// -----------------------------------------------------------------------------
/* contract for NOR HAL operations */
struct _effaceable_nor_hal
{
void * opaque;
/* NOR HAL operations must be supplied when starting device */
uint32_t (* getRegionCount )(effaceable_nor_hal_t * nor);
uint32_t (* getRegionSize )(effaceable_nor_hal_t * nor, uint32_t index);
EffaceableReturn (* eraseRegion )(effaceable_nor_hal_t * nor, uint32_t index, uint32_t length);
uint32_t (* writeRegion )(effaceable_nor_hal_t * nor, uint32_t index, const void * buf, uint32_t length);
bool (* readRegion )(effaceable_nor_hal_t * nor, uint32_t index, void * buf, uint32_t length);
};
// -----------------------------------------------------------------------------
/* contract for NAND HAL operations */
struct _effaceable_nand_hal
{
void * opaque;
/* NAND HAL operations must be supplied when starting device */
uint32_t (* getPageSize )(effaceable_nand_hal_t * nand);
uint32_t (* getPageCount )(effaceable_nand_hal_t * nand);
uint32_t (* getBlockCount )(effaceable_nand_hal_t * nand);
uint32_t (* getBankCount )(effaceable_nand_hal_t * nand);
bool (* isBlockBad )(effaceable_nand_hal_t * nand, uint32_t bank, uint32_t block);
EffaceableReturn (* eraseBlock )(effaceable_nand_hal_t * nand, uint32_t bank, uint32_t block);
EffaceableReturn (* writePage )(effaceable_nand_hal_t * nand, uint32_t bank, uint32_t block, uint32_t page, const void * buf, uint32_t length);
EffaceableReturn (* readPage )(effaceable_nand_hal_t * nand, uint32_t bank, uint32_t block, uint32_t page, void * buf, uint32_t length);
bool (* requestPartitionTableDiff )(effaceable_nand_hal_t * nand, void * buf, uint32_t length);
bool (* providePartitionTableDiff )(effaceable_nand_hal_t * nand, void * buf, uint32_t length);
};
// =============================================================================
__BEGIN_DECLS
// -----------------------------------------------------------------------------
extern void startEffaceableNOR(effaceable_device_t * device, effaceable_system_t * system, effaceable_nor_hal_t * nor, effaceable_storage_t * storage);
extern void startEffaceableNAND(effaceable_device_t * device, effaceable_system_t * system, effaceable_nand_hal_t * nor, effaceable_storage_t * storage);
// -----------------------------------------------------------------------------
__END_DECLS
// =============================================================================
#endif /* _EFFACEABLE_CONTRACT_H_ */
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2011 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 _EFFACEABLE_DEBUG_H_
#define _EFFACEABLE_DEBUG_H_
// =============================================================================
#define EFFACEABLE_DBGMSK_INIT (1<<0)
#define EFFACEABLE_DBGMSK_ERR (1<<1)
#define EFFACEABLE_DBGMSK_WARN (1<<2)
#define EFFACEABLE_DBGMSK_INFO (1<<3)
#define EFFACEABLE_DBGMSK_SPEW (1<<4)
// -----------------------------------------------------------------------------
#define EFFACEABLE_DBGTAG_INIT "INIT"
#define EFFACEABLE_DBGTAG_ERR "ERR "
#define EFFACEABLE_DBGTAG_WARN "WARN"
#define EFFACEABLE_DBGTAG_INFO "INFO"
#define EFFACEABLE_DBGTAG_SPEW "SPEW"
// -----------------------------------------------------------------------------
#define EFFACEABLE_DEBUG_ALL (EFFACEABLE_DBGMSK_INIT | \
EFFACEABLE_DBGMSK_ERR | \
EFFACEABLE_DBGMSK_WARN | \
EFFACEABLE_DBGMSK_INFO | \
EFFACEABLE_DBGMSK_SPEW)
#define EFFACEABLE_DEBUG_MOST (EFFACEABLE_DBGMSK_INIT | \
EFFACEABLE_DBGMSK_ERR | \
EFFACEABLE_DBGMSK_WARN | \
EFFACEABLE_DBGMSK_INFO)
#define EFFACEABLE_DEBUG_DEFAULT (EFFACEABLE_DBGMSK_INIT | \
EFFACEABLE_DBGMSK_ERR)
// -----------------------------------------------------------------------------
#define EFFACEABLE_DEBUG EFFACEABLE_DEBUG_DEFAULT
// -----------------------------------------------------------------------------
#if defined(EFFACEABLE_DEBUG) && EFFACEABLE_DEBUG
# define dlogf(_api, _fac, _fmt, ...) \
do { \
if (EFFACEABLE_DBGMSK_##_fac & \
EFFACEABLE_DEBUG) { \
logf(_api, "[effaceable:%s] " _fmt "\n", \
EFFACEABLE_DBGTAG_##_fac , \
## __VA_ARGS__ ); \
} \
} while(0)
# define dhexdump(_api, _fac, _buf, _count) \
do { \
if (EFFACEABLE_DBGMSK_##_fac & \
EFFACEABLE_DEBUG) { \
unsigned _i, _j; \
for (_i = 0; _i < _count; _i += 16) { \
logf(_api, "[effaceable:%s] 0x%08x:", \
EFFACEABLE_DBGTAG_##_fac , \
((unsigned) _buf) + _i); \
for (_j = 0; (_j < 16) && ((_i + _j) < _count); _j++) \
logf(_api, " %2.2x", ((uint8_t*)_buf)[_i + _j]); \
logf(_api, "\n"); \
} \
} \
} while(0)
#else
# define dlogf(...) do { /* nothing */ } while(0)
# define dhexdump(...) do { /* nothing */ } while(0)
#endif
// =============================================================================
#endif /* _EFFACEABLE_DEBUG_H_ */