diff --git a/exosphere/src/configitem.c b/exosphere/src/configitem.c
index de33c4e98..2dbadc38e 100644
--- a/exosphere/src/configitem.c
+++ b/exosphere/src/configitem.c
@@ -187,11 +187,10 @@ uint32_t configitem_get(bool privileged, ConfigItem item, uint64_t *p_outvalue)
*p_outvalue = INTERRUPT_ID_USER_SECURITY_ENGINE;
break;
case CONFIGITEM_VERSION:
- /* Always returns maxver - 1 on hardware. */
- *p_outvalue = PACKAGE2_MAXVER_400_410 - 1;
+ *p_outvalue = fuse_get_expected_fuse_version(exosphere_get_target_firmware());
break;
case CONFIGITEM_HARDWARETYPE:
- *p_outvalue = fuse_get_hardware_type(mkey_get_revision());
+ *p_outvalue = fuse_get_hardware_type(exosphere_get_target_firmware());
break;
case CONFIGITEM_ISRETAIL:
*p_outvalue = fuse_get_retail_type();
diff --git a/exosphere/src/fuse.c b/exosphere/src/fuse.c
index 3fe86e24e..62372bc77 100644
--- a/exosphere/src/fuse.c
+++ b/exosphere/src/fuse.c
@@ -13,8 +13,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#include
+#include
#include "car.h"
#include "fuse.h"
@@ -36,7 +37,7 @@ void fuse_init(void) {
clkrst_enable_fuse_regs(true);
fuse_disable_private_key();
fuse_disable_programming();
-
+
/* TODO: Should we allow this to be done later? */
if (!g_has_checked_for_rcm_bug_patch) {
(void)(fuse_has_rcm_bug_patch());
@@ -127,7 +128,7 @@ void fuse_hw_sense(void) {
ctrl_val &= ~0x3;
ctrl_val |= 0x3; /* Set SENSE_CTRL command */
FUSE_REGS->FUSE_FUSECTRL = ctrl_val;
-
+
/* Wait for idle state. */
fuse_wait_idle();
}
@@ -173,37 +174,38 @@ uint64_t fuse_get_device_id(void) {
uint64_t wafer_id = FUSE_CHIP_REGS->FUSE_OPT_WAFER_ID & 0x3F;
uint32_t lot_code = FUSE_CHIP_REGS->FUSE_OPT_LOT_CODE_0;
uint64_t fab_code = FUSE_CHIP_REGS->FUSE_OPT_FAB_CODE & 0x3F;
-
+
uint64_t derived_lot_code = 0;
for (unsigned int i = 0; i < 5; i++) {
derived_lot_code = (derived_lot_code * 0x24) + ((lot_code >> (24 - 6*i)) & 0x3F);
}
derived_lot_code &= 0x03FFFFFF;
-
+
device_id |= y_coord << 0;
device_id |= x_coord << 9;
device_id |= wafer_id << 18;
device_id |= derived_lot_code << 24;
device_id |= fab_code << 50;
-
+
return device_id;
}
/* Derive the Hardware Type using values in the shadow cache. */
-uint32_t fuse_get_hardware_type(uint32_t mkey_rev) {
+uint32_t fuse_get_hardware_type(uint32_t target_firmware) {
uint32_t fuse_reserved_odm4 = fuse_get_reserved_odm(4);
uint32_t hardware_type = (((fuse_reserved_odm4 >> 7) & 2) | ((fuse_reserved_odm4 >> 2) & 1));
-
+
/* Firmware from versions 1.0.0 to 3.0.2. */
- if (mkey_rev < 0x03) {
+ if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_400) {
+ volatile tegra_fuse_chip_t *fuse_chip = fuse_chip_get_regs();
if (hardware_type >= 1) {
return (hardware_type > 2) ? 3 : hardware_type - 1;
- } else if ((FUSE_CHIP_REGS->FUSE_SPARE_BIT[9] & 1) == 0) {
+ } else if ((fuse_chip->FUSE_SPARE_BIT[9] & 1) == 0) {
return 0;
} else {
return 3;
}
- } else if ((mkey_rev >= 0x03) && (mkey_rev < 0x07)) { /* Firmware versions from 4.0.0 to 6.2.0. */
+ } else if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_700) { /* Firmware versions from 4.0.0 to 6.2.0. */
static const uint32_t types[] = {0,1,4,3};
hardware_type |= ((fuse_reserved_odm4 >> 14) & 0x3C);
hardware_type--;
@@ -258,6 +260,31 @@ uint32_t fuse_get_5x_key_generation(void) {
}
}
+/* Returns the fuse version expected for the firmware. */
+uint32_t fuse_get_expected_fuse_version(uint32_t target_firmware) {
+ static const uint8_t expected_versions[ATMOSPHERE_TARGET_FIRMWARE_COUNT+1] = {
+ [ATMOSPHERE_TARGET_FIRMWARE_100] = 1,
+ [ATMOSPHERE_TARGET_FIRMWARE_200] = 2,
+ [ATMOSPHERE_TARGET_FIRMWARE_300] = 3,
+ /* [ATMOSPHERE_TARGET_FIRMWARE_302] = 4, */
+ [ATMOSPHERE_TARGET_FIRMWARE_400] = 5,
+ [ATMOSPHERE_TARGET_FIRMWARE_500] = 6,
+ [ATMOSPHERE_TARGET_FIRMWARE_600] = 7,
+ [ATMOSPHERE_TARGET_FIRMWARE_620] = 8,
+ [ATMOSPHERE_TARGET_FIRMWARE_700] = 9,
+ [ATMOSPHERE_TARGET_FIRMWARE_800] = 9,
+ [ATMOSPHERE_TARGET_FIRMWARE_810] = 10,
+ [ATMOSPHERE_TARGET_FIRMWARE_900] = 11,
+ [ATMOSPHERE_TARGET_FIRMWARE_910] = 12,
+ };
+
+ if (target_firmware >= ATMOSPHERE_TARGET_FIRMWARE_COUNT) {
+ generic_panic();
+ }
+
+ return expected_versions[target_firmware];
+}
+
/* Check for RCM bug patches. */
bool fuse_has_rcm_bug_patch(void) {
/* Only check for RCM bug patch once, and cache our result. */
diff --git a/exosphere/src/fuse.h b/exosphere/src/fuse.h
index 7f5353bb7..daafd4a11 100644
--- a/exosphere/src/fuse.h
+++ b/exosphere/src/fuse.h
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#ifndef EXOSPHERE_FUSE_H
#define EXOSPHERE_FUSE_H
@@ -218,7 +218,7 @@ uint32_t fuse_get_reserved_odm(uint32_t idx);
uint32_t fuse_get_bootrom_patch_version(void);
uint64_t fuse_get_device_id(void);
uint32_t fuse_get_dram_id(void);
-uint32_t fuse_get_hardware_type(uint32_t mkey_rev);
+uint32_t fuse_get_hardware_type(uint32_t target_firmware);
uint32_t fuse_get_retail_type(void);
void fuse_get_hardware_info(void *dst);
uint32_t fuse_get_5x_key_generation(void);
@@ -228,4 +228,7 @@ uint32_t fuse_hw_read(uint32_t addr);
void fuse_hw_write(uint32_t value, uint32_t addr);
void fuse_hw_sense(void);
+
+uint32_t fuse_get_expected_fuse_version(uint32_t target_firmware);
+
#endif
diff --git a/fusee/fusee-mtc/Makefile b/fusee/fusee-mtc/Makefile
index defdef18e..b594079df 100644
--- a/fusee/fusee-mtc/Makefile
+++ b/fusee/fusee-mtc/Makefile
@@ -29,7 +29,7 @@ TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := src src/lib src/display
DATA := data
-INCLUDES := include
+INCLUDES := include ../../libraries/libvapours/include
#---------------------------------------------------------------------------------
# options for code generation
diff --git a/fusee/fusee-mtc/src/fuse.c b/fusee/fusee-mtc/src/fuse.c
index 4d4c948fb..b17ea65fb 100644
--- a/fusee/fusee-mtc/src/fuse.c
+++ b/fusee/fusee-mtc/src/fuse.c
@@ -13,10 +13,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#include
#include
#include
+#include
#include "car.h"
#include "fuse.h"
@@ -79,7 +80,7 @@ void fuse_wait_idle(void) {
/* Read a fuse from the hardware array. */
uint32_t fuse_hw_read(uint32_t addr) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -101,7 +102,7 @@ uint32_t fuse_hw_read(uint32_t addr) {
/* Write a fuse in the hardware array. */
void fuse_hw_write(uint32_t value, uint32_t addr) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -122,7 +123,7 @@ void fuse_hw_write(uint32_t value, uint32_t addr) {
/* Sense the fuse hardware array into the shadow cache. */
void fuse_hw_sense(void) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -131,7 +132,7 @@ void fuse_hw_sense(void) {
ctrl_val &= ~0x3;
ctrl_val |= 0x3; /* Set SENSE_CTRL command */
fuse->FUSE_FUSECTRL = ctrl_val;
-
+
/* Wait for idle state. */
fuse_wait_idle();
}
@@ -176,36 +177,36 @@ uint32_t fuse_get_dram_id(void) {
/* Derive the Device ID using values in the shadow cache. */
uint64_t fuse_get_device_id(void) {
volatile tegra_fuse_chip_t *fuse_chip = fuse_chip_get_regs();
-
+
uint64_t device_id = 0;
uint64_t y_coord = fuse_chip->FUSE_OPT_Y_COORDINATE & 0x1FF;
uint64_t x_coord = fuse_chip->FUSE_OPT_X_COORDINATE & 0x1FF;
uint64_t wafer_id = fuse_chip->FUSE_OPT_WAFER_ID & 0x3F;
uint32_t lot_code = fuse_chip->FUSE_OPT_LOT_CODE_0;
uint64_t fab_code = fuse_chip->FUSE_OPT_FAB_CODE & 0x3F;
-
+
uint64_t derived_lot_code = 0;
for (unsigned int i = 0; i < 5; i++) {
derived_lot_code = (derived_lot_code * 0x24) + ((lot_code >> (24 - 6*i)) & 0x3F);
}
derived_lot_code &= 0x03FFFFFF;
-
+
device_id |= y_coord << 0;
device_id |= x_coord << 9;
device_id |= wafer_id << 18;
device_id |= derived_lot_code << 24;
device_id |= fab_code << 50;
-
+
return device_id;
}
/* Derive the Hardware Type using values in the shadow cache. */
-uint32_t fuse_get_hardware_type(uint32_t mkey_rev) {
+uint32_t fuse_get_hardware_type(uint32_t target_firmware) {
uint32_t fuse_reserved_odm4 = fuse_get_reserved_odm(4);
uint32_t hardware_type = (((fuse_reserved_odm4 >> 7) & 2) | ((fuse_reserved_odm4 >> 2) & 1));
-
+
/* Firmware from versions 1.0.0 to 3.0.2. */
- if (mkey_rev < 0x03) {
+ if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_400) {
volatile tegra_fuse_chip_t *fuse_chip = fuse_chip_get_regs();
if (hardware_type >= 1) {
return (hardware_type > 2) ? 3 : hardware_type - 1;
@@ -214,7 +215,7 @@ uint32_t fuse_get_hardware_type(uint32_t mkey_rev) {
} else {
return 3;
}
- } else if ((mkey_rev >= 0x03) && (mkey_rev < 0x07)) { /* Firmware versions from 4.0.0 to 6.2.0. */
+ } else if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_700) { /* Firmware versions from 4.0.0 to 6.2.0. */
static const uint32_t types[] = {0,1,4,3};
hardware_type |= ((fuse_reserved_odm4 >> 14) & 0x3C);
hardware_type--;
diff --git a/fusee/fusee-mtc/src/fuse.h b/fusee/fusee-mtc/src/fuse.h
index d118b53dc..5dae093c3 100644
--- a/fusee/fusee-mtc/src/fuse.h
+++ b/fusee/fusee-mtc/src/fuse.h
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#ifndef FUSEE_FUSE_H
#define FUSEE_FUSE_H
@@ -216,7 +216,7 @@ uint32_t fuse_get_reserved_odm(uint32_t idx);
uint32_t fuse_get_bootrom_patch_version(void);
uint64_t fuse_get_device_id(void);
uint32_t fuse_get_dram_id(void);
-uint32_t fuse_get_hardware_type(uint32_t mkey_rev);
+uint32_t fuse_get_hardware_type(uint32_t target_firmware);
uint32_t fuse_get_retail_type(void);
void fuse_get_hardware_info(void *dst);
diff --git a/fusee/fusee-primary/Makefile b/fusee/fusee-primary/Makefile
index 107b32f55..98fa93e81 100644
--- a/fusee/fusee-primary/Makefile
+++ b/fusee/fusee-primary/Makefile
@@ -29,7 +29,7 @@ TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := src src/sdmmc src/lib src/lib/fatfs src/display
DATA := data
-INCLUDES := include ../../common/include
+INCLUDES := include ../../libraries/libvapours/include
#---------------------------------------------------------------------------------
# options for code generation
diff --git a/fusee/fusee-primary/src/fuse.c b/fusee/fusee-primary/src/fuse.c
index dc0d2b41f..9bf733967 100644
--- a/fusee/fusee-primary/src/fuse.c
+++ b/fusee/fusee-primary/src/fuse.c
@@ -13,10 +13,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#include
#include
#include
+#include
#include "car.h"
#include "fuse.h"
@@ -79,7 +80,7 @@ void fuse_wait_idle(void) {
/* Read a fuse from the hardware array. */
uint32_t fuse_hw_read(uint32_t addr) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -101,7 +102,7 @@ uint32_t fuse_hw_read(uint32_t addr) {
/* Write a fuse in the hardware array. */
void fuse_hw_write(uint32_t value, uint32_t addr) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -122,7 +123,7 @@ void fuse_hw_write(uint32_t value, uint32_t addr) {
/* Sense the fuse hardware array into the shadow cache. */
void fuse_hw_sense(void) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -131,7 +132,7 @@ void fuse_hw_sense(void) {
ctrl_val &= ~0x3;
ctrl_val |= 0x3; /* Set SENSE_CTRL command */
fuse->FUSE_FUSECTRL = ctrl_val;
-
+
/* Wait for idle state. */
fuse_wait_idle();
}
@@ -176,36 +177,36 @@ uint32_t fuse_get_dram_id(void) {
/* Derive the Device ID using values in the shadow cache. */
uint64_t fuse_get_device_id(void) {
volatile tegra_fuse_chip_t *fuse_chip = fuse_chip_get_regs();
-
+
uint64_t device_id = 0;
uint64_t y_coord = fuse_chip->FUSE_OPT_Y_COORDINATE & 0x1FF;
uint64_t x_coord = fuse_chip->FUSE_OPT_X_COORDINATE & 0x1FF;
uint64_t wafer_id = fuse_chip->FUSE_OPT_WAFER_ID & 0x3F;
uint32_t lot_code = fuse_chip->FUSE_OPT_LOT_CODE_0;
uint64_t fab_code = fuse_chip->FUSE_OPT_FAB_CODE & 0x3F;
-
+
uint64_t derived_lot_code = 0;
for (unsigned int i = 0; i < 5; i++) {
derived_lot_code = (derived_lot_code * 0x24) + ((lot_code >> (24 - 6*i)) & 0x3F);
}
derived_lot_code &= 0x03FFFFFF;
-
+
device_id |= y_coord << 0;
device_id |= x_coord << 9;
device_id |= wafer_id << 18;
device_id |= derived_lot_code << 24;
device_id |= fab_code << 50;
-
+
return device_id;
}
/* Derive the Hardware Type using values in the shadow cache. */
-uint32_t fuse_get_hardware_type(uint32_t mkey_rev) {
+uint32_t fuse_get_hardware_type(uint32_t target_firmware) {
uint32_t fuse_reserved_odm4 = fuse_get_reserved_odm(4);
uint32_t hardware_type = (((fuse_reserved_odm4 >> 7) & 2) | ((fuse_reserved_odm4 >> 2) & 1));
-
+
/* Firmware from versions 1.0.0 to 3.0.2. */
- if (mkey_rev < 0x03) {
+ if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_400) {
volatile tegra_fuse_chip_t *fuse_chip = fuse_chip_get_regs();
if (hardware_type >= 1) {
return (hardware_type > 2) ? 3 : hardware_type - 1;
@@ -214,7 +215,7 @@ uint32_t fuse_get_hardware_type(uint32_t mkey_rev) {
} else {
return 3;
}
- } else if ((mkey_rev >= 0x03) && (mkey_rev < 0x07)) { /* Firmware versions from 4.0.0 to 6.2.0. */
+ } else if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_700) { /* Firmware versions from 4.0.0 to 6.2.0. */
static const uint32_t types[] = {0,1,4,3};
hardware_type |= ((fuse_reserved_odm4 >> 14) & 0x3C);
hardware_type--;
diff --git a/fusee/fusee-primary/src/fuse.h b/fusee/fusee-primary/src/fuse.h
index d118b53dc..5dae093c3 100644
--- a/fusee/fusee-primary/src/fuse.h
+++ b/fusee/fusee-primary/src/fuse.h
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#ifndef FUSEE_FUSE_H
#define FUSEE_FUSE_H
@@ -216,7 +216,7 @@ uint32_t fuse_get_reserved_odm(uint32_t idx);
uint32_t fuse_get_bootrom_patch_version(void);
uint64_t fuse_get_device_id(void);
uint32_t fuse_get_dram_id(void);
-uint32_t fuse_get_hardware_type(uint32_t mkey_rev);
+uint32_t fuse_get_hardware_type(uint32_t target_firmware);
uint32_t fuse_get_retail_type(void);
void fuse_get_hardware_info(void *dst);
diff --git a/fusee/fusee-secondary/src/fuse.c b/fusee/fusee-secondary/src/fuse.c
index 4d4c948fb..b17ea65fb 100644
--- a/fusee/fusee-secondary/src/fuse.c
+++ b/fusee/fusee-secondary/src/fuse.c
@@ -13,10 +13,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#include
#include
#include
+#include
#include "car.h"
#include "fuse.h"
@@ -79,7 +80,7 @@ void fuse_wait_idle(void) {
/* Read a fuse from the hardware array. */
uint32_t fuse_hw_read(uint32_t addr) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -101,7 +102,7 @@ uint32_t fuse_hw_read(uint32_t addr) {
/* Write a fuse in the hardware array. */
void fuse_hw_write(uint32_t value, uint32_t addr) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -122,7 +123,7 @@ void fuse_hw_write(uint32_t value, uint32_t addr) {
/* Sense the fuse hardware array into the shadow cache. */
void fuse_hw_sense(void) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -131,7 +132,7 @@ void fuse_hw_sense(void) {
ctrl_val &= ~0x3;
ctrl_val |= 0x3; /* Set SENSE_CTRL command */
fuse->FUSE_FUSECTRL = ctrl_val;
-
+
/* Wait for idle state. */
fuse_wait_idle();
}
@@ -176,36 +177,36 @@ uint32_t fuse_get_dram_id(void) {
/* Derive the Device ID using values in the shadow cache. */
uint64_t fuse_get_device_id(void) {
volatile tegra_fuse_chip_t *fuse_chip = fuse_chip_get_regs();
-
+
uint64_t device_id = 0;
uint64_t y_coord = fuse_chip->FUSE_OPT_Y_COORDINATE & 0x1FF;
uint64_t x_coord = fuse_chip->FUSE_OPT_X_COORDINATE & 0x1FF;
uint64_t wafer_id = fuse_chip->FUSE_OPT_WAFER_ID & 0x3F;
uint32_t lot_code = fuse_chip->FUSE_OPT_LOT_CODE_0;
uint64_t fab_code = fuse_chip->FUSE_OPT_FAB_CODE & 0x3F;
-
+
uint64_t derived_lot_code = 0;
for (unsigned int i = 0; i < 5; i++) {
derived_lot_code = (derived_lot_code * 0x24) + ((lot_code >> (24 - 6*i)) & 0x3F);
}
derived_lot_code &= 0x03FFFFFF;
-
+
device_id |= y_coord << 0;
device_id |= x_coord << 9;
device_id |= wafer_id << 18;
device_id |= derived_lot_code << 24;
device_id |= fab_code << 50;
-
+
return device_id;
}
/* Derive the Hardware Type using values in the shadow cache. */
-uint32_t fuse_get_hardware_type(uint32_t mkey_rev) {
+uint32_t fuse_get_hardware_type(uint32_t target_firmware) {
uint32_t fuse_reserved_odm4 = fuse_get_reserved_odm(4);
uint32_t hardware_type = (((fuse_reserved_odm4 >> 7) & 2) | ((fuse_reserved_odm4 >> 2) & 1));
-
+
/* Firmware from versions 1.0.0 to 3.0.2. */
- if (mkey_rev < 0x03) {
+ if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_400) {
volatile tegra_fuse_chip_t *fuse_chip = fuse_chip_get_regs();
if (hardware_type >= 1) {
return (hardware_type > 2) ? 3 : hardware_type - 1;
@@ -214,7 +215,7 @@ uint32_t fuse_get_hardware_type(uint32_t mkey_rev) {
} else {
return 3;
}
- } else if ((mkey_rev >= 0x03) && (mkey_rev < 0x07)) { /* Firmware versions from 4.0.0 to 6.2.0. */
+ } else if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_700) { /* Firmware versions from 4.0.0 to 6.2.0. */
static const uint32_t types[] = {0,1,4,3};
hardware_type |= ((fuse_reserved_odm4 >> 14) & 0x3C);
hardware_type--;
diff --git a/fusee/fusee-secondary/src/fuse.h b/fusee/fusee-secondary/src/fuse.h
index d118b53dc..5dae093c3 100644
--- a/fusee/fusee-secondary/src/fuse.h
+++ b/fusee/fusee-secondary/src/fuse.h
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#ifndef FUSEE_FUSE_H
#define FUSEE_FUSE_H
@@ -216,7 +216,7 @@ uint32_t fuse_get_reserved_odm(uint32_t idx);
uint32_t fuse_get_bootrom_patch_version(void);
uint64_t fuse_get_device_id(void);
uint32_t fuse_get_dram_id(void);
-uint32_t fuse_get_hardware_type(uint32_t mkey_rev);
+uint32_t fuse_get_hardware_type(uint32_t target_firmware);
uint32_t fuse_get_retail_type(void);
void fuse_get_hardware_info(void *dst);
diff --git a/libraries/libvapours/include/vapours/ams/ams_target_firmware.h b/libraries/libvapours/include/vapours/ams/ams_target_firmware.h
index 09d15a4e1..1e1f7be6f 100644
--- a/libraries/libvapours/include/vapours/ams/ams_target_firmware.h
+++ b/libraries/libvapours/include/vapours/ams/ams_target_firmware.h
@@ -32,3 +32,4 @@
#define ATMOSPHERE_TARGET_FIRMWARE_MIN ATMOSPHERE_TARGET_FIRMWARE_100
#define ATMOSPHERE_TARGET_FIRMWARE_MAX ATMOSPHERE_TARGET_FIRMWARE_CURRENT
+#define ATMOSPHERE_TARGET_FIRMWARE_COUNT ((ATMOSPHERE_TARGET_FIRMWARE_MAX - ATMOSPHERE_TARGET_FIRMWARE_MIN) + 1)
\ No newline at end of file
diff --git a/sept/sept-primary/Makefile b/sept/sept-primary/Makefile
index 96a026436..37de097a2 100644
--- a/sept/sept-primary/Makefile
+++ b/sept/sept-primary/Makefile
@@ -29,7 +29,7 @@ TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := src src/sdmmc src/lib src/lib/fatfs src/display
DATA := data
-INCLUDES := include ../../common/include
+INCLUDES := include ../../libraries/libvapours/include
#---------------------------------------------------------------------------------
# options for code generation
diff --git a/sept/sept-primary/src/fuse.c b/sept/sept-primary/src/fuse.c
index 57120207a..c4decedf1 100644
--- a/sept/sept-primary/src/fuse.c
+++ b/sept/sept-primary/src/fuse.c
@@ -13,10 +13,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#include
#include
#include
+#include
#include "car.h"
#include "fuse.h"
@@ -77,7 +78,7 @@ void fuse_wait_idle(void) {
/* Read a fuse from the hardware array. */
uint32_t fuse_hw_read(uint32_t addr) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -99,7 +100,7 @@ uint32_t fuse_hw_read(uint32_t addr) {
/* Write a fuse in the hardware array. */
void fuse_hw_write(uint32_t value, uint32_t addr) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -120,7 +121,7 @@ void fuse_hw_write(uint32_t value, uint32_t addr) {
/* Sense the fuse hardware array into the shadow cache. */
void fuse_hw_sense(void) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -129,7 +130,7 @@ void fuse_hw_sense(void) {
ctrl_val &= ~0x3;
ctrl_val |= 0x3; /* Set SENSE_CTRL command */
fuse->FUSE_FUSECTRL = ctrl_val;
-
+
/* Wait for idle state. */
fuse_wait_idle();
}
@@ -174,36 +175,36 @@ uint32_t fuse_get_dram_id(void) {
/* Derive the Device ID using values in the shadow cache. */
uint64_t fuse_get_device_id(void) {
volatile tegra_fuse_chip_t *fuse_chip = fuse_chip_get_regs();
-
+
uint64_t device_id = 0;
uint64_t y_coord = fuse_chip->FUSE_OPT_Y_COORDINATE & 0x1FF;
uint64_t x_coord = fuse_chip->FUSE_OPT_X_COORDINATE & 0x1FF;
uint64_t wafer_id = fuse_chip->FUSE_OPT_WAFER_ID & 0x3F;
uint32_t lot_code = fuse_chip->FUSE_OPT_LOT_CODE_0;
uint64_t fab_code = fuse_chip->FUSE_OPT_FAB_CODE & 0x3F;
-
+
uint64_t derived_lot_code = 0;
for (unsigned int i = 0; i < 5; i++) {
derived_lot_code = (derived_lot_code * 0x24) + ((lot_code >> (24 - 6*i)) & 0x3F);
}
derived_lot_code &= 0x03FFFFFF;
-
+
device_id |= y_coord << 0;
device_id |= x_coord << 9;
device_id |= wafer_id << 18;
device_id |= derived_lot_code << 24;
device_id |= fab_code << 50;
-
+
return device_id;
}
/* Derive the Hardware Type using values in the shadow cache. */
-uint32_t fuse_get_hardware_type(uint32_t mkey_rev) {
+uint32_t fuse_get_hardware_type(uint32_t target_firmware) {
uint32_t fuse_reserved_odm4 = fuse_get_reserved_odm(4);
uint32_t hardware_type = (((fuse_reserved_odm4 >> 7) & 2) | ((fuse_reserved_odm4 >> 2) & 1));
-
+
/* Firmware from versions 1.0.0 to 3.0.2. */
- if (mkey_rev < 0x03) {
+ if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_400) {
volatile tegra_fuse_chip_t *fuse_chip = fuse_chip_get_regs();
if (hardware_type >= 1) {
return (hardware_type > 2) ? 3 : hardware_type - 1;
@@ -212,7 +213,7 @@ uint32_t fuse_get_hardware_type(uint32_t mkey_rev) {
} else {
return 3;
}
- } else if ((mkey_rev >= 0x03) && (mkey_rev < 0x07)) { /* Firmware versions from 4.0.0 to 6.2.0. */
+ } else if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_700) { /* Firmware versions from 4.0.0 to 6.2.0. */
static const uint32_t types[] = {0,1,4,3};
hardware_type |= ((fuse_reserved_odm4 >> 14) & 0x3C);
hardware_type--;
diff --git a/sept/sept-primary/src/fuse.h b/sept/sept-primary/src/fuse.h
index d118b53dc..5dae093c3 100644
--- a/sept/sept-primary/src/fuse.h
+++ b/sept/sept-primary/src/fuse.h
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#ifndef FUSEE_FUSE_H
#define FUSEE_FUSE_H
@@ -216,7 +216,7 @@ uint32_t fuse_get_reserved_odm(uint32_t idx);
uint32_t fuse_get_bootrom_patch_version(void);
uint64_t fuse_get_device_id(void);
uint32_t fuse_get_dram_id(void);
-uint32_t fuse_get_hardware_type(uint32_t mkey_rev);
+uint32_t fuse_get_hardware_type(uint32_t target_firmware);
uint32_t fuse_get_retail_type(void);
void fuse_get_hardware_info(void *dst);
diff --git a/sept/sept-secondary/Makefile b/sept/sept-secondary/Makefile
index fbbcac1a3..2bd0362f9 100644
--- a/sept/sept-secondary/Makefile
+++ b/sept/sept-secondary/Makefile
@@ -29,7 +29,7 @@ TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := src src/sdmmc src/lib src/lib/fatfs src/display
DATA := data
-INCLUDES := include ../../common/include
+INCLUDES := include ../../libraries/libvapours/include
#---------------------------------------------------------------------------------
# options for code generation
@@ -143,17 +143,19 @@ clean:
#---------------------------------------------------------------------------------
else
-.PHONY: all $(OUTPUT).bin
+.PHONY: all
DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
-all : $(OUTPUT).enc
+all : $(OUTPUT)_01.enc
-$(OUTPUT).enc : $(OUTPUT).bin
- @python $(TOPDIR)/sept_sign.py $< $@
+$(OUTPUT)_01.enc : $(OUTPUT)_00.enc
+
+$(OUTPUT)_00.enc : $(OUTPUT).bin
+ @python $(TOPDIR)/sept_sign.py $(OUTPUT).bin $(OUTPUT).enc
@echo built ... $(notdir $@)
$(OUTPUT).bin : $(OUTPUT).elf
diff --git a/sept/sept-secondary/src/di.c b/sept/sept-secondary/src/di.c
index 07415ba6c..9f60c9832 100644
--- a/sept/sept-secondary/src/di.c
+++ b/sept/sept-secondary/src/di.c
@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#include
#include "di.h"
@@ -51,13 +51,13 @@ void display_init()
volatile tegra_car_t *car = car_get_regs();
volatile tegra_pmc_t *pmc = pmc_get_regs();
volatile tegra_pinmux_t *pinmux = pinmux_get_regs();
-
+
/* Power on. */
uint8_t val = 0xD0;
i2c_send(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_LDO0_CFG, &val, 1);
val = 0x09;
i2c_send(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_GPIO7, &val, 1);
-
+
/* Enable MIPI CAL, DSI, DISP1, HOST1X, UART_FST_MIPI_CAL, DSIA LP clocks. */
car->rst_dev_h_clr = 0x1010000;
car->clk_enb_h_set = 0x1010000;
@@ -78,31 +78,31 @@ void display_init()
pinmux->lcd_bl_pwm &= ~PINMUX_TRISTATE;
pinmux->lcd_bl_en &= ~PINMUX_TRISTATE;
pinmux->lcd_rst &= ~PINMUX_TRISTATE;
-
+
/* Configure Backlight +-5V GPIOs. */
gpio_configure_mode(GPIO_LCD_BL_P5V, GPIO_MODE_GPIO);
gpio_configure_mode(GPIO_LCD_BL_N5V, GPIO_MODE_GPIO);
gpio_configure_direction(GPIO_LCD_BL_P5V, GPIO_DIRECTION_OUTPUT);
gpio_configure_direction(GPIO_LCD_BL_N5V, GPIO_DIRECTION_OUTPUT);
-
+
/* Enable Backlight +5V. */
- gpio_write(GPIO_LCD_BL_P5V, GPIO_LEVEL_HIGH);
+ gpio_write(GPIO_LCD_BL_P5V, GPIO_LEVEL_HIGH);
udelay(10000);
/* Enable Backlight -5V. */
- gpio_write(GPIO_LCD_BL_N5V, GPIO_LEVEL_HIGH);
+ gpio_write(GPIO_LCD_BL_N5V, GPIO_LEVEL_HIGH);
udelay(10000);
/* Configure Backlight PWM, EN and RST GPIOs. */
gpio_configure_mode(GPIO_LCD_BL_PWM, GPIO_MODE_GPIO);
gpio_configure_mode(GPIO_LCD_BL_EN, GPIO_MODE_GPIO);
- gpio_configure_mode(GPIO_LCD_BL_RST, GPIO_MODE_GPIO);
+ gpio_configure_mode(GPIO_LCD_BL_RST, GPIO_MODE_GPIO);
gpio_configure_direction(GPIO_LCD_BL_PWM, GPIO_DIRECTION_OUTPUT);
gpio_configure_direction(GPIO_LCD_BL_EN, GPIO_DIRECTION_OUTPUT);
gpio_configure_direction(GPIO_LCD_BL_RST, GPIO_DIRECTION_OUTPUT);
-
+
/* Enable Backlight EN. */
gpio_write(GPIO_LCD_BL_EN, GPIO_LEVEL_HIGH);
@@ -114,7 +114,7 @@ void display_init()
exec_cfg((uint32_t *)DSI_BASE, _display_config_3, 60);
udelay(10000);
-
+
/* Enable Backlight RST. */
gpio_write(GPIO_LCD_BL_RST, GPIO_LEVEL_HIGH);
@@ -135,7 +135,7 @@ void display_init()
udelay(5000);
_display_ver = MAKE_DSI_REG(DSI_RD_DATA);
-
+
if (_display_ver == 0x10)
exec_cfg((uint32_t *)DSI_BASE, _display_config_4, 43);
@@ -151,7 +151,7 @@ void display_init()
exec_cfg((uint32_t *)DSI_BASE, _display_config_5, 21);
exec_cfg((uint32_t *)CAR_BASE, _display_config_6, 3);
-
+
MAKE_DI_REG(DC_DISP_DISP_CLOCK_CONTROL) = 4;
exec_cfg((uint32_t *)DSI_BASE, _display_config_7, 10);
@@ -176,10 +176,10 @@ void display_end()
{
volatile tegra_car_t *car = car_get_regs();
volatile tegra_pinmux_t *pinmux = pinmux_get_regs();
-
+
/* Disable Backlight. */
display_backlight(false);
-
+
MAKE_DSI_REG(DSI_VIDEO_MODE_CONTROL) = 1;
MAKE_DSI_REG(DSI_WR_DATA) = 0x2805;
@@ -198,19 +198,19 @@ void display_end()
MAKE_DSI_REG(DSI_TRIGGER) = DSI_TRIGGER_HOST;
udelay(50000);
-
+
/* Disable Backlight RST. */
- gpio_write(GPIO_LCD_BL_RST, GPIO_LEVEL_LOW);
+ gpio_write(GPIO_LCD_BL_RST, GPIO_LEVEL_LOW);
udelay(10000);
-
+
/* Disable Backlight -5V. */
- gpio_write(GPIO_LCD_BL_N5V, GPIO_LEVEL_LOW);
+ gpio_write(GPIO_LCD_BL_N5V, GPIO_LEVEL_LOW);
udelay(10000);
/* Disable Backlight +5V. */
- gpio_write(GPIO_LCD_BL_P5V, GPIO_LEVEL_LOW);
+ gpio_write(GPIO_LCD_BL_P5V, GPIO_LEVEL_LOW);
udelay(10000);
@@ -222,10 +222,10 @@ void display_end()
MAKE_DSI_REG(DSI_PAD_CONTROL_0) = (DSI_PAD_CONTROL_VS1_PULLDN_CLK | DSI_PAD_CONTROL_VS1_PULLDN(0xF) | DSI_PAD_CONTROL_VS1_PDIO_CLK | DSI_PAD_CONTROL_VS1_PDIO(0xF));
MAKE_DSI_REG(DSI_POWER_CONTROL) = 0;
-
+
/* Backlight PWM. */
gpio_configure_mode(GPIO_LCD_BL_PWM, GPIO_MODE_SFIO);
-
+
pinmux->lcd_bl_pwm = ((pinmux->lcd_bl_pwm & ~PINMUX_TRISTATE) | PINMUX_TRISTATE);
pinmux->lcd_bl_pwm = (((pinmux->lcd_bl_pwm >> 2) << 2) | 1);
}
@@ -257,7 +257,7 @@ uint32_t *display_init_framebuffer(void *address)
uint32_t *lfb_addr = (uint32_t *)address;
conf[19].val = (uint32_t)address;
-
+
/* This configures the framebuffer @ address with a resolution of 1280x720 (line stride 768). */
exec_cfg((uint32_t *)DI_BASE, conf, 32);
diff --git a/sept/sept-secondary/src/fuse.c b/sept/sept-secondary/src/fuse.c
index 4d4c948fb..b17ea65fb 100644
--- a/sept/sept-secondary/src/fuse.c
+++ b/sept/sept-secondary/src/fuse.c
@@ -13,10 +13,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#include
#include
#include
+#include
#include "car.h"
#include "fuse.h"
@@ -79,7 +80,7 @@ void fuse_wait_idle(void) {
/* Read a fuse from the hardware array. */
uint32_t fuse_hw_read(uint32_t addr) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -101,7 +102,7 @@ uint32_t fuse_hw_read(uint32_t addr) {
/* Write a fuse in the hardware array. */
void fuse_hw_write(uint32_t value, uint32_t addr) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -122,7 +123,7 @@ void fuse_hw_write(uint32_t value, uint32_t addr) {
/* Sense the fuse hardware array into the shadow cache. */
void fuse_hw_sense(void) {
volatile tegra_fuse_t *fuse = fuse_get_regs();
-
+
/* Wait for idle state. */
fuse_wait_idle();
@@ -131,7 +132,7 @@ void fuse_hw_sense(void) {
ctrl_val &= ~0x3;
ctrl_val |= 0x3; /* Set SENSE_CTRL command */
fuse->FUSE_FUSECTRL = ctrl_val;
-
+
/* Wait for idle state. */
fuse_wait_idle();
}
@@ -176,36 +177,36 @@ uint32_t fuse_get_dram_id(void) {
/* Derive the Device ID using values in the shadow cache. */
uint64_t fuse_get_device_id(void) {
volatile tegra_fuse_chip_t *fuse_chip = fuse_chip_get_regs();
-
+
uint64_t device_id = 0;
uint64_t y_coord = fuse_chip->FUSE_OPT_Y_COORDINATE & 0x1FF;
uint64_t x_coord = fuse_chip->FUSE_OPT_X_COORDINATE & 0x1FF;
uint64_t wafer_id = fuse_chip->FUSE_OPT_WAFER_ID & 0x3F;
uint32_t lot_code = fuse_chip->FUSE_OPT_LOT_CODE_0;
uint64_t fab_code = fuse_chip->FUSE_OPT_FAB_CODE & 0x3F;
-
+
uint64_t derived_lot_code = 0;
for (unsigned int i = 0; i < 5; i++) {
derived_lot_code = (derived_lot_code * 0x24) + ((lot_code >> (24 - 6*i)) & 0x3F);
}
derived_lot_code &= 0x03FFFFFF;
-
+
device_id |= y_coord << 0;
device_id |= x_coord << 9;
device_id |= wafer_id << 18;
device_id |= derived_lot_code << 24;
device_id |= fab_code << 50;
-
+
return device_id;
}
/* Derive the Hardware Type using values in the shadow cache. */
-uint32_t fuse_get_hardware_type(uint32_t mkey_rev) {
+uint32_t fuse_get_hardware_type(uint32_t target_firmware) {
uint32_t fuse_reserved_odm4 = fuse_get_reserved_odm(4);
uint32_t hardware_type = (((fuse_reserved_odm4 >> 7) & 2) | ((fuse_reserved_odm4 >> 2) & 1));
-
+
/* Firmware from versions 1.0.0 to 3.0.2. */
- if (mkey_rev < 0x03) {
+ if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_400) {
volatile tegra_fuse_chip_t *fuse_chip = fuse_chip_get_regs();
if (hardware_type >= 1) {
return (hardware_type > 2) ? 3 : hardware_type - 1;
@@ -214,7 +215,7 @@ uint32_t fuse_get_hardware_type(uint32_t mkey_rev) {
} else {
return 3;
}
- } else if ((mkey_rev >= 0x03) && (mkey_rev < 0x07)) { /* Firmware versions from 4.0.0 to 6.2.0. */
+ } else if (target_firmware < ATMOSPHERE_TARGET_FIRMWARE_700) { /* Firmware versions from 4.0.0 to 6.2.0. */
static const uint32_t types[] = {0,1,4,3};
hardware_type |= ((fuse_reserved_odm4 >> 14) & 0x3C);
hardware_type--;
diff --git a/sept/sept-secondary/src/fuse.h b/sept/sept-secondary/src/fuse.h
index d118b53dc..5dae093c3 100644
--- a/sept/sept-secondary/src/fuse.h
+++ b/sept/sept-secondary/src/fuse.h
@@ -13,7 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-
+
#ifndef FUSEE_FUSE_H
#define FUSEE_FUSE_H
@@ -216,7 +216,7 @@ uint32_t fuse_get_reserved_odm(uint32_t idx);
uint32_t fuse_get_bootrom_patch_version(void);
uint64_t fuse_get_device_id(void);
uint32_t fuse_get_dram_id(void);
-uint32_t fuse_get_hardware_type(uint32_t mkey_rev);
+uint32_t fuse_get_hardware_type(uint32_t target_firmware);
uint32_t fuse_get_retail_type(void);
void fuse_get_hardware_info(void *dst);