2018-02-19 08:41:19 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2018-02-24 15:25:38 +00:00
|
|
|
#include "bootconfig.h"
|
2018-02-19 08:41:19 +00:00
|
|
|
#include "configitem.h"
|
2018-02-24 20:46:57 +00:00
|
|
|
#include "interrupt.h"
|
|
|
|
#include "package2.h"
|
|
|
|
#include "se.h"
|
2018-02-25 19:00:50 +00:00
|
|
|
#include "fuse.h"
|
2018-02-24 20:46:57 +00:00
|
|
|
#include "utils.h"
|
2018-02-19 08:41:19 +00:00
|
|
|
|
2018-02-26 10:00:02 +00:00
|
|
|
static bool g_battery_profile = false;
|
2018-02-19 08:41:19 +00:00
|
|
|
|
|
|
|
uint32_t configitem_set(enum ConfigItem item, uint64_t value) {
|
|
|
|
if (item != CONFIGITEM_BATTERYPROFILE) {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2018-02-26 10:00:02 +00:00
|
|
|
g_battery_profile = (value != 0);
|
|
|
|
return 0;
|
2018-02-19 08:41:19 +00:00
|
|
|
}
|
|
|
|
|
2018-02-23 03:58:39 +00:00
|
|
|
bool configitem_is_recovery_boot(void) {
|
2018-02-20 09:02:01 +00:00
|
|
|
uint64_t is_recovery_boot;
|
|
|
|
if (configitem_get(CONFIGITEM_ISRECOVERYBOOT, &is_recovery_boot) != 0) {
|
2018-02-24 14:20:45 +00:00
|
|
|
generic_panic();
|
2018-02-20 09:02:01 +00:00
|
|
|
}
|
2018-02-23 03:58:39 +00:00
|
|
|
|
|
|
|
return is_recovery_boot != 0;
|
2018-02-20 09:02:01 +00:00
|
|
|
}
|
|
|
|
|
2018-02-25 09:21:52 +00:00
|
|
|
bool configitem_is_retail(void) {
|
|
|
|
uint64_t is_retail;
|
|
|
|
if (configitem_get(CONFIGITEM_ISRETAIL, &is_retail) != 0) {
|
|
|
|
generic_panic();
|
|
|
|
}
|
|
|
|
|
|
|
|
return is_retail != 0;
|
|
|
|
}
|
|
|
|
|
2018-02-26 10:00:02 +00:00
|
|
|
bool configitem_should_profile_battery(void) {
|
|
|
|
return g_battery_profile;
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:16:30 +00:00
|
|
|
uint64_t configitem_get_hardware_type(void) {
|
|
|
|
uint64_t hardware_type;
|
|
|
|
if (configitem_get(CONFIGITEM_HARDWARETYPE, &hardware_type) != 0) {
|
|
|
|
generic_panic();
|
|
|
|
}
|
|
|
|
return hardware_type;
|
|
|
|
}
|
|
|
|
|
2018-02-19 08:41:19 +00:00
|
|
|
uint32_t configitem_get(enum ConfigItem item, uint64_t *p_outvalue) {
|
|
|
|
uint32_t result = 0;
|
|
|
|
switch (item) {
|
|
|
|
case CONFIGITEM_DISABLEPROGRAMVERIFICATION:
|
2018-02-24 15:25:38 +00:00
|
|
|
*p_outvalue = (int)(bootconfig_disable_program_verification());
|
2018-02-19 08:41:19 +00:00
|
|
|
break;
|
2018-02-25 09:21:52 +00:00
|
|
|
case CONFIGITEM_DRAMID:
|
|
|
|
*p_outvalue = fuse_get_dram_id();
|
2018-02-19 08:41:19 +00:00
|
|
|
break;
|
|
|
|
case CONFIGITEM_SECURITYENGINEIRQ:
|
2018-02-24 15:25:38 +00:00
|
|
|
/* SE is interrupt #0x2C. */
|
|
|
|
*p_outvalue = INTERRUPT_ID_USER_SECURITY_ENGINE;
|
2018-02-19 08:41:19 +00:00
|
|
|
break;
|
2018-02-24 20:46:57 +00:00
|
|
|
case CONFIGITEM_VERSION:
|
2018-02-24 15:25:38 +00:00
|
|
|
/* Always returns maxver - 1 on hardware. */
|
|
|
|
*p_outvalue = PACKAGE2_MAXVER_400_CURRENT - 1;
|
2018-02-19 08:41:19 +00:00
|
|
|
break;
|
|
|
|
case CONFIGITEM_HARDWARETYPE:
|
2018-02-25 09:21:52 +00:00
|
|
|
*p_outvalue = fuse_get_hardware_type();
|
2018-02-19 08:41:19 +00:00
|
|
|
break;
|
|
|
|
case CONFIGITEM_ISRETAIL:
|
2018-02-25 09:21:52 +00:00
|
|
|
*p_outvalue = fuse_get_retail_type();
|
2018-02-19 08:41:19 +00:00
|
|
|
break;
|
|
|
|
case CONFIGITEM_ISRECOVERYBOOT:
|
2018-02-24 15:25:38 +00:00
|
|
|
/* TODO: This requires reading values passed to crt0 via NX_Bootloader. TBD pending crt0 implementation. */
|
2018-02-19 08:41:19 +00:00
|
|
|
*p_outvalue = 0;
|
|
|
|
break;
|
|
|
|
case CONFIGITEM_DEVICEID:
|
2018-02-25 09:21:52 +00:00
|
|
|
*p_outvalue = fuse_get_device_id();
|
2018-02-19 08:41:19 +00:00
|
|
|
break;
|
|
|
|
case CONFIGITEM_BOOTREASON:
|
|
|
|
/* TODO: This requires reading values passed to crt0 via NX_Bootloader. TBD pending crt0 implementation. */
|
|
|
|
break;
|
|
|
|
case CONFIGITEM_MEMORYARRANGE:
|
2018-02-25 09:21:52 +00:00
|
|
|
*p_outvalue = bootconfig_get_memory_arrangement();
|
2018-02-19 08:41:19 +00:00
|
|
|
break;
|
|
|
|
case CONFIGITEM_ISDEBUGMODE:
|
2018-02-25 09:21:52 +00:00
|
|
|
*p_outvalue = (int)(bootconfig_is_debug_mode());
|
2018-02-19 08:41:19 +00:00
|
|
|
break;
|
|
|
|
case CONFIGITEM_KERNELMEMORYCONFIGURATION:
|
2018-02-25 09:21:52 +00:00
|
|
|
*p_outvalue = bootconfig_get_kernel_memory_configuration();
|
2018-02-19 08:41:19 +00:00
|
|
|
break;
|
|
|
|
case CONFIGITEM_BATTERYPROFILE:
|
2018-02-26 10:00:02 +00:00
|
|
|
*p_outvalue = (int)g_battery_profile;
|
2018-02-19 08:41:19 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|