From acbc7c8ac704e700e389f429c3deb96a3b44b481 Mon Sep 17 00:00:00 2001 From: rehius <128579193+rehius@users.noreply.github.com> Date: Mon, 22 May 2023 10:31:58 +0000 Subject: [PATCH] Update main.c --- main.c | 131 --------------------------------------------------------- 1 file changed, 131 deletions(-) diff --git a/main.c b/main.c index 70da09d..8682980 100644 --- a/main.c +++ b/main.c @@ -165,134 +165,3 @@ int main() // attempts limit halt_with_error(7, 3); } -{ - gpio_enable_input_output(pin); - adc_gpio_init(pin); - adc_select_input(pin - 26); - uint16_t result = adc_read(); - gpio_disable_input_output(pin); - float voltage = result * 3.3f / (1 << 12); - return voltage >= (target - range) && voltage <= (target + range); -} - -// test all ADC pins -void self_test() -{ - absolute_time_t tio_time = make_timeout_time_ms(2500); - adc_init(); - bool rst_ok = false, cmd_ok = false, d0_ok = false, clk_ok = false; - while (!time_reached(tio_time)) { - if (!rst_ok) - rst_ok |= safe_test_voltage(PIN_RST, 1.8f, 0.2f); - if (!cmd_ok) - cmd_ok |= safe_test_voltage(PIN_CMD, 1.8f, 0.2f); - if (!d0_ok) - d0_ok |= safe_test_voltage(PIN_DAT, 1.8f, 0.2f); - if (!clk_ok) - clk_ok |= safe_test_voltage(PIN_CLK, 1.1f, 0.9f); - if (rst_ok && cmd_ok && d0_ok && clk_ok) - break; - } - if(!rst_ok) - { - halt_with_error(0, 2); - } - if(!cmd_ok) - { - halt_with_error(1, 2); - } - if(!d0_ok) - { - halt_with_error(2, 2); - } - if(!clk_ok) - { - halt_with_error(3, 2); - } -} - -extern bool was_self_reset; - -int main() -{ - // stop watchdog - *(uint32_t*)(0x40058000 + 0x3000) = (1 << 30); - // init reset, mosfet and LED - detect_board(); - // clocks & voltage - init_system(); - // fuses counter - init_fuses(); - // LED & glitch & emmc PIO - upload_pio(); - // check if this is the very first start - if (watchdog_caused_reboot() && boot_try == 0) - { - halt_with_error(1, 1); - } - // is chip reset required - bool force_button = detect_by_pull_up(1, 0); - // start LED - put_pixel(PIX_blu); - // test pins - self_test(); - // wait till the CPU has proper power & started reading the eMMC - wait_for_boot(2500); - // ensure the BCT has not been overwritten by system update - bool force_check = fast_check(); - was_self_reset = force_button || !is_configured(cid_buf + 1); - // perform payload rewrite if required - if (!force_check || was_self_reset) { - rewrite_payload(); - } - // setup the glitch trigger for Mariko - if (mariko) { - pio1->instr_mem[gtrig_pio_offset + 4] = pio_encode_nop(); - pio1->instr_mem[gtrig_pio_offset + 5] = pio_encode_nop(); - } - // start from some default width - int width = 150; - bool glitched = false; - int offset = 0; - for (int full_try = 0; full_try < 2; full_try++) { - // try saved records - for (int y = 0; (y < 2) && !glitched; y++) { - int max_weight = -1; - while (1) { - offset = find_best_record(&max_weight); - if (offset == -1) - break; - // try glitch - glitched = glitch_try_offset(offset, &width, 3); - if (glitched) - break; - } - } - if (!glitched) { - for(int z = 0; (z < 2) && !glitched; z++) { - prepare_random_array(); - for(int y = 0; y < OFFSET_CNT; y++) - { - offset = offsets_array[y]; - glitched = glitch_try_offset(offset, &width, 4); - if (glitched) - break; - } - } - } - if (glitched) { - if ((count_fuses() & 1) != boot_slot) - { - // finish update / rollback - burn_fuse(); - } - add_boot_record(offset); - halt_with_error(0, 0); - } - if (full_try == 0) { - rewrite_payload(); - } - } - // attempts limit - halt_with_error(7, 3); -}