Пример #1
0
/* address must be aligned to 4 and size must be multiple of 4 */
static NOINSTR void emit_core_dump_section(const char *name, uint32_t addr,
                                           uint32_t size) {
  struct section_ctx ctx = {.col_counter = 0, .crc32 = 0};
  cs_base64_init(&ctx.b64_ctx, core_dump_emit_char, &ctx);
  esp_exc_printf(",\r\n\"%s\": {\"addr\": %u, \"data\": \"\r\n", name, addr);

  uint32_t end = addr + size;
  while (addr < end) {
    uint32_t tmp;
    tmp = *((uint32_t *) addr);
    addr += sizeof(tmp);
    ctx.crc32 = cs_crc32(ctx.crc32, &tmp, sizeof(tmp));
    cs_base64_update(&ctx.b64_ctx, (char *) &tmp, sizeof(tmp));
  }
  cs_base64_finish(&ctx.b64_ctx);
  esp_exc_printf("\", \"crc32\": %u}", ctx.crc32);
}

NOINSTR void esp_dump_core(uint32_t cause, struct regfile *regs) {
  (void) cause;
  esp_exc_puts("\r\n--- BEGIN CORE DUMP ---\r\n{\"arch\": \"ESP8266\"");
  emit_core_dump_section("REGS", (uintptr_t) regs, sizeof(*regs));
  emit_core_dump_section("DRAM", 0x3FFE8000, 0x18000);
  emit_core_dump_section("IRAM", 0x40100000, 0x8000);
  /*
   * IRAM and IROM can be obtained from the firmware/ dir.
   * We need the ELF binary anyway to do symbolic debugging anyway
   * so we can avoid sending here huge amount of data that's available
   * on the host where we run GDB.
   */
  esp_exc_puts("}\r\n---- END CORE DUMP ----\r\n");
}
Пример #2
0
void mg_basic_auth_header(const struct mg_str user, const struct mg_str pass,
                          struct mbuf *buf) {
  const char *header_prefix = "Authorization: Basic ";
  const char *header_suffix = "\r\n";

  struct cs_base64_ctx ctx;
  cs_base64_init(&ctx, mg_mbuf_append_base64_putc, buf);

  mbuf_append(buf, header_prefix, strlen(header_prefix));

  cs_base64_update(&ctx, user.p, user.len);
  if (pass.len > 0) {
    cs_base64_update(&ctx, ":", 1);
    cs_base64_update(&ctx, pass.p, pass.len);
  }
  cs_base64_finish(&ctx);
  mbuf_append(buf, header_suffix, strlen(header_suffix));
}
Пример #3
0
/* address must be aligned to 4 and size must be multiple of 4 */
static NOINSTR void emit_core_dump_section(int fd, const char *name,
                                           uint32_t addr, uint32_t size) {
  struct cs_base64_ctx ctx;
  int col_counter = 0;
  uart_puts(fd, ",\"");
  uart_puts(fd, name);
  uart_puts(fd, "\": {\"addr\": ");
  uart_putdec(fd, addr);
  uart_puts(fd, ", \"data\": \"");
  core_dump_emit_char_fd = fd;
  cs_base64_init(&ctx, core_dump_emit_char, &col_counter);

  uint32_t end = addr + size;
  while (addr < end) {
    uint32_t buf;
    buf = *((uint32_t *) addr);
    addr += sizeof(uint32_t);
    cs_base64_update(&ctx, (char *) &buf, sizeof(uint32_t));
  }
  cs_base64_finish(&ctx);
  uart_puts(fd, "\"}");
}
Пример #4
0
void mg_mbuf_append_base64(struct mbuf *mbuf, const void *data, size_t len) {
  struct cs_base64_ctx ctx;
  cs_base64_init(&ctx, mg_mbuf_append_base64_putc, mbuf);
  cs_base64_update(&ctx, (const char *) data, len);
  cs_base64_finish(&ctx);
}