diff --git a/bootloader/frontend/fe_emmc_tools.c b/bootloader/frontend/fe_emmc_tools.c index 1f60657..c272e2a 100644 --- a/bootloader/frontend/fe_emmc_tools.c +++ b/bootloader/frontend/fe_emmc_tools.c @@ -35,6 +35,8 @@ #define SDXC_BUF_ALIGNED 0xB6000000 #define MIXD_BUF_ALIGNED 0xB7000000 +#define NUM_SECTORS_PER_ITER 8192 // 4MB Cache. + extern sdmmc_t sd_sdmmc; extern sdmmc_storage_t sd_storage; extern FATFS sd_fs; @@ -47,7 +49,7 @@ extern void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_st static int _dump_emmc_verify(sdmmc_storage_t *storage, u32 lba_curr, char *outFilename, emmc_part_t *part) { FIL fp; - u8 sparseShouldVerify = 0; + u8 sparseShouldVerify = 4; u32 btn = 0; u32 prevPct = 200; int res = 0; @@ -60,8 +62,6 @@ static int _dump_emmc_verify(sdmmc_storage_t *storage, u32 lba_curr, char *outFi { u32 totalSectorsVer = (u32)((u64)f_size(&fp) >> (u64)9); - const u32 NUM_SECTORS_PER_ITER = 8192; // 4MB Cache. - u8 *bufEm = (u8 *)EMMC_BUF_ALIGNED; u8 *bufSd = (u8 *)SDXC_BUF_ALIGNED; @@ -111,9 +111,6 @@ static int _dump_emmc_verify(sdmmc_storage_t *storage, u32 lba_curr, char *outFi } } - sparseShouldVerify++; - sdFileSector += NUM_SECTORS_PER_ITER; - pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start); if (pct != prevPct) { @@ -123,6 +120,8 @@ static int _dump_emmc_verify(sdmmc_storage_t *storage, u32 lba_curr, char *outFi lba_curr += num; totalSectorsVer -= num; + sdFileSector += num; + sparseShouldVerify++; btn = btn_wait_timeout(0, BTN_VOL_DOWN | BTN_VOL_UP); if ((btn & BTN_VOL_DOWN) && (btn & BTN_VOL_UP)) @@ -274,8 +273,6 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t return 0; } - const u32 NUM_SECTORS_PER_ITER = 8192; - u8 *buf = (u8 *)MIXD_BUF_ALIGNED; u32 lba_curr = part->lba_start; @@ -292,7 +289,7 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t lbaStartPart = lba_curr; // Update the start LBA for verification. } u64 totalSize = (u64)((u64)totalSectors << 9); - if (!isSmallSdCard && sd_fs.fs_type == FS_EXFAT) + if (!isSmallSdCard && (sd_fs.fs_type == FS_EXFAT || totalSize <= FAT32_FILESIZE_LIMIT)) f_lseek(&fp, totalSize); else f_lseek(&fp, MIN(totalSize, multipartSplitSize)); @@ -691,8 +688,6 @@ static int _restore_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part (u32)((use_multipart ? (u64)totalCheckFileSize : fileSize) >> (u64)9) >> SECTORS_TO_MIB_COEFF); } - const u32 NUM_SECTORS_PER_ITER = 8192; // 4MB Cache. - u8 *buf = (u8 *)MIXD_BUF_ALIGNED; u32 lba_curr = part->lba_start; diff --git a/bootloader/frontend/fe_info.c b/bootloader/frontend/fe_info.c index d3b54ef..d2e7b20 100644 --- a/bootloader/frontend/fe_info.c +++ b/bootloader/frontend/fe_info.c @@ -449,9 +449,6 @@ void print_fuel_gauge_info() gfx_printf(&gfx_con, "%kFuel Gauge IC Info:\n%k", 0xFF00DDFF, 0xFFCCCCCC); - max17050_get_property(MAX17050_Age, &value); - gfx_printf(&gfx_con, "Age: %3d%\n", value); - max17050_get_property(MAX17050_RepSOC, &value); gfx_printf(&gfx_con, "Capacity now: %3d%\n", value >> 8); @@ -654,9 +651,9 @@ void bootrom_ipatches_info() else EPRINTFARGS("Failed to read evp_thunks. Error: %d", res); - u32 words[0x100]; - read_raw_ipatch_fuses(words); - emmcsn_path_impl(path, "/dumps", "ipatches.bin", NULL); + u32 words[192]; + read_raw_fuses(words); + emmcsn_path_impl(path, "/dumps", "raw_fuses.bin", NULL); if (!sd_save_to_file((u8 *)words, sizeof(words), path)) gfx_puts(&gfx_con, "\nipatches.bin saved!\n"); diff --git a/bootloader/gfx/di.c b/bootloader/gfx/di.c index fd02d25..5710ef1 100644 --- a/bootloader/gfx/di.c +++ b/bootloader/gfx/di.c @@ -142,7 +142,7 @@ void display_backlight_pwm_init() { clock_enable_pwm(); - PWM(PWM_CONTROLLER_PWM_CSR) = (1 << 31); // Enable PWM + PWM(PWM_CONTROLLER_PWM_CSR_0) = (1 << 31); // Enable PWM PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) = (PINMUX_AUX(PINMUX_AUX_LCD_BL_PWM) >> 2) << 2 | 1; // PWM clock source. gpio_config(GPIO_PORT_V, GPIO_PIN_0, GPIO_MODE_SPIO); // Backlight power mode. @@ -156,7 +156,7 @@ void display_backlight(bool enable) void display_backlight_brightness(u32 brightness, u32 step_delay) { - u32 old_value = (PWM(PWM_CONTROLLER_PWM_CSR) >> 16) & 0xFF; + u32 old_value = (PWM(PWM_CONTROLLER_PWM_CSR_0) >> 16) & 0xFF; if (brightness == old_value) return; @@ -167,7 +167,7 @@ void display_backlight_brightness(u32 brightness, u32 step_delay) { for (u32 i = old_value; i < brightness + 1; i++) { - PWM(PWM_CONTROLLER_PWM_CSR) = (1 << 31) | (i << 16); // Enable PWM + PWM(PWM_CONTROLLER_PWM_CSR_0) = (1 << 31) | (i << 16); // Enable PWM usleep(step_delay); } } @@ -175,12 +175,12 @@ void display_backlight_brightness(u32 brightness, u32 step_delay) { for (u32 i = old_value; i > brightness; i--) { - PWM(PWM_CONTROLLER_PWM_CSR) = (1 << 31) | (i << 16); // Enable PWM + PWM(PWM_CONTROLLER_PWM_CSR_0) = (1 << 31) | (i << 16); // Enable PWM usleep(step_delay); } } if (!brightness) - PWM(PWM_CONTROLLER_PWM_CSR) = 0; + PWM(PWM_CONTROLLER_PWM_CSR_0) = 0; } void display_end() diff --git a/bootloader/gfx/di.h b/bootloader/gfx/di.h index ec4bd23..898029d 100644 --- a/bootloader/gfx/di.h +++ b/bootloader/gfx/di.h @@ -350,9 +350,6 @@ #define MIPI_CAL_MIPI_BIAS_PAD_CFG2 0x60 -/*! Display backlight related PWM registers. */ -#define PWM_CONTROLLER_PWM_CSR 0x00 - void display_init(); void display_backlight_pwm_init(); void display_end(); diff --git a/bootloader/hos/hos.c b/bootloader/hos/hos.c index ada8a94..f2fcf6a 100644 --- a/bootloader/hos/hos.c +++ b/bootloader/hos/hos.c @@ -616,7 +616,7 @@ int hos_launch(ini_sec_t *cfg) // Config Exosphère if booting full Atmosphère. if (ctxt.atmosphere && ctxt.secmon) - config_exosphere(ctxt.pkg1_id->id, ctxt.pkg1_id->kb, (void *)ctxt.pkg1_id->warmboot_base, ctxt.pkg1, ctxt.stock); + config_exosphere(ctxt.pkg1_id->id, ctxt.pkg1_id->kb, (void *)ctxt.pkg1_id->warmboot_base, ctxt.stock); // Unmount SD card. sd_unmount(); diff --git a/bootloader/hos/hos_config.c b/bootloader/hos/hos_config.c index 02bd9b2..f9a7db4 100644 --- a/bootloader/hos/hos_config.c +++ b/bootloader/hos/hos_config.c @@ -224,10 +224,12 @@ int parse_boot_config(launch_ctxt_t *ctxt) { if (!strcmp(_config_handlers[i].key, kv->key)) if (!_config_handlers[i].handler(ctxt, kv->val)) + { + EPRINTFARGS("Error while loading %s:\n%s", kv->key, kv->val); return 0; + } } } return 1; } - diff --git a/bootloader/hos/secmon_exo.c b/bootloader/hos/secmon_exo.c index 0372864..e1fa2cd 100644 --- a/bootloader/hos/secmon_exo.c +++ b/bootloader/hos/secmon_exo.c @@ -48,7 +48,7 @@ typedef struct _atm_meta_t #define EXO_FLAG_DBG_PRIV (1 << 1) #define EXO_FLAG_DBG_USER (1 << 2) -void config_exosphere(const char *id, u32 kb, void *warmboot, void *pkg1, bool stock) +void config_exosphere(const char *id, u32 kb, void *warmboot, bool stock) { u32 exoFwNo = 0; u32 exoFlags = 0; diff --git a/bootloader/hos/secmon_exo.h b/bootloader/hos/secmon_exo.h index d4e529b..cb6c680 100644 --- a/bootloader/hos/secmon_exo.h +++ b/bootloader/hos/secmon_exo.h @@ -19,6 +19,6 @@ #include "../utils/types.h" -void config_exosphere(const char *id, u32 kb, void *warmboot, void *pkg1, bool stock); +void config_exosphere(const char *id, u32 kb, void *warmboot, bool stock); #endif diff --git a/bootloader/libs/fatfs/ff.h b/bootloader/libs/fatfs/ff.h index 4751209..0f4be3a 100644 --- a/bootloader/libs/fatfs/ff.h +++ b/bootloader/libs/fatfs/ff.h @@ -178,12 +178,12 @@ typedef struct { DWORD dir_sect; /* Sector number containing the directory entry (not used at exFAT) */ BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */ #endif -#if FF_USE_FASTSEEK - DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */ -#endif #if !FF_FS_TINY BYTE buf[FF_MAX_SS]; /* File private data read/write window */ #endif +#if FF_USE_FASTSEEK + DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */ +#endif } FIL; diff --git a/bootloader/libs/fatfs/ffconf.h b/bootloader/libs/fatfs/ffconf.h index b4b4947..be64ef3 100644 --- a/bootloader/libs/fatfs/ffconf.h +++ b/bootloader/libs/fatfs/ffconf.h @@ -239,7 +239,7 @@ #define FF_FS_NORTC 1 #define FF_NORTC_MON 1 #define FF_NORTC_MDAY 1 -#define FF_NORTC_YEAR 2018 +#define FF_NORTC_YEAR 2019 /* The option FF_FS_NORTC switches timestamp function. If the system does not have / any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable / the timestamp function. Every object modified by FatFs will have a fixed timestamp diff --git a/bootloader/sec/se.c b/bootloader/sec/se.c index 69b76b8..0b3c707 100644 --- a/bootloader/sec/se.c +++ b/bootloader/sec/se.c @@ -36,7 +36,7 @@ static void _gf256_mul_x(void *block) u8 *pdata = (u8 *)block; u32 carry = 0; - for (u32 i = 0xF; i >= 0; i--) + for (int i = 0xF; i >= 0; i--) { u8 b = pdata[i]; pdata[i] = (b << 1) | carry; diff --git a/bootloader/soc/clock.c b/bootloader/soc/clock.c index 9ec86e0..26808e2 100644 --- a/bootloader/soc/clock.c +++ b/bootloader/soc/clock.c @@ -276,12 +276,16 @@ static void _clock_sdmmc_set_reset(u32 id) { case SDMMC_1: CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_SET) = L_SET_SDMMC1_RST; + break; case SDMMC_2: CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_SET) = L_SET_SDMMC2_RST; + break; case SDMMC_3: CLOCK(CLK_RST_CONTROLLER_RST_DEV_U_SET) = U_SET_SDMMC3_RST; + break; case SDMMC_4: CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_SET) = L_SET_SDMMC4_RST; + break; } } @@ -291,12 +295,16 @@ static void _clock_sdmmc_clear_reset(u32 id) { case SDMMC_1: CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_CLR) = L_CLR_SDMMC1_RST; + break; case SDMMC_2: CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_CLR) = L_CLR_SDMMC2_RST; + break; case SDMMC_3: CLOCK(CLK_RST_CONTROLLER_RST_DEV_U_CLR) = U_CLR_SDMMC3_RST; + break; case SDMMC_4: CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_CLR) = L_CLR_SDMMC4_RST; + break; } } @@ -322,12 +330,16 @@ static void _clock_sdmmc_set_enable(u32 id) { case SDMMC_1: CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_SET) = L_SET_CLK_ENB_SDMMC1; + break; case SDMMC_2: CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_SET) = L_SET_CLK_ENB_SDMMC2; + break; case SDMMC_3: CLOCK(CLK_RST_CONTROLLER_CLK_ENB_U_SET) = U_SET_CLK_ENB_SDMMC3; + break; case SDMMC_4: CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_SET) = L_SET_CLK_ENB_SDMMC4; + break; } } @@ -337,12 +349,16 @@ static void _clock_sdmmc_clear_enable(u32 id) { case SDMMC_1: CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_CLR) = L_CLR_CLK_ENB_SDMMC1; + break; case SDMMC_2: CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_CLR) = L_CLR_CLK_ENB_SDMMC2; + break; case SDMMC_3: CLOCK(CLK_RST_CONTROLLER_CLK_ENB_U_CLR) = U_CLR_CLK_ENB_SDMMC3; + break; case SDMMC_4: CLOCK(CLK_RST_CONTROLLER_CLK_ENB_L_CLR) = L_CLR_CLK_ENB_SDMMC4; + break; } } @@ -457,6 +473,7 @@ void clock_sdmmc_get_params(u32 *pout, u16 *pdivisor, u32 type) case 5: *pout = 25000; *pdivisor = 64; + break; case 6: case 8: *pout = 25000; @@ -465,9 +482,11 @@ void clock_sdmmc_get_params(u32 *pout, u16 *pdivisor, u32 type) case 7: *pout = 50000; *pdivisor = 1; + break; case 10: *pout = 100000; *pdivisor = 1; + break; case 13: *pout = 40800; *pdivisor = 1; diff --git a/bootloader/soc/fuse.c b/bootloader/soc/fuse.c index 756e56c..98a347a 100644 --- a/bootloader/soc/fuse.c +++ b/bootloader/soc/fuse.c @@ -313,9 +313,9 @@ int fuse_read_evp_thunk(u32 *iram_evp_thunks, u32 *iram_evp_thunks_len) return 0; } -void read_raw_ipatch_fuses(u32 *words) +void read_raw_fuses(u32 *words) { - for (u32 i = 0; i < 0x100; i++) + for (u32 i = 0; i < 192; i++) { FUSE(FUSE_ADDR) = i; FUSE(FUSE_CTRL) = (FUSE(FUSE_ADDR) & ~FUSE_CMD_MASK) | FUSE_READ; diff --git a/bootloader/soc/fuse.h b/bootloader/soc/fuse.h index b2f04e0..c15d811 100644 --- a/bootloader/soc/fuse.h +++ b/bootloader/soc/fuse.h @@ -57,6 +57,6 @@ u32 fuse_read_odm(u32 idx); void fuse_wait_idle(); int fuse_read_ipatch(void (*ipatch)(u32 offset, u32 value)); int fuse_read_evp_thunk(u32 *iram_evp_thunks, u32 *iram_evp_thunks_len); -void read_raw_ipatch_fuses(u32 *words); +void read_raw_fuses(u32 *words); #endif diff --git a/bootloader/soc/hw_init.c b/bootloader/soc/hw_init.c index 271140b..1c2e92a 100644 --- a/bootloader/soc/hw_init.c +++ b/bootloader/soc/hw_init.c @@ -18,6 +18,14 @@ #include #include "hw_init.h" +#include "clock.h" +#include "fuse.h" +#include "gpio.h" +#include "i2c.h" +#include "pinmux.h" +#include "pmc.h" +#include "t210.h" +#include "uart.h" #include "../gfx/di.h" #include "../mem/mc.h" #include "../mem/sdram.h" @@ -25,14 +33,6 @@ #include "../power/max7762x.h" #include "../sec/se.h" #include "../sec/se_t210.h" -#include "../soc/clock.h" -#include "../soc/fuse.h" -#include "../soc/gpio.h" -#include "../soc/i2c.h" -#include "../soc/pinmux.h" -#include "../soc/pmc.h" -#include "../soc/t210.h" -#include "../soc/uart.h" #include "../storage/sdmmc.h" #include "../utils/util.h" diff --git a/bootloader/soc/t210.h b/bootloader/soc/t210.h index 0d0b541..1b11d72 100644 --- a/bootloader/soc/t210.h +++ b/bootloader/soc/t210.h @@ -179,6 +179,10 @@ #define I2S_CG_SLCG_ENABLE (1 << 0) #define I2S_CTRL_MASTER_EN (1 << 10) +/*! PWM registers. */ +#define PWM_CONTROLLER_PWM_CSR_0 0x00 +#define PWM_CONTROLLER_PWM_CSR_1 0x10 + /*! Special registers. */ #define EMC_SCRATCH0 0x324 #define EMC_HEKA_UPD (1 << 30) diff --git a/bootloader/storage/nx_emmc.h b/bootloader/storage/nx_emmc.h index 05c74f4..753d5aa 100644 --- a/bootloader/storage/nx_emmc.h +++ b/bootloader/storage/nx_emmc.h @@ -59,7 +59,7 @@ typedef struct _emmc_part_t u32 lba_start; u32 lba_end; u64 attrs; - s8 name[37]; + char name[37]; link_t link; } emmc_part_t; diff --git a/bootloader/storage/sdmmc.c b/bootloader/storage/sdmmc.c index cc56a03..69a6a18 100644 --- a/bootloader/storage/sdmmc.c +++ b/bootloader/storage/sdmmc.c @@ -530,7 +530,9 @@ int sdmmc_storage_init_mmc(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 id, u32 DPRINTF("[MMC] BKOPS enabled\n"); } else + { DPRINTF("[MMC] BKOPS disabled\n"); + } if (!_mmc_storage_enable_highspeed(storage, storage->ext_csd.card_type, type)) return 0; @@ -1103,7 +1105,9 @@ int sdmmc_storage_init_sd(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 id, u32 DPRINTF("[SD] switched to wide bus width\n"); } else + { DPRINTF("[SD] SD does not support wide bus width\n"); + } if (storage->is_low_voltage) { @@ -1129,7 +1133,9 @@ int sdmmc_storage_init_sd(sdmmc_storage_t *storage, sdmmc_t *sdmmc, u32 id, u32 // Parse additional card info from sd status. if (_sd_storage_get_ssr(storage, buf)) + { DPRINTF("[SD] got sd status\n"); + } free(buf); return 1; diff --git a/bootloader/storage/sdmmc.h b/bootloader/storage/sdmmc.h index a144c12..7ae20e3 100644 --- a/bootloader/storage/sdmmc.h +++ b/bootloader/storage/sdmmc.h @@ -47,7 +47,7 @@ typedef struct _mmc_csd u32 read_blkbits; u32 write_blkbits; u32 capacity; - u8 write_protect; + u8 write_protect; u16 busspeed; } mmc_csd_t; diff --git a/bootloader/utils/types.h b/bootloader/utils/types.h index d1eab24..abe237a 100644 --- a/bootloader/utils/types.h +++ b/bootloader/utils/types.h @@ -26,7 +26,7 @@ #define OFFSET_OF(t, m) ((u32)&((t *)NULL)->m) #define CONTAINER_OF(mp, t, mn) ((t *)((u32)mp - OFFSET_OF(t, mn))) -typedef char s8; +typedef signed char s8; typedef short s16; typedef short SHORT; typedef int s32;