From 011a1b94aa6c60b437ae2cf85ce5fffc4cd23498 Mon Sep 17 00:00:00 2001 From: Ross Philipson Date: Fri, 20 Aug 2021 16:27:02 -0400 Subject: [PATCH] tb_ -> sk_ Signed-off-by: Ross Philipson --- trenchboot/skboot/common/cmdline.c | 68 +++++++++++++++--------------- trenchboot/skboot/common/linux.c | 26 ++++++------ trenchboot/skboot/common/loader.c | 28 ++++++------ trenchboot/skboot/common/printk.c | 6 +-- trenchboot/skboot/common/sha1.c | 14 +++--- trenchboot/skboot/common/sha256.c | 2 +- trenchboot/skboot/common/skboot.c | 8 ++-- trenchboot/skboot/common/skl.c | 2 +- trenchboot/skboot/common/string.c | 32 +++++++------- trenchboot/skboot/common/tpm.c | 14 +++--- trenchboot/skboot/common/tpm_12.c | 12 +++--- trenchboot/skboot/common/vga.c | 2 +- trenchboot/skboot/include/string.h | 30 ++++++------- trenchboot/skboot/include/tpm.h | 4 +- 14 files changed, 124 insertions(+), 124 deletions(-) diff --git a/trenchboot/skboot/common/cmdline.c b/trenchboot/skboot/common/cmdline.c index 4c31db8..05b89a0 100644 --- a/trenchboot/skboot/common/cmdline.c +++ b/trenchboot/skboot/common/cmdline.c @@ -89,10 +89,10 @@ static char g_linux_param_values[ARRAY_SIZE(g_linux_cmdline_options)][MAX_VALUE_ typedef struct { const char *log_name; uint8_t log_val; -} tb_loglvl_map_t; +} sk_loglvl_map_t; /* map */ -static const tb_loglvl_map_t g_loglvl_map[] = { +static const sk_loglvl_map_t g_loglvl_map[] = { { "none", SKBOOT_LOG_LEVEL_NONE }, { "err", SKBOOT_LOG_LEVEL_ERR }, { "warn", SKBOOT_LOG_LEVEL_WARN }, @@ -104,7 +104,7 @@ static const tb_loglvl_map_t g_loglvl_map[] = { static const char* get_option_val(const cmdline_option_t *options, char vals[][MAX_VALUE_LEN], const char *opt_name) { for ( int i = 0; options[i].name != NULL; i++ ) { - if ( tb_strcmp(options[i].name, opt_name) == 0 ) + if ( sk_strcmp(options[i].name, opt_name) == 0 ) return vals[i]; } printk(SKBOOT_ERR"requested unknown option: %s\n", opt_name); @@ -119,7 +119,7 @@ static void cmdline_parse(const char *cmdline, const cmdline_option_t *options, /* copy default values to vals[] */ for ( i = 0; options[i].name != NULL; i++ ) { - tb_strncpy(vals[i], options[i].def_val, MAX_VALUE_LEN-1); + sk_strncpy(vals[i], options[i].def_val, MAX_VALUE_LEN-1); vals[i][MAX_VALUE_LEN-1] = '\0'; } @@ -137,13 +137,13 @@ static void cmdline_parse(const char *cmdline, const cmdline_option_t *options, /* find end of current option */ const char *opt_start = p; - const char *opt_end = tb_strchr(opt_start, ' '); + const char *opt_end = sk_strchr(opt_start, ' '); if ( opt_end == NULL ) - opt_end = opt_start + tb_strlen(opt_start); + opt_end = opt_start + sk_strlen(opt_start); p = opt_end; /* find value part; if no value found, use default and continue */ - const char *val_start = tb_strchr(opt_start, '='); + const char *val_start = sk_strchr(opt_start, '='); if ( val_start == NULL || val_start > opt_end ) continue; val_start++; @@ -157,8 +157,8 @@ static void cmdline_parse(const char *cmdline, const cmdline_option_t *options, /* value found, so copy it */ for ( i = 0; options[i].name != NULL; i++ ) { - if ( tb_strncmp(options[i].name, opt_start, opt_name_size ) == 0 ) { - tb_strncpy(vals[i], val_start, copy_size); + if ( sk_strncmp(options[i].name, opt_start, opt_name_size ) == 0 ) { + sk_strncpy(vals[i], val_start, copy_size); vals[i][copy_size] = '\0'; /* add '\0' to the end of string */ break; } @@ -209,9 +209,9 @@ void get_skboot_loglvl(void) unsigned int i; for ( i = 0; i < ARRAY_SIZE(g_loglvl_map); i++ ) { - if ( tb_strncmp(loglvl, g_loglvl_map[i].log_name, - tb_strlen(g_loglvl_map[i].log_name)) == 0 ) { - loglvl += tb_strlen(g_loglvl_map[i].log_name); + if ( sk_strncmp(loglvl, g_loglvl_map[i].log_name, + sk_strlen(g_loglvl_map[i].log_name)) == 0 ) { + loglvl += sk_strlen(g_loglvl_map[i].log_name); if ( g_loglvl_map[i].log_val == SKBOOT_LOG_LEVEL_NONE ) { g_log_level = SKBOOT_LOG_LEVEL_NONE; @@ -245,7 +245,7 @@ void get_skboot_log_targets(void) return; /* determine if no targets set explicitly */ - if ( tb_strcmp(targets, "none") == 0 ) { + if ( sk_strcmp(targets, "none") == 0 ) { g_log_targets = SKBOOT_LOG_TARGET_NONE; /* print nothing */ return; } @@ -254,15 +254,15 @@ void get_skboot_log_targets(void) g_log_targets = SKBOOT_LOG_TARGET_NONE; while ( *targets != '\0' ) { - if ( tb_strncmp(targets, "memory", 6) == 0 ) { + if ( sk_strncmp(targets, "memory", 6) == 0 ) { g_log_targets |= SKBOOT_LOG_TARGET_MEMORY; targets += 6; } - else if ( tb_strncmp(targets, "serial", 6) == 0 ) { + else if ( sk_strncmp(targets, "serial", 6) == 0 ) { g_log_targets |= SKBOOT_LOG_TARGET_SERIAL; targets += 6; } - else if ( tb_strncmp(targets, "vga", 3) == 0 ) { + else if ( sk_strncmp(targets, "vga", 3) == 0 ) { g_log_targets |= SKBOOT_LOG_TARGET_VGA; targets += 3; } @@ -279,15 +279,15 @@ void get_skboot_log_targets(void) static bool parse_pci_bdf(const char **bdf, uint32_t *bus, uint32_t *slot, uint32_t *func) { - *bus = tb_strtoul(*bdf, (char **)bdf, 16); + *bus = sk_strtoul(*bdf, (char **)bdf, 16); if ( **bdf != ':' ) return false; (*bdf)++; - *slot = tb_strtoul(*bdf, (char **)bdf, 16); + *slot = sk_strtoul(*bdf, (char **)bdf, 16); if ( **bdf != '.' ) return false; (*bdf)++; - *func = tb_strtoul(*bdf, (char **)bdf, 16); + *func = sk_strtoul(*bdf, (char **)bdf, 16); return true; } @@ -327,7 +327,7 @@ static bool parse_com_fmt(const char **fmt) /* must specify all values */ - if ( tb_strlen(*fmt) < 3 ) + if ( sk_strlen(*fmt) < 3 ) return false; /* data bits */ @@ -360,7 +360,7 @@ static bool parse_com_fmt(const char **fmt) static bool parse_serial_param(const char *com) { /* parse baud */ - g_com_port.comc_curspeed = tb_strtoul(com, (char **)&com, 10); + g_com_port.comc_curspeed = sk_strtoul(com, (char **)&com, 10); if ( (g_com_port.comc_curspeed < 1200) || (g_com_port.comc_curspeed > 115200) ) return false; @@ -368,7 +368,7 @@ static bool parse_serial_param(const char *com) /* parse clock hz */ if ( *com == '/' ) { ++com; - g_com_port.comc_clockhz = tb_strtoul(com, (char **)&com, 0) << 4; + g_com_port.comc_clockhz = sk_strtoul(com, (char **)&com, 0) << 4; if ( g_com_port.comc_clockhz == 0 ) return false; } @@ -386,7 +386,7 @@ static bool parse_serial_param(const char *com) if ( *com != ',' ) goto exit; ++com; - g_com_port.comc_port = tb_strtoul(com, (char **)&com, 0); + g_com_port.comc_port = sk_strtoul(com, (char **)&com, 0); if ( g_com_port.comc_port == 0 ) return false; @@ -394,7 +394,7 @@ static bool parse_serial_param(const char *com) if ( *com != ',' ) goto exit; ++com; - g_com_port.comc_irq = tb_strtoul(com, (char **)&com, 10); + g_com_port.comc_irq = sk_strtoul(com, (char **)&com, 10); if ( g_com_port.comc_irq == 0 ) return false; @@ -433,7 +433,7 @@ void get_skboot_vga_delay(void) if ( vga_delay == NULL ) return; - g_vga_delay = tb_strtoul(vga_delay, NULL, 0); + g_vga_delay = sk_strtoul(vga_delay, NULL, 0); } extern uint32_t g_min_ram; @@ -444,7 +444,7 @@ void get_skboot_min_ram(void) if ( min_ram == NULL ) return; - g_min_ram = tb_strtoul(min_ram, NULL, 0); + g_min_ram = sk_strtoul(min_ram, NULL, 0); } uint32_t get_error_shutdown(void) @@ -454,11 +454,11 @@ uint32_t get_error_shutdown(void) g_skboot_param_values, "error_shutdown"); if ( error_shutdown != NULL ) { - if ( tb_strcmp(error_shutdown, "reboot") == 0 ) + if ( sk_strcmp(error_shutdown, "reboot") == 0 ) return SK_SHUTDOWN_REBOOT; - if ( tb_strcmp(error_shutdown, "shutdown") == 0 ) + if ( sk_strcmp(error_shutdown, "shutdown") == 0 ) return SK_SHUTDOWN_SHUTDOWN; - if ( tb_strcmp(error_shutdown, "halt") == 0 ) + if ( sk_strcmp(error_shutdown, "halt") == 0 ) return SK_SHUTDOWN_HALT; } @@ -477,14 +477,14 @@ bool get_linux_vga(int *vid_mode) if ( vga == NULL || vid_mode == NULL ) return false; - if ( tb_strcmp(vga, "normal") == 0 ) + if ( sk_strcmp(vga, "normal") == 0 ) *vid_mode = 0xFFFF; - else if ( tb_strcmp(vga, "ext") == 0 ) + else if ( sk_strcmp(vga, "ext") == 0 ) *vid_mode = 0xFFFE; - else if ( tb_strcmp(vga, "ask") == 0 ) + else if ( sk_strcmp(vga, "ask") == 0 ) *vid_mode = 0xFFFD; else - *vid_mode = tb_strtoul(vga, NULL, 0); + *vid_mode = sk_strtoul(vga, NULL, 0); return true; } @@ -497,7 +497,7 @@ bool get_linux_mem(uint64_t *max_mem) if ( mem == NULL || max_mem == NULL ) return false; - *max_mem = tb_strtoul(mem, &last, 0); + *max_mem = sk_strtoul(mem, &last, 0); if ( *max_mem == 0 ) return false; diff --git a/trenchboot/skboot/common/linux.c b/trenchboot/skboot/common/linux.c index 5b38ff4..aa1cc96 100644 --- a/trenchboot/skboot/common/linux.c +++ b/trenchboot/skboot/common/linux.c @@ -60,11 +60,11 @@ printk_long(const char *what) { /* chunk the command line into 70 byte chunks */ #define CHUNK_SIZE 70 - int cmdlen = tb_strlen(what); + int cmdlen = sk_strlen(what); const char *cptr = what; char cmdchunk[CHUNK_SIZE+1]; while (cmdlen > 0) { - tb_strncpy(cmdchunk, cptr, CHUNK_SIZE); + sk_strncpy(cmdchunk, cptr, CHUNK_SIZE); cmdchunk[CHUNK_SIZE] = 0; printk(SKBOOT_INFO"\t%s\n", cmdchunk); cmdlen -= CHUNK_SIZE; @@ -220,7 +220,7 @@ bool expand_linux_image(const void *linux_image, size_t linux_size, } } - tb_memmove((void *)initrd_base, initrd_image, initrd_size); + sk_memmove((void *)initrd_base, initrd_image, initrd_size); printk(SKBOOT_DETA"Initrd from 0x%lx to 0x%lx\n", (unsigned long)initrd_base, (unsigned long)(initrd_base + initrd_size)); @@ -305,17 +305,17 @@ bool expand_linux_image(const void *linux_image, size_t linux_size, } /* save linux header struct to temp memory to copy changes to zero page */ - tb_memmove(&temp_hdr, hdr, sizeof(temp_hdr)); + sk_memmove(&temp_hdr, hdr, sizeof(temp_hdr)); /* load real-mode part */ - tb_memmove((void *)real_mode_base, linux_image, real_mode_size); + sk_memmove((void *)real_mode_base, linux_image, real_mode_size); printk(SKBOOT_DETA"Kernel (real mode) from 0x%lx to 0x%lx size: 0x%lx\n", (unsigned long)linux_image, (unsigned long)real_mode_base, (unsigned long)real_mode_size); /* load protected-mode part */ - tb_memmove((void *)protected_mode_base, linux_image + real_mode_size, + sk_memmove((void *)protected_mode_base, linux_image + real_mode_size, protected_mode_size); printk(SKBOOT_DETA"Kernel (protected mode) from 0x%lx to 0x%lx size: 0x%lx\n", (unsigned long)(linux_image + real_mode_size), @@ -326,7 +326,7 @@ bool expand_linux_image(const void *linux_image, size_t linux_size, hdr = (linux_kernel_header_t *)(real_mode_base + KERNEL_HEADER_OFFSET); /* copy back the updated kernel header */ - tb_memmove(hdr, &temp_hdr, sizeof(temp_hdr)); + sk_memmove(hdr, &temp_hdr, sizeof(temp_hdr)); /* set cmd_line_ptr */ hdr->cmd_line_ptr = real_mode_base + KERNEL_CMDLINE_OFFSET; @@ -338,11 +338,11 @@ bool expand_linux_image(const void *linux_image, size_t linux_size, return false; } const size_t kernel_cmdline_size = REAL_END_OFFSET - KERNEL_CMDLINE_OFFSET; - size_t kernel_cmdline_strlen = tb_strlen(kernel_cmdline); + size_t kernel_cmdline_strlen = sk_strlen(kernel_cmdline); if (kernel_cmdline_strlen > kernel_cmdline_size - 1) kernel_cmdline_strlen = kernel_cmdline_size - 1; - tb_memset((void *)hdr->cmd_line_ptr, 0, kernel_cmdline_size); - tb_memcpy((void *)hdr->cmd_line_ptr, kernel_cmdline, kernel_cmdline_strlen); + sk_memset((void *)hdr->cmd_line_ptr, 0, kernel_cmdline_size); + sk_memcpy((void *)hdr->cmd_line_ptr, kernel_cmdline, kernel_cmdline_strlen); printk(SKBOOT_INFO"Linux cmdline from 0x%lx to 0x%lx:\n", (unsigned long)hdr->cmd_line_ptr, @@ -380,7 +380,7 @@ bool expand_linux_image(const void *linux_image, size_t linux_size, uint32_t descr_size = 0, descr_vers = 0, mmap_size = 0, efi_mmap_addr = 0; /* loader signature */ - tb_memcpy(&efi->efi_ldr_sig, "EL64", sizeof(uint32_t)); + sk_memcpy(&efi->efi_ldr_sig, "EL64", sizeof(uint32_t)); /* EFI system table addr */ { @@ -459,8 +459,8 @@ bool expand_linux_image(const void *linux_image, size_t linux_size, } /* Clear out some boot_params we don't want dangling around */ - tb_memset((void *)boot_params->skboot_shared_addr, 0, 8); - tb_memset((void *)boot_params->acpi_rsdp_addr, 0, 8); + sk_memset((void *)boot_params->skboot_shared_addr, 0, 8); + sk_memset((void *)boot_params->acpi_rsdp_addr, 0, 8); /* Copy all the handoff information about the loaded IL kernel */ g_il_kernel_setup.real_mode_base = real_mode_base; diff --git a/trenchboot/skboot/common/loader.c b/trenchboot/skboot/common/loader.c index e489438..8b859ed 100644 --- a/trenchboot/skboot/common/loader.c +++ b/trenchboot/skboot/common/loader.c @@ -73,11 +73,11 @@ printk_long(char *what) { /* chunk the command line into 70 byte chunks */ #define CHUNK_SIZE 70 - int cmdlen = tb_strlen(what); + int cmdlen = sk_strlen(what); char *cptr = what; char cmdchunk[CHUNK_SIZE+1]; while (cmdlen > 0) { - tb_strncpy(cmdchunk, cptr, CHUNK_SIZE); + sk_strncpy(cmdchunk, cptr, CHUNK_SIZE); cmdchunk[CHUNK_SIZE] = 0; printk(SKBOOT_INFO"\t%s\n", cmdchunk); cmdlen -= CHUNK_SIZE; @@ -174,13 +174,13 @@ void print_mbi(const multiboot_info_t *mbi) if ( mbi->flags & MBI_CMDLINE ) { # define CHUNK_SIZE 72 /* Break the command line up into 72 byte chunks */ - int cmdlen = tb_strlen(mbi->cmdline); + int cmdlen = sk_strlen(mbi->cmdline); char *cmdptr = (char *)mbi->cmdline; char chunk[CHUNK_SIZE+1]; printk(SKBOOT_DETA"\t cmdline@0x%x: ", mbi->cmdline); chunk[CHUNK_SIZE] = '\0'; while (cmdlen > 0) { - tb_strncpy(chunk, cmdptr, CHUNK_SIZE); + sk_strncpy(chunk, cmdptr, CHUNK_SIZE); printk(SKBOOT_DETA"\n\t\"%s\"", chunk); cmdptr += CHUNK_SIZE; cmdlen -= CHUNK_SIZE; @@ -379,7 +379,7 @@ static void *remove_module(loader_ctx *lctx, void *mod_start) } /* copy remaing mods down by one */ - tb_memmove(m, m + 1, (mbi->mods_count - i - 1)*sizeof(module_t)); + sk_memmove(m, m + 1, (mbi->mods_count - i - 1)*sizeof(module_t)); mbi->mods_count--; @@ -402,10 +402,10 @@ static void *remove_module(loader_ctx *lctx, void *mod_start) printk(SKBOOT_ERR"could not find module cmdline\n"); return NULL; } - if ((tb_strlen(mod_string)) > (tb_strlen(cmdline))){ - if (tb_strlen(mod_string) >= SKBOOT_KERNEL_CMDLINE_SIZE){ + if ((sk_strlen(mod_string)) > (sk_strlen(cmdline))){ + if (sk_strlen(mod_string) >= SKBOOT_KERNEL_CMDLINE_SIZE){ printk(SKBOOT_ERR"No room to copy MB2 cmdline [%d < %d]\n", - (int)(tb_strlen(cmdline)), (int)(tb_strlen(mod_string))); + (int)(sk_strlen(cmdline)), (int)(sk_strlen(mod_string))); } else { char *s = mod_string; char *d = cmdbuf; @@ -482,7 +482,7 @@ static void *remove_module(loader_ctx *lctx, void *mod_start) return NULL; } - grow_mb2_tag(lctx, cur, tb_strlen(cmdbuf) - tb_strlen(cmd->string)); + grow_mb2_tag(lctx, cur, sk_strlen(cmdbuf) - sk_strlen(cmd->string)); /* now we're all good, except for fixing up cmd */ { @@ -533,7 +533,7 @@ find_module_by_pattern(loader_ctx *lctx, void **base, size_t *size, } for ( unsigned int j = 0; j < (mod_size + len); j++ ) { - if ( tb_memcmp((void *)(m->mod_start + j), pattern, len) == 0 ) { + if ( sk_memcmp((void *)(m->mod_start + j), pattern, len) == 0 ) { *base = (void *)m->mod_start; if ( size != NULL ) *size = mod_size; @@ -556,7 +556,7 @@ unsigned long get_mbi_mem_end_mb1(const multiboot_info_t *mbi) unsigned long end = (unsigned long)(mbi + 1); if ( mbi->flags & MBI_CMDLINE ) - end = max(end, mbi->cmdline + tb_strlen((char *)mbi->cmdline) + 1); + end = max(end, mbi->cmdline + sk_strlen((char *)mbi->cmdline) + 1); if ( mbi->flags & MBI_MODULES ) { end = max(end, mbi->mods_addr + mbi->mods_count * sizeof(module_t)); unsigned int i; @@ -564,7 +564,7 @@ unsigned long get_mbi_mem_end_mb1(const multiboot_info_t *mbi) module_t *p = get_module_mb1(mbi, i); if ( p == NULL ) break; - end = max(end, p->string + tb_strlen((char *)p->string) + 1); + end = max(end, p->string + sk_strlen((char *)p->string) + 1); } } if ( mbi->flags & MBI_AOUT ) { @@ -585,7 +585,7 @@ unsigned long get_mbi_mem_end_mb1(const multiboot_info_t *mbi) /* GET CONFIGURATION bios call", so skip it */ if ( mbi->flags & MBI_BTLDNAME ) end = max(end, mbi->boot_loader_name - + tb_strlen((char *)mbi->boot_loader_name) + 1); + + sk_strlen((char *)mbi->boot_loader_name) + 1); if ( mbi->flags & MBI_APM ) /* per Grub-multiboot-Main Part2 Rev94-Structures, apm size is 20 */ end = max(end, mbi->apm_table + 20); @@ -1129,7 +1129,7 @@ void determine_loader_type(void *addr, uint32_t magic) * image. */ mb2_reloc = (void*)PAGE_DOWN(SKBOOT_BASE_ADDR - g_mb_orig_size); - tb_memcpy(mb2_reloc, addr, g_mb_orig_size); + sk_memcpy(mb2_reloc, addr, g_mb_orig_size); g_ldr_ctx->addr = mb2_reloc; addr = mb2_reloc; printk(SKBOOT_INFO"MB2 relocated to: %p size: %x\n", diff --git a/trenchboot/skboot/common/printk.c b/trenchboot/skboot/common/printk.c index aac8b23..7427fa7 100644 --- a/trenchboot/skboot/common/printk.c +++ b/trenchboot/skboot/common/printk.c @@ -79,7 +79,7 @@ static void memlog_write(const char *str, unsigned int count) if ( g_log->curr_pos + count > g_log->max_size ) g_log->curr_pos = 0; - tb_memcpy(&g_log->buf[g_log->curr_pos], str, count); + sk_memcpy(&g_log->buf[g_log->curr_pos], str, count); g_log->curr_pos += count; /* if the string wasn't NULL-terminated, then NULL-terminate the log */ @@ -130,9 +130,9 @@ void printk(const char *fmt, ...) uint8_t log_level; static bool last_line_cr = true; - tb_memset(buf, '\0', sizeof(buf)); + sk_memset(buf, '\0', sizeof(buf)); va_start(ap, fmt); - n = tb_vscnprintf(buf, sizeof(buf), fmt, ap); + n = sk_vscnprintf(buf, sizeof(buf), fmt, ap); log_level = get_loglvl_prefix(&pbuf, &n); diff --git a/trenchboot/skboot/common/sha1.c b/trenchboot/skboot/common/sha1.c index c898481..c3067f8 100644 --- a/trenchboot/skboot/common/sha1.c +++ b/trenchboot/skboot/common/sha1.c @@ -111,7 +111,7 @@ static void sha1_step(struct sha1_ctxt *ctxt) #if LITTLE_ENDIAN struct sha1_ctxt tctxt; - tb_memcpy(&tctxt.m.b8[0], &ctxt->m.b8[0], 64); + sk_memcpy(&tctxt.m.b8[0], &ctxt->m.b8[0], 64); ctxt->m.b8[0] = tctxt.m.b8[3]; ctxt->m.b8[1] = tctxt.m.b8[2]; ctxt->m.b8[2] = tctxt.m.b8[1]; ctxt->m.b8[3] = tctxt.m.b8[0]; ctxt->m.b8[4] = tctxt.m.b8[7]; ctxt->m.b8[5] = tctxt.m.b8[6]; @@ -181,14 +181,14 @@ static void sha1_step(struct sha1_ctxt *ctxt) H(3) = H(3) + d; H(4) = H(4) + e; - tb_memset(&ctxt->m.b8[0],0, 64); + sk_memset(&ctxt->m.b8[0],0, 64); } /*------------------------------------------------------------*/ static void sha1_init(struct sha1_ctxt *ctxt) { - tb_memset(ctxt,0, sizeof(struct sha1_ctxt)); + sk_memset(ctxt,0, sizeof(struct sha1_ctxt)); H(0) = 0x67452301; H(1) = 0xefcdab89; H(2) = 0x98badcfe; @@ -206,14 +206,14 @@ static void sha1_pad(struct sha1_ctxt *ctxt) padstart = COUNT % 64; padlen = 64 - padstart; if (padlen < 8) { - tb_memset(&ctxt->m.b8[padstart],0, padlen); + sk_memset(&ctxt->m.b8[padstart],0, padlen); COUNT += padlen; COUNT %= 64; sha1_step(ctxt); padstart = COUNT % 64; /* should be 0 */ padlen = 64 - padstart; /* should be 64 */ } - tb_memset(&ctxt->m.b8[padstart],0, padlen - 8); + sk_memset(&ctxt->m.b8[padstart],0, padlen - 8); COUNT += (padlen - 8); COUNT %= 64; #if BIG_ENDIAN @@ -243,7 +243,7 @@ static void sha1_loop(struct sha1_ctxt *ctxt,const uint8_t *input,size_t len) gaplen = 64 - gapstart; copysiz = (gaplen < len - off) ? gaplen : len - off; - tb_memcpy(&ctxt->m.b8[gapstart],&input[off], copysiz); + sk_memcpy(&ctxt->m.b8[gapstart],&input[off], copysiz); COUNT += copysiz; COUNT %= 64; ctxt->c.b64[0] += copysiz * 8; @@ -259,7 +259,7 @@ static void sha1_result(struct sha1_ctxt *ctxt,unsigned char *digest0) digest = (uint8_t *)digest0; sha1_pad(ctxt); #if BIG_ENDIAN - tb_memcpy(digest, &ctxt->h.b8[0],20); + sk_memcpy(digest, &ctxt->h.b8[0],20); #else digest[0] = ctxt->h.b8[3]; digest[1] = ctxt->h.b8[2]; digest[2] = ctxt->h.b8[1]; digest[3] = ctxt->h.b8[0]; diff --git a/trenchboot/skboot/common/sha256.c b/trenchboot/skboot/common/sha256.c index 2c8d18a..172fa65 100644 --- a/trenchboot/skboot/common/sha256.c +++ b/trenchboot/skboot/common/sha256.c @@ -162,7 +162,7 @@ static int sha256_process(sha256_state * md, const unsigned char *in, unsigned l inlen -= SHA256_BLOCK_SIZE; } else { n = MIN(inlen, (SHA256_BLOCK_SIZE - md->curlen)); - tb_memcpy(md->buf + md->curlen, in, (size_t)n); + sk_memcpy(md->buf + md->curlen, in, (size_t)n); md->curlen += n; in += n; inlen -= n; diff --git a/trenchboot/skboot/common/skboot.c b/trenchboot/skboot/common/skboot.c index d49aa84..7d68ae1 100644 --- a/trenchboot/skboot/common/skboot.c +++ b/trenchboot/skboot/common/skboot.c @@ -75,9 +75,9 @@ static void shutdown_system(uint32_t shutdown_type) /* the case in SLBOOT */ if ( shutdown_type >= ARRAY_SIZE(types) ) - tb_snprintf(type, sizeof(type), "unknown: %u", shutdown_type); + sk_snprintf(type, sizeof(type), "unknown: %u", shutdown_type); else { - tb_strncpy(type, types[shutdown_type], sizeof(type)); + sk_strncpy(type, types[shutdown_type], sizeof(type)); type[sizeof(type) - 1] = '\0'; } printk(SKBOOT_INFO"shutdown_system() called for shutdown_type: %s\n", type); @@ -232,9 +232,9 @@ void begin_launch(void *addr, uint32_t magic) determine_loader_type(addr, magic); cmdline = get_cmdline(g_ldr_ctx); - tb_memset(g_cmdline, '\0', sizeof(g_cmdline)); + sk_memset(g_cmdline, '\0', sizeof(g_cmdline)); if ( cmdline ) - tb_strncpy(g_cmdline, cmdline, sizeof(g_cmdline)-1); + sk_strncpy(g_cmdline, cmdline, sizeof(g_cmdline)-1); /* always parse cmdline */ skboot_parse_cmdline(); diff --git a/trenchboot/skboot/common/skl.c b/trenchboot/skboot/common/skl.c index 1284b81..ddcb016 100644 --- a/trenchboot/skboot/common/skl.c +++ b/trenchboot/skboot/common/skl.c @@ -34,7 +34,7 @@ bool is_skl_module(const void *skl_base, uint32_t skl_size) return false; } - if (tb_memcmp(info->uuid, lz_info.uuid, 16)) { + if (sk_memcmp(info->uuid, lz_info.uuid, 16)) { printk(SKBOOT_INFO"Possible SKL module incorrect UUID\n"); return false; } diff --git a/trenchboot/skboot/common/string.c b/trenchboot/skboot/common/string.c index acbb7cf..241cc8f 100644 --- a/trenchboot/skboot/common/string.c +++ b/trenchboot/skboot/common/string.c @@ -244,7 +244,7 @@ static size_t int2str(long long val, char *str, size_t strlen, return length; } -int tb_vscnprintf(char *buf, size_t size, const char *fmt, va_list ap) +int sk_vscnprintf(char *buf, size_t size, const char *fmt, va_list ap) { unsigned int buf_pos = 0; /* return value doesn't count the last '\0' */ const char *fmt_ptr; @@ -258,7 +258,7 @@ int tb_vscnprintf(char *buf, size_t size, const char *fmt, va_list ap) if ( fmt == NULL ) return 0; - tb_memset(&mods, 0, sizeof(mods)); + sk_memset(&mods, 0, sizeof(mods)); while ( buf_pos < size ) { bool success; @@ -311,7 +311,7 @@ int tb_vscnprintf(char *buf, size_t size, const char *fmt, va_list ap) fmt_ptr++; } else - mods.width = tb_strtoul(fmt_ptr, (char **)&fmt_ptr, 10); + mods.width = sk_strtoul(fmt_ptr, (char **)&fmt_ptr, 10); if ( *fmt_ptr == '.' ) { /* skip . */ @@ -323,7 +323,7 @@ int tb_vscnprintf(char *buf, size_t size, const char *fmt, va_list ap) fmt_ptr++; } else - mods.precision = tb_strtoul(fmt_ptr, (char **)&fmt_ptr, 10); + mods.precision = sk_strtoul(fmt_ptr, (char **)&fmt_ptr, 10); } /* parsing qualifier: h l L; @@ -378,7 +378,7 @@ int tb_vscnprintf(char *buf, size_t size, const char *fmt, va_list ap) str[0] = (char)va_arg(ap, int); mods.digit = false; buf_pos = write_string_to_buffer( - buf, size, buf_pos, str, tb_strlen(str), &mods); + buf, size, buf_pos, str, sk_strlen(str), &mods); break; } case 's': @@ -388,7 +388,7 @@ int tb_vscnprintf(char *buf, size_t size, const char *fmt, va_list ap) str = va_arg(ap, char *); mods.digit = false; buf_pos = write_string_to_buffer( - buf, size, buf_pos, str, tb_strlen(str), &mods); + buf, size, buf_pos, str, sk_strlen(str), &mods); break; } case 'o': @@ -445,11 +445,11 @@ int tb_vscnprintf(char *buf, size_t size, const char *fmt, va_list ap) return buf_pos - 1; } -int tb_snprintf(char *buf, size_t size, const char *fmt, ...) +int sk_snprintf(char *buf, size_t size, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - int count = tb_vscnprintf(buf, size, fmt, ap); + int count = sk_vscnprintf(buf, size, fmt, ap); va_end(ap); return count; } @@ -458,7 +458,7 @@ int tb_snprintf(char *buf, size_t size, const char *fmt, ...) * index() is also present as the strchr() in the kernel; it does exactly the * same thing as it's userland equivalent. */ -char *tb_index(p, ch) +char *sk_index(p, ch) const char *p; int ch; { @@ -482,7 +482,7 @@ char *tb_index(p, ch) /* * Compare memory regions. */ -int tb_memcmp(const void *s1, const void *s2, size_t n) +int sk_memcmp(const void *s1, const void *s2, size_t n) { if (s1 == NULL || s2 == NULL) return (-1); @@ -515,7 +515,7 @@ typedef int word; /* "word" used for optimal copy speed */ * This is the routine that actually implements * (the portable versions of) bcopy, memcpy, and memmove. */ -void *tb_memcpy(void *dst0, const void *src0, size_t length) +void *sk_memcpy(void *dst0, const void *src0, size_t length) { char *dst; const char *src; @@ -597,7 +597,7 @@ void *tb_memcpy(void *dst0, const void *src0, size_t length) /* * Compare strings. */ -int tb_strcmp(s1, s2) +int sk_strcmp(s1, s2) register const char *s1, *s2; { if (s1 == NULL || s2 == NULL) @@ -610,7 +610,7 @@ int tb_strcmp(s1, s2) return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1)); } -size_t tb_strlen(str) +size_t sk_strlen(str) const char *str; { register const char *s; @@ -621,7 +621,7 @@ size_t tb_strlen(str) return(s - str); } -int tb_strncmp(s1, s2, n) +int sk_strncmp(s1, s2, n) register const char *s1, *s2; register size_t n; { @@ -643,7 +643,7 @@ int tb_strncmp(s1, s2, n) * Copy src to dst, truncating or null-padding to always copy n bytes. * Return dst. */ -char *tb_strncpy(char * __restrict dst, const char * __restrict src, size_t n) +char *sk_strncpy(char * __restrict dst, const char * __restrict src, size_t n) { if (dst == NULL || src == NULL) return NULL; @@ -671,7 +671,7 @@ char *tb_strncpy(char * __restrict dst, const char * __restrict src, size_t n) * Ignores `locale' stuff. Assumes that the upper and lower case * alphabets and digits are each contiguous. */ -unsigned long tb_strtoul(const char *nptr, char **endptr, int base) +unsigned long sk_strtoul(const char *nptr, char **endptr, int base) { const char *s = nptr; unsigned long acc; diff --git a/trenchboot/skboot/common/tpm.c b/trenchboot/skboot/common/tpm.c index c0b06f4..1681d57 100644 --- a/trenchboot/skboot/common/tpm.c +++ b/trenchboot/skboot/common/tpm.c @@ -99,7 +99,7 @@ else \ static void tpm_send_cmd_ready_status(uint32_t locality) { /* write 1 to TPM_STS_x.commandReady to let TPM enter ready state */ - tb_memset((void *)&g_reg_sts, 0, sizeof(g_reg_sts)); + sk_memset((void *)&g_reg_sts, 0, sizeof(g_reg_sts)); g_reg_sts.command_ready = 1; write_tpm_sts_reg(locality); } @@ -118,14 +118,14 @@ static bool tpm_send_cmd_ready_status_crb(uint32_t locality) #endif if ( reg_ctrl_sts.tpmidle == 1) { - tb_memset(®_ctrl_request,0,sizeof(reg_ctrl_request)); + sk_memset(®_ctrl_request,0,sizeof(reg_ctrl_request)); reg_ctrl_request.cmdReady = 1; write_tpm_reg(locality, TPM_CRB_CTRL_REQ, ®_ctrl_request); return true; } - tb_memset(®_ctrl_request,0,sizeof(reg_ctrl_request)); + sk_memset(®_ctrl_request,0,sizeof(reg_ctrl_request)); reg_ctrl_request.goIdle = 1; write_tpm_reg(locality, TPM_CRB_CTRL_REQ, ®_ctrl_request); @@ -156,7 +156,7 @@ static bool tpm_send_cmd_ready_status_crb(uint32_t locality) printk(SKBOOT_INFO"2. reg_ctrl_sts.tpmsts: 0x%x\n", reg_ctrl_sts.tpmsts); #endif - tb_memset(®_ctrl_request,0,sizeof(reg_ctrl_request)); + sk_memset(®_ctrl_request,0,sizeof(reg_ctrl_request)); reg_ctrl_request.cmdReady = 1; write_tpm_reg(locality, TPM_CRB_CTRL_REQ, ®_ctrl_request); @@ -245,7 +245,7 @@ static bool tpm_check_da_status(uint32_t locality) static void tpm_execute_cmd(uint32_t locality) { - tb_memset((void *)&g_reg_sts, 0, sizeof(g_reg_sts)); + sk_memset((void *)&g_reg_sts, 0, sizeof(g_reg_sts)); g_reg_sts.tpm_go = 1; write_tpm_sts_reg(locality); } @@ -708,7 +708,7 @@ bool tpm_relinquish_locality_crb(uint32_t locality) if ( reg_loc_state.loc_assigned == 0 ) return true; /* make inactive by writing a 1 */ - tb_memset(®_loc_ctrl,0,sizeof(reg_loc_ctrl)); + sk_memset(®_loc_ctrl,0,sizeof(reg_loc_ctrl)); reg_loc_ctrl.relinquish = 1; write_tpm_reg(locality, TPM_REG_LOC_CTRL, ®_loc_ctrl); @@ -759,7 +759,7 @@ bool tpm_request_locality_crb(uint32_t locality) tpm_reg_loc_state_t reg_loc_state; tpm_reg_loc_ctrl_t reg_loc_ctrl; /* request access to the TPM from locality N */ - tb_memset(®_loc_ctrl,0,sizeof(reg_loc_ctrl)); + sk_memset(®_loc_ctrl,0,sizeof(reg_loc_ctrl)); reg_loc_ctrl.requestAccess = 1; write_tpm_reg(locality, TPM_REG_LOC_CTRL, ®_loc_ctrl); diff --git a/trenchboot/skboot/common/tpm_12.c b/trenchboot/skboot/common/tpm_12.c index 45bd6cd..ddcfeae 100644 --- a/trenchboot/skboot/common/tpm_12.c +++ b/trenchboot/skboot/common/tpm_12.c @@ -247,7 +247,7 @@ typedef struct __packed { } #define UNLOAD_BLOB(buf, offset, blob, size) {\ - tb_memcpy(buf + offset, blob, size);\ + sk_memcpy(buf + offset, blob, size);\ offset += size;\ } @@ -260,7 +260,7 @@ typedef struct __packed { } #define LOAD_BLOB(buf, offset, blob, size) {\ - tb_memcpy(blob, buf + offset, size);\ + sk_memcpy(blob, buf + offset, size);\ offset += size;\ } @@ -448,7 +448,7 @@ static bool tpm12_init(struct tpm_if *ti) } /* make sure tpm is not disabled/deactivated */ - tb_memset(&pflags, 0, sizeof(pflags)); + sk_memset(&pflags, 0, sizeof(pflags)); ret = tpm12_get_flags(locality, TPM_CAP_FLAG_PERMANENT, (uint8_t *)&pflags, sizeof(pflags)); if ( ret != TPM_SUCCESS ) { @@ -461,7 +461,7 @@ static bool tpm12_init(struct tpm_if *ti) return false; } - tb_memset(&vflags, 0, sizeof(vflags)); + sk_memset(&vflags, 0, sizeof(vflags)); ret = tpm12_get_flags(locality, TPM_CAP_FLAG_VOLATILE, (uint8_t *)&vflags, sizeof(vflags)); if ( ret != TPM_SUCCESS ) { @@ -529,9 +529,9 @@ static bool tpm12_init(struct tpm_if *ti) ti->cur_alg = HASH_ALG_SHA1; /* init NV index */ - ti->tb_policy_index = 0x20000001; + ti->sk_policy_index = 0x20000001; ti->lcp_own_index = 0x40000001; - ti->tb_err_index = 0x20000002; + ti->sk_err_index = 0x20000002; ti->sgx_svn_index = 0x50000004; return true; diff --git a/trenchboot/skboot/common/vga.c b/trenchboot/skboot/common/vga.c index 3a7f5c4..34fd900 100644 --- a/trenchboot/skboot/common/vga.c +++ b/trenchboot/skboot/common/vga.c @@ -46,7 +46,7 @@ uint8_t g_vga_delay = 0; /* default to no delay */ static inline void reset_screen(void) { - tb_memset(screen, 0, SCREEN_BUFFER); + sk_memset(screen, 0, SCREEN_BUFFER); cursor_x = 0; cursor_y = 0; num_lines = 0; diff --git a/trenchboot/skboot/include/string.h b/trenchboot/skboot/include/string.h index ec846f3..43f342f 100644 --- a/trenchboot/skboot/include/string.h +++ b/trenchboot/skboot/include/string.h @@ -39,18 +39,18 @@ #include #include -int tb_memcmp(const void *b1, const void *b2, size_t len); -char *tb_index(const char *, int); -int tb_strcmp(const char *, const char *); -size_t tb_strlen(const char *); -int tb_strncmp(const char *, const char *, size_t); -char *tb_strncpy(char * __restrict, const char * __restrict, size_t); -void *tb_memcpy(void *dst, const void *src, size_t len); -int tb_snprintf(char *buf, size_t size, const char *fmt, ...); -int tb_vscnprintf(char *buf, size_t size, const char *fmt, va_list ap); -unsigned long tb_strtoul(const char *nptr, char **endptr, int base); +int sk_memcmp(const void *b1, const void *b2, size_t len); +char *sk_index(const char *, int); +int sk_strcmp(const char *, const char *); +size_t sk_strlen(const char *); +int sk_strncmp(const char *, const char *, size_t); +char *sk_strncpy(char * __restrict, const char * __restrict, size_t); +void *sk_memcpy(void *dst, const void *src, size_t len); +int sk_snprintf(char *buf, size_t size, const char *fmt, ...); +int sk_vscnprintf(char *buf, size_t size, const char *fmt, va_list ap); +unsigned long sk_strtoul(const char *nptr, char **endptr, int base); -static inline void *tb_memset(void *b, int c, size_t len) +static inline void *sk_memset(void *b, int c, size_t len) { char *bb; @@ -60,14 +60,14 @@ static inline void *tb_memset(void *b, int c, size_t len) return (b); } -static inline void *tb_memmove(void *dest, const void *src, size_t n) +static inline void *sk_memmove(void *dest, const void *src, size_t n) { - return tb_memcpy(dest, src, n); + return sk_memcpy(dest, src, n); } -static __inline char *tb_strchr(const char *p, int ch) +static __inline char *sk_strchr(const char *p, int ch) { - return tb_index(p, ch); + return sk_index(p, ch); } #endif /* __STRING_H__ */ diff --git a/trenchboot/skboot/include/tpm.h b/trenchboot/skboot/include/tpm.h index 12cf3f2..56f69c6 100644 --- a/trenchboot/skboot/include/tpm.h +++ b/trenchboot/skboot/include/tpm.h @@ -460,8 +460,8 @@ struct tpm_if { /* NV index to be used */ u32 lcp_own_index; - u32 tb_policy_index; - u32 tb_err_index; + u32 sk_policy_index; + u32 sk_err_index; u32 sgx_svn_index; };