diff --git a/fusee/fusee-secondary/src/console.c b/fusee/fusee-secondary/src/console.c new file mode 100644 index 000000000..9b095eb4d --- /dev/null +++ b/fusee/fusee-secondary/src/console.c @@ -0,0 +1,132 @@ +#include +#include +#include +#include +#include +#include "console.h" +#include "display/video_fb.h" + +static ssize_t console_write(struct _reent *r, void *fd, const char *ptr, size_t len); + +static const devoptab_t dotab_stdout = { + .name = "con", + .write_r = console_write, +}; + +/* https://github.com/switchbrew/libnx/blob/master/nx/source/runtime/util/utf/decode_utf8.c */ +ssize_t decode_utf8(uint32_t *out, const uint8_t *in) { + uint8_t code1, code2, code3, code4; + + code1 = *in++; + if(code1 < 0x80) { + /* 1-byte sequence */ + *out = code1; + return 1; + } else if(code1 < 0xC2) { + return -1; + } else if(code1 < 0xE0) { + /* 2-byte sequence */ + code2 = *in++; + if((code2 & 0xC0) != 0x80) { + return -1; + } + + *out = (code1 << 6) + code2 - 0x3080; + return 2; + } else if(code1 < 0xF0) { + /* 3-byte sequence */ + code2 = *in++; + if((code2 & 0xC0) != 0x80) { + return -1; + } + if(code1 == 0xE0 && code2 < 0xA0) { + return -1; + } + + code3 = *in++; + if((code3 & 0xC0) != 0x80) { + return -1; + } + + *out = (code1 << 12) + (code2 << 6) + code3 - 0xE2080; + return 3; + } else if(code1 < 0xF5) { + /* 4-byte sequence */ + code2 = *in++; + if((code2 & 0xC0) != 0x80) { + return -1; + } + if(code1 == 0xF0 && code2 < 0x90) { + return -1; + } + if(code1 == 0xF4 && code2 >= 0x90) { + return -1; + } + + code3 = *in++; + if((code3 & 0xC0) != 0x80) { + return -1; + } + + code4 = *in++; + if((code4 & 0xC0) != 0x80) { + return -1; + } + + *out = (code1 << 18) + (code2 << 12) + (code3 << 6) + code4 - 0x3C82080; + return 4; + } + + return -1; +} + +static ssize_t console_write(struct _reent *r, void *fd, const char *ptr, size_t len) { + size_t i = 0; + while (i < len) { + uint32_t chr; + ssize_t n = decode_utf8(&chr, (uint8_t *)(ptr + i)); + if (n == -1) { + break; + } else { + i += (size_t)n; + video_putc(chr > 0xFF ? '?' : (char)chr); + } + } + + return i; +} + +static bool g_console_created = false; + +static int console_create(void) { + if (g_console_created) { + errno = EEXIST; + return -1; + } + + devoptab_list[STD_OUT] = &dotab_stdout; + devoptab_list[STD_ERR] = &dotab_stdout; + + setvbuf(stdout, NULL , _IONBF, 0); + setvbuf(stderr, NULL , _IONBF, 0); + + g_console_created = true; + return 0; +} + +int console_init(void *fb) { + if (video_init(fb) == -1) { + errno = EIO; + return -1; + } + + return console_create(); +} + +int console_resume(void *fb, int row, int col) { + video_resume(fb, row, col); if(false){// if (video_resume(fb, row, col) == -1) { + errno = EIO; + return -1; + } + return console_create(); +} diff --git a/fusee/fusee-secondary/src/console.h b/fusee/fusee-secondary/src/console.h new file mode 100644 index 000000000..f46954427 --- /dev/null +++ b/fusee/fusee-secondary/src/console.h @@ -0,0 +1,7 @@ +#ifndef FUSEE_CONSOLE_H +#define FUSEE_CONSOLE_H + +int console_init(void *fb); +int console_resume(void *fb, int row, int col); + +#endif diff --git a/fusee/fusee-secondary/src/display/video_fb.h b/fusee/fusee-secondary/src/display/video_fb.h index ebedc0626..43a7ef60d 100644 --- a/fusee/fusee-secondary/src/display/video_fb.h +++ b/fusee/fusee-secondary/src/display/video_fb.h @@ -52,6 +52,7 @@ int video_get_row(void); int video_init(void *fb); int video_resume(void *fb, int row, int col); +void video_putc(char c); void video_puts(const char *s); #endif /*_VIDEO_FB_H_ */ diff --git a/fusee/fusee-secondary/src/gpio.c b/fusee/fusee-secondary/src/gpio.c index fd44a0f67..f6572d16c 100644 --- a/fusee/fusee-secondary/src/gpio.c +++ b/fusee/fusee-secondary/src/gpio.c @@ -1,12 +1,12 @@ +#include #include #include #include #include "gpio.h" -#include "lib/printk.h" enum tegra_gpio_shifts { - GPIO_BANK_SHIFT = 5, + GPIO_BANK_SHIFT = 5, GPIO_PORT_SHIFT = 3, }; @@ -56,7 +56,7 @@ static volatile uint32_t gpio_get_mask(enum tegra_named_gpio pin) * * @param pin The GPIO pin to work with, as created with TEGRA_GPIO, or a named GPIO. * @param should_be_set True iff the relevant bit should be set; or false if it should be cleared. - * @param offset The offset into a gpio_bank structure + * @param offset The offset into a gpio_bank structure */ static void gpio_simple_register_set(enum tegra_named_gpio pin, bool should_be_set, size_t offset) { @@ -83,7 +83,7 @@ static void gpio_simple_register_set(enum tegra_named_gpio pin, bool should_be_s * * @param pin The GPIO pin to work with, as created with TEGRA_GPIO, or a named GPIO. * @param should_be_set True iff the relevant bit should be set; or false if it should be cleared. - * @param offset The offset into a gpio_bank structure + * @param offset The offset into a gpio_bank structure */ static bool gpio_simple_register_get(enum tegra_named_gpio pin, size_t offset) { @@ -121,7 +121,7 @@ void gpio_configure_mode(enum tegra_named_gpio pin, enum tegra_gpio_mode mode) */ void gpio_configure_direction(enum tegra_named_gpio pin, enum tegra_gpio_direction dir) { - gpio_simple_register_set(pin, dir == GPIO_DIRECTION_OUTPUT, offsetof(struct tegra_gpio_bank, direction)); + gpio_simple_register_set(pin, dir == GPIO_DIRECTION_OUTPUT, offsetof(struct tegra_gpio_bank, direction)); } @@ -133,7 +133,7 @@ void gpio_configure_direction(enum tegra_named_gpio pin, enum tegra_gpio_directi */ void gpio_write(enum tegra_named_gpio pin, enum tegra_gpio_value value) { - gpio_simple_register_set(pin, value == GPIO_LEVEL_HIGH, offsetof(struct tegra_gpio_bank, out)); + gpio_simple_register_set(pin, value == GPIO_LEVEL_HIGH, offsetof(struct tegra_gpio_bank, out)); } @@ -145,5 +145,5 @@ void gpio_write(enum tegra_named_gpio pin, enum tegra_gpio_value value) */ enum tegra_gpio_value gpio_read(enum tegra_named_gpio pin) { - return gpio_simple_register_get(pin, offsetof(struct tegra_gpio_bank, in)); + return gpio_simple_register_get(pin, offsetof(struct tegra_gpio_bank, in)); } diff --git a/fusee/fusee-secondary/src/lib/printk.c b/fusee/fusee-secondary/src/lib/printk.c deleted file mode 100644 index b53f1e109..000000000 --- a/fusee/fusee-secondary/src/lib/printk.c +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Kernel print functions. - */ - -#include -#include "printk.h" - -#include "../display/video_fb.h" - -/** - * Temporary stand-in main printk. - * - * TODO: This should print via UART, console framebuffer, and to a ring for - * consumption by Horizon - */ -void printk(char *fmt, ...) -{ - va_list list; - va_start(list, fmt); - vprintk(fmt, list); - va_end(list); -} - - -void vprintk(char *fmt, va_list args) -{ - char buf[512]; - vsnprintf(buf, sizeof(buf), fmt, args); - video_puts(buf); -} diff --git a/fusee/fusee-secondary/src/lib/printk.h b/fusee/fusee-secondary/src/lib/printk.h deleted file mode 100644 index aaad8f1b4..000000000 --- a/fusee/fusee-secondary/src/lib/printk.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __PRINTK_H__ -#define __PRINTK_H__ - -#include - -void printk(char *fmt, ...); -void vprintk(char *fmt, va_list args); - -#endif diff --git a/fusee/fusee-secondary/src/loader.c b/fusee/fusee-secondary/src/loader.c index 758ac55ba..d573cdc77 100644 --- a/fusee/fusee-secondary/src/loader.c +++ b/fusee/fusee-secondary/src/loader.c @@ -4,7 +4,6 @@ #include "loader.h" #include "sd_utils.h" #include "stage2.h" -#include "lib/printk.h" #include "lib/ini.h" const char *g_bct0 = NULL; @@ -52,29 +51,29 @@ void load_list_entry(const char *key) { load_file_t load_file_ctx = {0}; load_file_ctx.key = key; - printk("Loading %s\n", key); + printf("Loading %s\n", key); if (ini_parse_string(get_loader_ctx()->bct0, loadlist_entry_ini_handler, &load_file_ctx) < 0) { - printk("Error: Failed to parse BCT.ini!\n"); + printf("Error: Failed to parse BCT.ini!\n"); generic_panic(); } if (load_file_ctx.load_address == 0 || load_file_ctx.path[0] == '\x00') { - printk("Error: Failed to determine where to load %s!\n", key); + printf("Error: Failed to determine where to load %s!\n", key); generic_panic(); } - printk("Loading %s from %s to 0x%08x\n", key, load_file_ctx.path, load_file_ctx.load_address); + printf("Loading %s from %s to 0x%08x\n", key, load_file_ctx.path, load_file_ctx.load_address); if (!validate_load_address(load_file_ctx.load_address)) { - printk("Error: Load address 0x%08x is invalid!\n"); + printf("Error: Load address 0x%08x is invalid!\n", load_file_ctx.load_address); generic_panic(); } /* Read file off of SD. */ load_file_ctx.load_size = read_sd_file((void *)load_file_ctx.load_address, LOADER_FILESIZE_MAX, load_file_ctx.path); if (load_file_ctx.load_size == 0) { - printk("Error: Failed to read %s!\n", load_file_ctx.path); + printf("Error: Failed to read %s!\n", load_file_ctx.path); generic_panic(); } @@ -91,7 +90,7 @@ void load_list_entry(const char *key) { } void parse_loadlist(const char *ll) { - printk("Parsing load list: %s\n", ll); + printf("Parsing load list: %s\n", ll); char load_list[0x200] = {0}; strncpy(load_list, ll, 0x200); @@ -112,7 +111,7 @@ void parse_loadlist(const char *ll) { /* Skip to the next delimiter. */ for (; *p == ' ' || *p == '\t' || *p == '\x00'; p++) { } if (*p != '|') { - printk("Error: Load list is malformed!\n"); + printf("Error: Load list is malformed!\n"); generic_panic(); } else { /* Skip to the next entry. */ @@ -158,7 +157,7 @@ void load_payload(const char *bct0) { ctx->bct0 = bct0; if (ini_parse_string(ctx->bct0, loadlist_ini_handler, ctx) < 0) { - printk("Error: Failed to parse BCT.ini!\n"); + printf("Error: Failed to parse BCT.ini!\n"); generic_panic(); } } diff --git a/fusee/fusee-secondary/src/main.c b/fusee/fusee-secondary/src/main.c index 2c7e9a904..eeb35b68d 100644 --- a/fusee/fusee-secondary/src/main.c +++ b/fusee/fusee-secondary/src/main.c @@ -1,11 +1,11 @@ +#include #include "utils.h" #include "hwinit.h" #include "loader.h" #include "stage2.h" #include "nxboot.h" +#include "console.h" #include "sd_utils.h" -#include "lib/printk.h" -#include "display/video_fb.h" #include "fs_dev.h" /* TODO: Add a #define for this size, somewhere. Also, primary can only actually load 0x7000. */ @@ -40,16 +40,16 @@ int main(int argc, void **argv) { /* TODO: What other hardware init should we do here? */ - /* Setup LFB. */ - video_resume(args.lfb, args.console_row, args.console_col); + /* Setup console/stdout. */ + console_resume(args.lfb, args.console_row, args.console_col); - printk("Welcome to Atmosph\xe8re Fus\xe9" "e Stage 2!\n"); - printk("Stage 2 executing from: %s\n", (const char *)argv[STAGE2_ARGV_PROGRAM_PATH]); + printf(u8"Welcome to Atmosphère Fusée Stage 2!\n"); + printf("Stage 2 executing from: %s\n", (const char *)argv[STAGE2_ARGV_PROGRAM_PATH]); /* This will load all remaining binaries off of the SD. */ load_payload(g_bct0); - printk("Loaded payloads!\n"); + printf("Loaded payloads!\n"); /* Unmount everything (this causes all open files to be flushed and closed) */ fsdev_unmount_all(); diff --git a/fusee/fusee-secondary/src/nxboot.c b/fusee/fusee-secondary/src/nxboot.c index adf6a4d39..f7c08c4f1 100644 --- a/fusee/fusee-secondary/src/nxboot.c +++ b/fusee/fusee-secondary/src/nxboot.c @@ -1,3 +1,4 @@ +#include #include "utils.h" #include "nxboot.h" #include "key_derivation.h" @@ -5,7 +6,6 @@ #include "loader.h" #include "splash_screen.h" #include "exocfg.h" -#include "lib/printk.h" #include "display/video_fb.h" #include "lib/ini.h" #include "hwinit/cluster.h" @@ -26,45 +26,45 @@ static int exosphere_ini_handler(void *user, const char *section, const char *na void nxboot_configure_exosphere(void) { exosphere_config_t exo_cfg = {0}; - + exo_cfg.magic = MAGIC_EXOSPHERE_BOOTCONFIG; exo_cfg.target_firmware = EXOSPHERE_TARGET_FIRMWARE_MAX; - + if (ini_parse_string(get_loader_ctx()->bct0, exosphere_ini_handler, &exo_cfg) < 0) { - printk("Error: Failed to parse BCT.ini!\n"); + printf("Error: Failed to parse BCT.ini!\n"); generic_panic(); } - + if (exo_cfg.target_firmware < EXOSPHERE_TARGET_FIRMWARE_MIN || exo_cfg.target_firmware > EXOSPHERE_TARGET_FIRMWARE_MAX) { - printk("Error: Invalid Exosphere target firmware!\n"); + printf("Error: Invalid Exosphere target firmware!\n"); generic_panic(); } - + *(MAILBOX_EXOSPHERE_CONFIGURATION) = exo_cfg; } /* This is the main function responsible for booting Horizon. */ void nxboot_main(void) { loader_ctx_t *loader_ctx = get_loader_ctx(); - + /* TODO: Validate that we're capable of booting. */ - + /* TODO: Initialize Boot Reason. */ - + /* TODO: How should we deal with bootconfig? */ - + /* Setup boot configuration for Exosphere. */ nxboot_configure_exosphere(); - + /* Derive keydata. */ derive_nx_keydata(MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware); - + /* Patch package2, adding thermosphere + custom KIPs. */ package2_patch((void *)loader_ctx->package2_loadfile.load_address); - + /* Boot up Exosphere. */ MAILBOX_NX_BOOTLOADER_IS_SECMON_AWAKE = 0; - if (MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware <= EXOSPHERE_TARGET_FIRMWARE_400) { + if (MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware <= EXOSPHERE_TARGET_FIRMWARE_400) { MAILBOX_NX_BOOTLOADER_SETUP_STATE = NX_BOOTLOADER_STATE_LOADED_PACKAGE2; } else { MAILBOX_NX_BOOTLOADER_SETUP_STATE = NX_BOOTLOADER_STATE_LOADED_PACKAGE2_4X; @@ -73,14 +73,14 @@ void nxboot_main(void) { while (MAILBOX_NX_BOOTLOADER_IS_SECMON_AWAKE == 0) { /* Wait for Exosphere to wake up. */ } - if (MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware <= EXOSPHERE_TARGET_FIRMWARE_400) { + if (MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware <= EXOSPHERE_TARGET_FIRMWARE_400) { MAILBOX_NX_BOOTLOADER_SETUP_STATE = NX_BOOTLOADER_STATE_FINISHED; } else { MAILBOX_NX_BOOTLOADER_SETUP_STATE = NX_BOOTLOADER_STATE_FINISHED_4X; } - + /* Display splash screen. */ display_splash_screen_bmp(loader_ctx->custom_splash_path); - + /* TODO: Halt ourselves. */ -} \ No newline at end of file +} diff --git a/fusee/fusee-secondary/src/package2.c b/fusee/fusee-secondary/src/package2.c index 753391223..8e8e6d0e7 100644 --- a/fusee/fusee-secondary/src/package2.c +++ b/fusee/fusee-secondary/src/package2.c @@ -1,17 +1,17 @@ +#include #include "utils.h" #include "masterkey.h" #include "stratosphere.h" #include "package2.h" #include "kip.h" #include "se.h" -#include "lib/printk.h" /* Stage 2 executes from DRAM, so we have tons of space. */ /* This *greatly* simplifies logic. */ unsigned char g_patched_package2[PACKAGE2_SIZE_MAX]; unsigned char g_package2_sections[PACKAGE2_SECTION_MAX][PACKAGE2_SIZE_MAX]; -package2_header_t *g_patched_package2_header = (package2_header_t *)g_patched_package2; +package2_header_t *g_patched_package2_header = (package2_header_t *)g_patched_package2; void package2_decrypt(void *package2_address); void package2_add_thermosphere_section(void); @@ -22,19 +22,19 @@ void package2_fixup_header_and_section_hashes(void); void package2_patch(void *package2_address) { /* First things first: Decrypt Package2. */ package2_decrypt(package2_address); - + /* Modify Package2 to add an additional thermosphere section. */ package2_add_thermosphere_section(); - + /* Perform any patches we want to the NX kernel. */ package2_patch_kernel(); - + /* Perform any patches we want to the INI1 (This is where our built-in sysmodules will be added.) */ package2_patch_ini1(); - + /* Fix all necessary data in the header to accomodate for the new patches. */ package2_fixup_header_and_section_hashes(); - + /* Relocate Package2. */ memcpy(NX_BOOTLOADER_PACKAGE2_LOAD_ADDRESS, g_patched_package2, sizeof(g_patched_package2)); } @@ -139,7 +139,7 @@ uint32_t decrypt_and_validate_header(package2_header_t *header, bool is_plaintex package2_meta_t metadata; /* TODO: Also accept plaintext package2 based on bootconfig. */ - + if (!is_plaintext) { uint32_t mkey_rev; @@ -156,7 +156,7 @@ uint32_t decrypt_and_validate_header(package2_header_t *header, bool is_plaintex } /* Ensure we successfully decrypted the header. */ - if (mkey_rev > mkey_get_revision()) { + if (mkey_rev > mkey_get_revision()) { panic(0xFAF00003); } } else if (!validate_package2_metadata(&header->metadata)) { @@ -168,13 +168,13 @@ uint32_t decrypt_and_validate_header(package2_header_t *header, bool is_plaintex void package2_decrypt(void *package2_address) { /* TODO: Actually decrypt, and copy sections into the relevant g_package2_sections[n] */ memcpy(g_patched_package2, NX_BOOTLOADER_PACKAGE2_LOAD_ADDRESS, PACKAGE2_SIZE_MAX); - + bool is_package2_plaintext = g_patched_package2_header->signature[0]; is_package2_plaintext &= memcmp(g_patched_package2_header->signature, g_patched_package2_header->signature + 1, sizeof(g_patched_package2_header->signature) - 1) == 0; is_package2_plaintext &= g_patched_package2_header->metadata.magic == MAGIC_PK21; - + uint32_t pk21_mkey_revision = decrypt_and_validate_header(g_patched_package2_header, is_package2_plaintext); - + size_t cur_section_offset = 0; /* Copy each section to its appropriate location, decrypting if necessary. */ for (unsigned int section = 0; section < PACKAGE2_SECTION_MAX; section++) { @@ -193,17 +193,17 @@ void package2_decrypt(void *package2_address) { } cur_section_offset += size; } - + /* Clear the signature, to signal that this is a plaintext, unsigned package2. */ memset(g_patched_package2_header->signature, 0, sizeof(g_patched_package2_header->signature)); } void package2_add_thermosphere_section(void) { if (g_patched_package2_header->metadata.section_sizes[PACKAGE2_SECTION_UNUSED] != 0) { - printk("Error: Package2 has no unused section for Thermosph\xe8re!\n"); + printf(u8"Error: Package2 has no unused section for Thermosphère!\n"); generic_panic(); } - + /* TODO: Copy thermosphere to g_package2_sections[PACKAGE2_SECTION_UNUSED], update header size. */ } @@ -219,34 +219,34 @@ void package2_patch_ini1(void) { inis_to_merge[STRATOSPHERE_INI1_PACKAGE2] = (ini1_header_t *)g_package2_sections[PACKAGE2_SECTION_INI1]; /* Merge all of the INI1s. */ - g_patched_package2_header->metadata.section_sizes[PACKAGE2_SECTION_INI1] = stratosphere_merge_inis(g_package2_sections[PACKAGE2_SECTION_INI1], inis_to_merge, STRATOSPHERE_INI1_MAX); + g_patched_package2_header->metadata.section_sizes[PACKAGE2_SECTION_INI1] = stratosphere_merge_inis(g_package2_sections[PACKAGE2_SECTION_INI1], inis_to_merge, STRATOSPHERE_INI1_MAX); } void package2_fixup_header_and_section_hashes(void) { size_t cur_section_offset = 0; - + /* Copy each section to its appropriate location. */ for (unsigned int section = 0; section < PACKAGE2_SECTION_MAX; section++) { if (g_patched_package2_header->metadata.section_sizes[section] == 0) { continue; } - + size_t size = (size_t)g_patched_package2_header->metadata.section_sizes[section]; if (sizeof(package2_header_t) + cur_section_offset + size > PACKAGE2_SIZE_MAX) { - printk("Error: Patched Package2 is too big!\n"); + printf("Error: Patched Package2 is too big!\n"); generic_panic(); } - + /* Copy the section into the new package2. */ memcpy(g_patched_package2 + sizeof(package2_header_t) + cur_section_offset, g_package2_sections[section], size); /* Fix up the hash. */ se_calculate_sha256(g_patched_package2_header->metadata.section_hashes[section], g_package2_sections[section], size); - + cur_section_offset += size; } - + /* Fix up the size in XOR'd CTR. */ uint32_t package_size = g_patched_package2_header->metadata.ctr_dwords[0] ^ g_patched_package2_header->metadata.ctr_dwords[2] ^ g_patched_package2_header->metadata.ctr_dwords[3]; uint32_t new_package_size = sizeof(package2_header_t) + cur_section_offset; g_patched_package2_header->metadata.ctr_dwords[3] ^= (package_size ^ new_package_size); -} \ No newline at end of file +} diff --git a/fusee/fusee-secondary/src/sd_utils.c b/fusee/fusee-secondary/src/sd_utils.c index 47c4dc34e..d9983c5f0 100644 --- a/fusee/fusee-secondary/src/sd_utils.c +++ b/fusee/fusee-secondary/src/sd_utils.c @@ -2,8 +2,6 @@ #include "sd_utils.h" #include "hwinit.h" #include "sdmmc.h" -#include "lib/printk.h" -#include "lib/fatfs/ff.h" /* This is used by diskio.h. */ struct mmc sd_mmc; @@ -23,7 +21,7 @@ int initialize_sd(void) { } mc_enable_ahb_redirect(); if (sdmmc_init(&sd_mmc, SWITCH_MICROSD) == 0) { - printk("Initialized SD card!\n"); + printf("Initialized SD card!\n"); initialized_sd = 1; } return initialized_sd; diff --git a/fusee/fusee-secondary/src/sdmmc.c b/fusee/fusee-secondary/src/sdmmc.c index 42258ca36..cf88a9fd0 100644 --- a/fusee/fusee-secondary/src/sdmmc.c +++ b/fusee/fusee-secondary/src/sdmmc.c @@ -1,8 +1,9 @@ /** * Fusée SD/MMC driver for the Switch - * ~ktemkin + * ~ktemkin */ - +#include +#include #include #include #include @@ -16,7 +17,6 @@ #include "supplies.h" #include "pmc.h" #include "pad_control.h" -#include "lib/printk.h" #define TEGRA_SDMMC_BASE (0x700B0000) #define TEGRA_SDMMC_SIZE (0x200) @@ -231,7 +231,7 @@ enum sdmmc_command { CMD_SEND_EXT_CSD = 8, CMD_SEND_IF_COND = 8, CMD_SEND_CSD = 9, - CMD_SEND_CID = 10, + CMD_SEND_CID = 10, CMD_STOP_TRANSMISSION = 12, CMD_READ_STATUS = 13, CMD_BUS_TEST = 14, @@ -348,7 +348,7 @@ enum sdmmc_csd_versions { -/** +/** * Positions of different fields in various CSDs. * May eventually be replaced with a bitfield struct, if we use enough of the CSDs. */ @@ -427,9 +427,9 @@ static void mmc_vprint(struct mmc *mmc, char *fmt, int required_loglevel, va_lis if (sdmmc_loglevel < required_loglevel) return; - printk("%s: ", mmc->name); - vprintk(fmt, list); - printk("\n"); + printf("%s: ", mmc->name); + vprintf(fmt, list); + printf("\n"); } @@ -661,7 +661,7 @@ static int sdmmc1_hardware_init(struct mmc *mmc) /** - * Sets up the I/O and clocking resources necessary to use the given controller. + * Sets up the I/O and clocking resources necessary to use the given controller. */ static int sdmmc_setup_controller_clock_and_io(struct mmc *mmc) { @@ -682,7 +682,7 @@ static int sdmmc_setup_controller_clock_and_io(struct mmc *mmc) /** - * Sets up the I/O and clocking resources necessary to use the given controller. + * Sets up the I/O and clocking resources necessary to use the given controller. */ static int sdmmc_enable_supplies(struct mmc *mmc) { @@ -732,7 +732,7 @@ static int sdmmc_set_up_clocking_parameters(struct mmc *mmc) break; default: - printk("ERROR: initialization not yet writen for SDMMC%d", mmc->controller); + printf("ERROR: initialization not yet writen for SDMMC%d", mmc->controller); return ENODEV; } @@ -828,20 +828,20 @@ static int sdmmc_hardware_init(struct mmc *mmc) // Clear PAD_E_INPUT_OR_E_PWRD (relevant for eMMC only) regs->sdmemcomppadctrl &= ~(0x80000000); - + // Set SDHCI_CLOCK_INT_EN regs->clock_control |= 0x01; - + // Program a timeout of 2000ms timebase = get_time(); is_timeout = false; - + // Wait for SDHCI_CLOCK_INT_STABLE to be set while (!(regs->clock_control & 0x02) && !is_timeout) { // Keep checking if timeout expired is_timeout = get_time_since(timebase) > 2000000; } - + // Clock failed to stabilize if (is_timeout) { mmc_print(mmc, "clock never stabalized!"); @@ -856,11 +856,11 @@ static int sdmmc_hardware_init(struct mmc *mmc) // Clear SDHCI_CTRL_SDMA and SDHCI_CTRL_ADMA2 regs->host_control &= 0xE7; - + // Set the timeout to be the maximum value regs->timeout_control &= ~(0x0F); regs->timeout_control |= 0x0E; - + // Clear SDHCI_CTRL_4BITBUS and SDHCI_CTRL_8BITBUS regs->host_control &= 0xFD; regs->host_control &= 0xDF; @@ -878,7 +878,7 @@ static int sdmmc_hardware_init(struct mmc *mmc) // Clear SDHCI_CTRL_HISPD regs->host_control &= 0xFB; - // Clear SDHCI_CTRL_VDD_180 + // Clear SDHCI_CTRL_VDD_180 regs->host_control2 &= ~(0x08); // Set SDHCI_DIVIDER and SDHCI_DIVIDER_HI @@ -983,7 +983,7 @@ static int sdmmc_wait_until_no_longer_busy(struct mmc *mmc) * Blocks until the SD driver has completed issuing a command. * * @param mmc The MMC controller on which to wait. - * @param target_irq A bitmask that specifies the bits that + * @param target_irq A bitmask that specifies the bits that * will make this function return success * @param fault_conditions A bitmask that specifies the bits that * will make this function return EFAULT. @@ -991,7 +991,7 @@ static int sdmmc_wait_until_no_longer_busy(struct mmc *mmc) * @return 0 on sucess, EFAULT if a fault condition occurs, * or an error code if a transfer failure occurs */ -static int sdmmc_wait_for_interrupt(struct mmc *mmc, +static int sdmmc_wait_for_interrupt(struct mmc *mmc, uint32_t target_irq, uint32_t fault_conditions) { uint32_t timebase = get_time(); @@ -1130,7 +1130,7 @@ static int sdmmc_handle_cpu_transfer(struct mmc *mmc, uint16_t blocks, bool is_w * @param auto_termiante True iff we should instruct the system * to reclaim the data lines after a transaction. */ -static void sdmmc_prepare_command_data(struct mmc *mmc, uint16_t blocks, +static void sdmmc_prepare_command_data(struct mmc *mmc, uint16_t blocks, bool is_write, bool auto_terminate, int argument) { if (blocks) { @@ -1182,7 +1182,7 @@ static void sdmmc_prepare_command_data(struct mmc *mmc, uint16_t blocks, static void sdmmc_prepare_command_registers(struct mmc *mmc, int blocks_to_xfer, enum sdmmc_command command, enum sdmmc_response_type response_type, enum sdmmc_response_checks checks) { - // Populate the command number + // Populate the command number uint16_t to_write = (command << MMC_COMMAND_NUMBER_SHIFT) | (response_type << MMC_COMMAND_RESPONSE_TYPE_SHIFT) | checks; // If this is a "stop transmitting" command, set the abort flag. @@ -1301,7 +1301,7 @@ static int sdmmc_handle_command_response(struct mmc *mmc, */ static int sdmmc_send_command(struct mmc *mmc, enum sdmmc_command command, enum sdmmc_response_type response_type, enum sdmmc_response_checks checks, - uint32_t argument, void *response_buffer, uint16_t blocks_to_transfer, + uint32_t argument, void *response_buffer, uint16_t blocks_to_transfer, bool is_write, bool auto_terminate, void *data_buffer) { uint32_t total_data_to_xfer = sdmmc_get_block_size(mmc, is_write) * blocks_to_transfer; @@ -1480,7 +1480,7 @@ static uint32_t sdmmc_extract_csd_bits(uint32_t *csd, int start, int width) // Sanity check our span. if ((start + width) > 128) { - printk("MMC ERROR: invalid CSD slice!\n"); + printf("MMC ERROR: invalid CSD slice!\n"); return 0xFFFFFFFF; } @@ -1585,7 +1585,7 @@ static int sdmmc_read_and_parse_ext_csd(struct mmc *mmc) uint8_t ext_csd[MMC_EXT_CSD_SIZE]; // Read the single EXT CSD block. - rc = sdmmc_send_command(mmc, CMD_SEND_EXT_CSD, MMC_RESPONSE_LEN48, + rc = sdmmc_send_command(mmc, CMD_SEND_EXT_CSD, MMC_RESPONSE_LEN48, MMC_CHECKS_ALL, 0, NULL, 1, false, true, ext_csd); if (rc) { mmc_print(mmc, "ERROR: failed to read the extended CSD!"); @@ -1762,7 +1762,7 @@ static int sdmmc_get_relative_address(struct mmc *mmc) * @param mmc The MMC controller to work with. * @return 0 on success, or an error code on failure. */ -static int sdmmc_get_or_set_relative_address(struct mmc *mmc) +static int sdmmc_get_or_set_relative_address(struct mmc *mmc) { // The SD and MMC specifications handle relative address assignemnt // differently-- delegate accordingly. @@ -1845,7 +1845,7 @@ static int sdmmc_mmc_wait_for_card_readiness(struct mmc *mmc) uint32_t response_masked; // Ask the SD card to identify its state. It will respond with readiness and a capacity magic. - rc = sdmmc_send_command(mmc, CMD_SEND_OPERATING_CONDITIONS, MMC_RESPONSE_LEN48, + rc = sdmmc_send_command(mmc, CMD_SEND_OPERATING_CONDITIONS, MMC_RESPONSE_LEN48, MMC_CHECKS_NONE, 0x40000080, response, 0, false, false, NULL); if (rc) { mmc_print(mmc, "ERROR: could not read the card's operating conditions!"); @@ -2044,7 +2044,7 @@ static int sdmmc_sd_card_init(struct mmc *mmc) * * @param mmc The device to initialize. */ -static int sdmmc_handle_card_type_init(struct mmc *mmc) +static int sdmmc_handle_card_type_init(struct mmc *mmc) { int rc; @@ -2140,7 +2140,7 @@ static int sdmmc_wait_for_card_ready(struct mmc *mmc, uint32_t timeout) static int sdmmc_switch_mode(struct mmc *mmc, enum sdmmc_switch_access_mode mode, enum sdmmc_switch_field field, uint16_t value, uint32_t timeout) { // Collapse our various parameters into a single argument. - uint32_t argument = + uint32_t argument = (mode << MMC_SWITCH_ACCESS_MODE_SHIFT) | (field << MMC_SWITCH_FIELD_SHIFT) | (value << MMC_SWITCH_VALUE_SHIFT); @@ -2205,7 +2205,7 @@ static void sdmmc_initialize_defaults(struct mmc *mmc) break; default: - printk("ERROR: initialization not yet writen for SDMMC%d", mmc->controller); + printf("ERROR: initialization not yet writen for SDMMC%d", mmc->controller); break; } } diff --git a/fusee/fusee-secondary/src/splash_screen.c b/fusee/fusee-secondary/src/splash_screen.c index 3170d5b80..51276d37e 100644 --- a/fusee/fusee-secondary/src/splash_screen.c +++ b/fusee/fusee-secondary/src/splash_screen.c @@ -1,15 +1,15 @@ +#include #include "utils.h" #include "timers.h" #include "splash_screen.h" #include "sd_utils.h" -#include "lib/printk.h" #include "display/video_fb.h" void display_splash_screen_bmp(const char *custom_splash_path) { uint8_t *splash_screen = g_default_splash_screen; if (custom_splash_path != NULL && custom_splash_path[0] != '\x00') { if (!read_sd_file(splash_screen, sizeof(g_default_splash_screen), custom_splash_path)) { - printk("Error: Failed to read custom splash screen from %s!\n", custom_splash_path); + printf("Error: Failed to read custom splash screen from %s!\n", custom_splash_path); generic_panic(); } } diff --git a/fusee/fusee-secondary/src/stratosphere.c b/fusee/fusee-secondary/src/stratosphere.c index e35790a72..095abab81 100644 --- a/fusee/fusee-secondary/src/stratosphere.c +++ b/fusee/fusee-secondary/src/stratosphere.c @@ -3,7 +3,6 @@ #include "package2.h" #include "stratosphere.h" #include "sd_utils.h" -#include "lib/printk.h" unsigned char g_stratosphere_ini1[PACKAGE2_SIZE_MAX]; static bool g_initialized_stratosphere_ini1 = false; @@ -32,7 +31,7 @@ size_t stratosphere_merge_inis(void *dst, ini1_header_t **inis, unsigned int num /* Validate all ini headers. */ for (unsigned int i = 0; i < num_inis; i++) { if (inis[i] == NULL || inis[i]->magic != MAGIC_INI1 || inis[i]->num_processes > INI1_MAX_KIPS) { - printk("Error: INI1s[%d] section appears to not contain an INI1!\n", i); + printf("Error: INI1s[%d] section appears to not contain an INI1!\n", i); generic_panic(); } } @@ -54,7 +53,7 @@ size_t stratosphere_merge_inis(void *dst, ini1_header_t **inis, unsigned int num for (unsigned int p = 0; p < inis[i]->num_processes; p++) { kip1_header_t *current_kip = (kip1_header_t *)(inis[i]->kip_data + offset); if (current_kip->magic != MAGIC_KIP1) { - printk("Error: INI1s[%d][%d] appears not to be a KIP1!\n", i, p); + printf("Error: INI1s[%d][%d] appears not to be a KIP1!\n", i, p); generic_panic(); } @@ -71,16 +70,16 @@ size_t stratosphere_merge_inis(void *dst, ini1_header_t **inis, unsigned int num } /* TODO: What folder should these be read out of? */ - snprintf(sd_path, sizeof(sd_path), "atmosph\xe8re/titles/%016llx/%016llx.kip", current_kip->title_id, current_kip->title_id); + snprintf(sd_path, sizeof(sd_path), "atmosphere/titles/%016llx/%016llx.kip", current_kip->title_id, current_kip->title_id); /* Try to load an override KIP from SD, if possible. */ if (read_sd_file(current_dst_kip, remaining_size, sd_path)) { kip1_header_t *sd_kip = (kip1_header_t *)(current_dst_kip); if (sd_kip->magic != MAGIC_KIP1) { - printk("Error: %s is not a KIP1?\n", sd_path); + printf("Error: %s is not a KIP1?\n", sd_path); generic_panic(); } else if (sd_kip->title_id != current_kip->title_id) { - printk("Error: %s has wrong Title ID!\n", sd_path); + printf("Error: %s has wrong Title ID!\n", sd_path); generic_panic(); } uint64_t sd_kip_size = kip1_get_size_from_header(sd_kip); @@ -89,7 +88,7 @@ size_t stratosphere_merge_inis(void *dst, ini1_header_t **inis, unsigned int num } else { uint64_t current_kip_size = kip1_get_size_from_header(current_kip); if (current_kip_size > remaining_size) { - printk("Error: Not enough space for all the KIP1s!\n"); + printf("Error: Not enough space for all the KIP1s!\n"); generic_panic(); } memcpy(current_dst_kip, current_kip, current_kip_size); diff --git a/fusee/fusee-secondary/src/supplies.c b/fusee/fusee-secondary/src/supplies.c index 821267f44..6276e2256 100644 --- a/fusee/fusee-secondary/src/supplies.c +++ b/fusee/fusee-secondary/src/supplies.c @@ -3,8 +3,8 @@ * ~ktemkin */ +#include #include "supplies.h" -#include "lib/printk.h" // FIXME: replace hwinit with our own code #include "hwinit/max7762x.h" @@ -23,7 +23,7 @@ void supply_enable(enum switch_power_supply supply) return; default: - printk("ERROR: could not enable unknown supply %d!\n", supply); + printf("ERROR: could not enable unknown supply %d!\n", supply); return; } }