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

+376
View File
@@ -0,0 +1,376 @@
/*
* Copyright (C) 2012 Apple Inc. All rights reserved.
*
* This document is the property of Apple Computer, 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.
*/
#define ASP_TARGET_RTXC 1
#define CASSERT(x, name) typedef char __ASP_CASSERT_##name[(x) ? 1 : -1]
#include <stdint.h>
#include <csi_ipc_protocol.h>
#include <csi_platform_defines.h>
#include <arch.h>
#include <aspcore_mbox.h>
#include <aspcore_protocol.h>
#include <debug.h>
#include <drivers/asp.h>
#include <drivers/csi.h>
#include <lib/env.h>
#include <lib/heap.h>
#include <lib/partition.h>
#include <platform.h>
#include <stdio.h>
#include <sys.h>
#include <sys/menu.h>
#include <target/aspnandconfig.h>
#if !SUPPORT_FPGA
#include <target/powerconfig.h>
#endif
#include "common_util.h"
//
// Defines
//
#define MY_ASP_PROTOCOL_VERSION 10
CASSERT(ASP_PROTOCOL_VERSION == MY_ASP_PROTOCOL_VERSION, protocol_versions_match);
//
// Prototypes
//
static bool asp_get_nand_info(void);
//
// Globals
//
asp_t asp;
aspproto_nand_geom_t nand_info;
struct blockdev *asp_nand_dev;
struct blockdev *asp_nvram_dev;
struct blockdev *asp_firmware_dev;
struct blockdev *asp_llb_dev;
struct blockdev *asp_effaceable_dev;
struct blockdev *asp_syscfg_dev;
struct blockdev *asp_paniclog_dev;
static int asp_set_atv(void)
{
aspproto_cmd_t * command;
command = asp_get_cmd_for_tag(ASP_TAG_GENERIC);
command->op = ASPPROTO_CMD_SETOPTIONS;
command->opts.isATV = true;
if ((asp_send_command(command->tag) != ASPPROTO_CMD_STATUS_SUCCESS)){
dprintf(DEBUG_CRITICAL, "Unable to set atv mode\n");
return -1;
}
return 0;
}
int asp_init(void)
{
csi_status_t result;
asp.state = ASP_STATE_INITIALIZING;
asp.writable = false;
asp_nand_dev = NULL;
asp_nvram_dev = NULL;
asp_firmware_dev = NULL;
asp_llb_dev = NULL;
asp_effaceable_dev = NULL;
asp_syscfg_dev = NULL;
asp_paniclog_dev = NULL;
event_init(&asp.msg_event, EVENT_FLAG_AUTO_UNSIGNAL, false);
result = csi_register_endpoint(CSI_COPROC_ANS, IPC_ENDPOINT_ASP, &asp.msg_event, &asp.csi_token, &asp.ep_name);
if (result != CSI_STATUS_OK)
{
asp.state = ASP_STATE_ERROR_CRITICAL;
dprintf(DEBUG_CRITICAL, "Failed to register ASP endpoint");
return -1;
}
#if !ASP_ENABLE_TIMEOUTS
dprintf(DEBUG_CRITICAL, "ASP Timeouts disabled!\n");
#endif
if (!asp_wait_for_ready())
{
asp.state = ASP_STATE_ERROR_CRITICAL;
return -1;
}
if (!asp_init_tags())
{
asp.state = ASP_STATE_ERROR_CRITICAL;
return -1;
}
if (!asp_get_geometry())
{
// need to create dummy NVRAM device anyways to prevet iBoot panic
asp_create_block_device(ASP_NVRAM);
asp.state = ASP_STATE_ERROR_NOT_REGISTERED;
return -1;
}
if (!asp_get_nand_info())
{
dprintf(DEBUG_CRITICAL, "asp_get_nand_info failed\n");
}
asp_reinit();
if (!asp_create_block_device(ASP_NVRAM))
{
asp.state = ASP_STATE_ERROR_NOT_REGISTERED;
return -1;
}
#if TARGET_POWER_NO_BATTERY
if (asp_set_atv() != 0) {
return -1;
}
#endif
asp_create_block_device(ASP_FIRMWARE);
asp_create_block_device(ASP_LLB);
asp_create_block_device(ASP_EFFACEABLE);
asp_create_block_device(ASP_SYSCFG);
asp_create_block_device(ASP_PANICLOG);
asp.state = ASP_STATE_READY;
return 0;
}
bool asp_wait_for_ready(void)
{
msg_payload_t msg;
uint32_t tag;
csi_status_t result;
#if ASP_ENABLE_TIMEOUTS
if (!event_wait_timeout(&asp.msg_event, ASP_READY_TIMEOUT_US))
{
dprintf(DEBUG_CRITICAL, "ASP timed out waiting for hardware to become ready!");
asp.state = ASP_STATE_TIMEOUT;
return false;
}
#else
event_wait(&asp.msg_event);
#endif
result = csi_receive_message(asp.csi_token, &msg);
if (result != CSI_STATUS_OK)
{
return false;
}
tag = ASPMBOX_FIN_GET_TAG(msg);
if (tag != ASPMBOX_TAG_AWAKE)
{
return false;
}
else
{
if (ASPMBOX_FIN_GET_ERRCODE(msg) != ASP_PROTOCOL_VERSION)
{
dprintf(DEBUG_CRITICAL, "iBoot ASP protocol version %d aspcore protocol version %lld",
ASP_PROTOCOL_VERSION, ASPMBOX_FIN_GET_ERRCODE(msg));
return false;
}
}
return true;
}
bool asp_init_tags(void)
{
addr_t paddr;
uint64_t payload;
uint32_t i;
asp.asp_command = csi_allocate_shared_memory(asp.csi_token,
ASP_NUM_TAGS * ASPPROTO_CMD_LINES * CACHELINE_BYTES);
if (!asp.asp_command)
{
dprintf(DEBUG_CRITICAL, "Unable to allocate ASP command memory");
asp.asp_command = NULL;
return false;
}
paddr = mem_static_map_physical((addr_t)asp.asp_command);
payload = ASPMBOX_MAKE_CMD_SETBASE((uint64_t)paddr, ASP_NUM_TAGS * ASPPROTO_CMD_LINES);
dprintf(DEBUG_CRITICAL, "Using paddr %p, setbase message 0x%016llx\n", (void *)paddr, payload);
if (csi_send_message(asp.csi_token, payload) != CSI_STATUS_OK)
{
dprintf(DEBUG_CRITICAL, "Unable to send ASPMBOX_MASK_CMD_SETBASE message\n");
return false;
}
for (i = 0; i < ASP_NUM_TAGS; i++)
{
aspproto_cmd_t *cmd;
payload = ASPMBOX_MAKE_CMD_SETADDR(i, (i * ASPPROTO_CMD_LINES), ASPPROTO_CMD_LINES);
if (csi_send_message(asp.csi_token, payload) != CSI_STATUS_OK)
{
dprintf(DEBUG_CRITICAL, "Unable to send ASPMBOX_MAKE_CMD_SETADDR message\n");
return false;
}
cmd = asp_get_cmd_for_tag(i);
cmd->tag = i;
}
return true;
}
static bool asp_get_nand_info(void)
{
aspproto_cmd_t * command = asp_get_cmd_for_tag(ASP_TAG_GENERIC);
command->op = ASP_PROTO_CMD_DEVICE_INFO;
if (asp_send_command(command->tag) != ASPPROTO_CMD_STATUS_SUCCESS)
{
dprintf(DEBUG_CRITICAL, "Unable to read ASP device info\n");
return false;
}
if(command->nand_info.size > sizeof(nand_info))
{
panic ("nand info size exceeded\n");
}
memcpy(&nand_info, command->nand_info.data, command->nand_info.size);
return true;
}
bool asp_send_open(void)
{
aspproto_cmd_t * command = asp_get_cmd_for_tag(ASP_TAG_GENERIC);
int status;
command->op = ASPPROTO_CMD_OPEN;
status = asp_send_command(command->tag);
if (status != ASPPROTO_CMD_STATUS_SUCCESS)
{
dprintf(DEBUG_CRITICAL, "Unable to open ASP: 0x%08x\n", status);
return false;
}
return true;
}
int asp_nand_open(void)
{
if (asp.state != ASP_STATE_READY)
{
return -1;
}
if (!asp_send_open())
{
return -1;
}
// NOTE: Need to get NAND geometry again after sending an OPEN
// command to ASP to ensure that the lbaFormatted field is
// correctly updated after CLOG replay
if (!asp_get_geometry())
{
asp.state = ASP_STATE_ERROR_NOT_REGISTERED;
return -1;
}
if (!asp_create_block_device(ASP_NAND))
{
asp.state = ASP_STATE_ERROR_NOT_REGISTERED;
return -1;
}
partition_scan_and_publish_subdevices("asp_nand");
return 0;
}
int asp_set_default_dies_in_parallel(void)
{
asp_set_dies_in_parallel(ASPNAND_SLC_WRITE_DIES_IN_PARALLEL,
ASPNAND_READ_DIES_IN_PARALLEL,
ASPNAND_ERASE_DIES_IN_PARALLEL,
ASPNAND_MLC_WRITE_DIES_IN_PARALLEL,
ASPNAND_TLC_SLC_WRITE_DIES_IN_PARALLEL,
ASPNAND_TLC_READ_DIES_IN_PARALLEL,
ASPNAND_TLC_ERASE_DIES_IN_PARALLEL,
ASPNAND_TLC_TLC_WRITE_DIES_IN_PARALLEL,
CORE_POWERSTATE_HIGH_POWER);
asp_set_dies_in_parallel(ASPNAND_SLC_WRITE_LOW_POWER_DIES_IN_PARALLEL,
ASPNAND_READ_LOW_POWER_DIES_IN_PARALLEL,
ASPNAND_ERASE_LOW_POWER_DIES_IN_PARALLEL,
ASPNAND_MLC_WRITE_LOW_POWER_DIES_IN_PARALLEL,
ASPNAND_TLC_SLC_WRITE_LOW_POWER_DIES_IN_PARALLEL,
ASPNAND_TLC_READ_LOW_POWER_DIES_IN_PARALLEL,
ASPNAND_TLC_ERASE_LOW_POWER_DIES_IN_PARALLEL,
ASPNAND_TLC_TLC_WRITE_LOW_POWER_DIES_IN_PARALLEL,
CORE_POWERSTATE_LOW_POWER);
asp_set_power_state(CORE_POWERSTATE_HIGH_POWER);
return 0;
}
int asp_disable_uid(void)
{
aspproto_cmd_t * command = asp_get_cmd_for_tag(ASP_TAG_GENERIC);
command->op = ASPPROTO_CMD_NAND_DEBUG;
command->tunnel.opcode = NAND_DEBUG_DISABLE_UID;
command->tunnel.buffer_paddr = 0;
command->tunnel.bufferLen = 0;
command->tunnel.options.mask = (1 << ANC_MAX_BUSSES) - 1;
dprintf(DEBUG_CRITICAL, "Disabling ANS UID keys\n");
if (asp_send_command(command->tag) != ASPPROTO_CMD_STATUS_SUCCESS)
{
dprintf(DEBUG_CRITICAL, "Failed to disable UID keys\n");
return -1;
}
return 0;
}
File diff suppressed because it is too large. Load diff
+186
View File
@@ -0,0 +1,186 @@
/*
* 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 __common_util_h__
#define __common_util_h__
//#define ASP_ENABLE_NEURALIZE 1
#define ASP_ENABLE_WRITES 0
#if !SUPPORT_FPGA
#define ASP_ENABLE_TIMEOUTS 1
#else
#define ASP_ENABLE_TIMEOUTS 0
#endif
#define ASP_READY_TIMEOUT_US (90 * 1000 * 1000)
#define ASP_IO_TIMEOUT_US (90 * 1000 * 1000)
typedef struct
{
csi_coproc_t coproc;
struct task_event msg_event;
void * csi_token;
void * asp_command;
uint32_t num_lbas;
uint32_t bytes_per_lba;
bool lba_formatted;
bool util_formatted;
int state;
bool writable;
const char * ep_name;
uint32_t lastUserBand;
uint32_t lastBand;
uint32_t numVirtualSLCBonfireBands;
uint32_t firstIntermediateBand;
uint32_t lastIntermediateBand;
uint8_t chip_id[ANC_MAX_BUSSES][ANC_NAND_ID_SIZE];
uint8_t mfg_id[ANC_MAX_BUSSES][ANC_NAND_ID_SIZE];
} asp_t;
enum
{
ASP_TAG_GENERIC = 0,
ASP_TAG_NAND,
ASP_TAG_NVRAM,
ASP_TAG_FIRMWARE,
ASP_TAG_LLB,
ASP_TAG_EFFACEABLE,
ASP_TAG_SYSCFG,
ASP_TAG_PANICLOG,
ASP_NUM_TAGS
};
//
// Definitions
//
enum
{
ASP_NAND_BLKSZ = (4 * 1024),
ASP_NVRAM_BLKSZ = (8 * 1024),
ASP_FIRMWARE_BLKSZ = (4 * 1024),
ASP_LLB_BLKSZ = (4 * 1024),
ASP_EFFACEABLE_BLKSZ = (4 * 1024),
ASP_SYSCFG_BLKSZ = (8 * 1024),
ASP_PANICLOG_BLKSZ = (4 * 1024),
};
enum
{
ASP_NAND_NUMBLKS = 0, // For general NAND, size should be looked up from geometry
ASP_NVRAM_NUMBLKS = 1,
ASP_FIRMWARE_NUMBLKS = 2048,
#if defined (ASP_LLB_OVERRIDE_NUM_BLKS)
ASP_LLB_NUMBLKS = ASP_LLB_OVERRIDE_NUM_BLKS,
# else
ASP_LLB_NUMBLKS = 253,
#endif
ASP_EFFACEABLE_NUMBLKS = 1,
ASP_SYSCFG_NUMBLKS = 18,
ASP_PANICLOG_NUMBLKS = 256,
};
enum
{
ASP_NAND = 1,
ASP_NVRAM,
ASP_FIRMWARE,
ASP_LLB,
ASP_EFFACEABLE,
ASP_SYSCFG,
ASP_PANICLOG,
};
enum
{
ASP_STATE_INITIALIZING = 0,
ASP_STATE_INITIALIZED,
ASP_STATE_READY,
ASP_STATE_TIMEOUT,
ASP_STATE_ERROR_NOT_REGISTERED,
ASP_STATE_ERROR_NOT_WRITABLE,
ASP_STATE_ERROR_NEURALIZE,
ASP_STATE_ERROR_INVALID_PPNFW,
ASP_STATE_ERROR_CRITICAL,
ASP_STATE_PANIC_RECOVERY,
};
enum
{
ASP_FORMAT_UTIL,
ASP_FORMAT_LBA,
ASP_FORMAT_ALL,
};
#define MAX_SGL_ENTRIES (512)
//Calculate number of cache lines needed for the command and round them up
#define ASPPROTO_CMD_LINES ((((MAX_SGL_ENTRIES * sizeof(uint32_t)) + sizeof(aspproto_cmd_t))/CACHELINE_BYTES) + 1)
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) < (b)) ? (b) : (a))
#define ASP_NAND_BLK_ALIGN_SHIFT (12)
#define ASP_NAND_BLK_ALIGNMENT (1 << ASP_NAND_BLK_ALIGN_SHIFT)
#define VADDR_TO_PADDR32(buffer) (mem_static_map_physical((addr_t)(buffer)) >> ASP_NAND_BLK_ALIGN_SHIFT)
#define ALIGN_UP(val, n) ((((val) + (n) - 1) / (n)) * (n))
int asp_send_command(uint32_t tag);
int asp_wait_for_completion(uint32_t tag);
bool asp_set_writable(void);
bool asp_get_geometry(void);
bool asp_create_block_device(uint8_t type);
bool asp_set_dies_in_parallel(uint32_t mlc_slc_write_dies,
uint32_t mlc_read_dies,
uint32_t mlc_erase_dies,
uint32_t mlc_write_dies,
uint32_t tlc_slc_write_dies,
uint32_t tlc_read_dies,
uint32_t tlc_erase_dies,
uint32_t tlc_tlc_write_dies,
CorePowerState_e power_level);
bool asp_set_power_state(CorePowerState_e powerState);
bool asp_set_indirection_memory(uint32_t indirection_memory, uint32_t legacy_memory);
bool asp_test_scratchpad(void);
#if !RELEASE_BUILD && WITH_MENU
int asp_update_ppn_firmware(const void *fw_buffer, size_t fw_length);
#endif // #if !RELEASE_BUILD && WITH_MENU
aspproto_cmd_t * asp_get_cmd_for_tag(uint32_t tag);
int asp_read_block(struct blockdev *_dev, void *ptr, block_addr block, uint32_t count);
int asp_write_block(struct blockdev *_dev, const void *ptr, block_addr block, uint32_t count);
#if !RELEASE_BUILD
int asp_erase_block(struct blockdev * _dev, off_t offset, uint64_t len);
#endif
bool asp_sync(void);
int asp_type_from_blkdev (struct blockdev *device);
struct blockdev * asp_get_blkdev_for_type (int type);
int asp_set_blkdev_for_type (int type, struct blockdev * device);
bool asp_set_photoflow_mode(core_flow_mode_e slc_mode);
bool asp_enable_bg(void);
bool asp_disable_bg(void);
bool asp_send_open(void);
int asp_panic_recover(void);
bool asp_init_tags(void);
void asp_reinit(void);
bool asp_wait_for_ready(void);
#if defined(ASP_ENABLE_NEURALIZE) && ASP_ENABLE_NEURALIZE
bool asp_neuralize(void);
#endif // ASP_ENABLE_NEURALIZE
#endif // __common_util_h__
File diff suppressed because it is too large. Load diff
+23
View File
@@ -0,0 +1,23 @@
# 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.
#
LOCAL_DIR := $(GET_LOCAL_DIR)
GLOBAL_INCLUDES += $(LOCAL_DIR)/include \
$(DSTROOT)/usr/local/standalone/firmware \
$(SDKROOT)/../../../usr/local/standalone/firmware
ALL_OBJS += \
$(LOCAL_DIR)/asp.o \
$(LOCAL_DIR)/debug.o \
$(LOCAL_DIR)/common_util.o
OPTIONS += \
WITH_HW_ASP=1 \
WITH_NAND_BOOT=1