/**
* Copyright (c) 2024 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include "pico/stdlib.h"
#include "pico/bootrom.h"
#include "hardware/watchdog.h"
static void print_partition_name(int8_t partition) {
switch (partition) {
case BOOT_PARTITION_NONE: {
printf("\tnone\n");
break;
}
case BOOT_PARTITION_SLOT0: {
printf("\tslot0\n");
break;
}
case BOOT_PARTITION_SLOT1: {
printf("\tslot1\n");
break;
}
case BOOT_PARTITION_WINDOW: {
printf("\twindow\n");
break;
}
default: {
printf("\tunknown\n");
break;
}
}
}
static void print_boot_type_name(uint8_t boot_type) {
switch (boot_type & ~BOOT_TYPE_CHAINED_FLAG) {
case BOOT_TYPE_NORMAL: {
printf("\tnormal\n");
break;
}
case BOOT_TYPE_BOOTSEL: {
printf("\tbootsel\n");
break;
}
case BOOT_TYPE_RAM_IMAGE: {
printf("\tram image\n");
break;
}
case BOOT_TYPE_FLASH_UPDATE: {
printf("\tflash update\n");
break;
}
case BOOT_TYPE_PC_SP: {
printf("\tpc_sp\n");
break;
}
default: {
printf("\tunknown\n");
break;
}
}
if (boot_type & BOOT_TYPE_CHAINED_FLAG) {
printf("\tchained\n");
}
}
static void print_try_before_you_buy_name(uint8_t tbyb) {
assert((tbyb & BOOT_TBYB_AND_UPDATE_FLAG_OTP_VERSION_APPLIED) || !(tbyb & BOOT_TBYB_AND_UPDATE_FLAG_OTHER_ERASED));
switch (tbyb & ~BOOT_TBYB_AND_UPDATE_FLAG_OTHER_ERASED) {
case 0: {
printf("\tnone\n");
break;
}
case BOOT_TBYB_AND_UPDATE_FLAG_BUY_PENDING: {
printf("\tpending\n");
break;
}
case BOOT_TBYB_AND_UPDATE_FLAG_OTP_VERSION_APPLIED: {
printf("\tapplied\n");
if (tbyb & BOOT_TBYB_AND_UPDATE_FLAG_OTHER_ERASED) {
printf("\tother erased\n");
}
break;
}
default: {
printf("\tunknow\n");
break;
}
}
}
static void print_boot_diagnostics(uint32_t boot_diagnostic) {
if (boot_diagnostic & BOOT_DIAGNOSTIC_WINDOW_SEARCHED) {
printf("\twindow searched\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_INVALID_BLOCK_LOOP) {
printf("\tinvalid block loop\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_VALID_BLOCK_LOOP) {
printf("\tvalid block loop\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_VALID_IMAGE_DEF) {
printf("\tvalid image def\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_HAS_PARTITION_TABLE) {
printf("\thas partition table\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_CONSIDERED) {
printf("\tconsidered\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_CHOSEN) {
printf("\tchosen\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_PARTITION_TABLE_MATCHING_KEY_FOR_VERIFY) {
printf("\tpartition table matching key for verify\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_PARTITION_TABLE_HASH_FOR_VERIFY) {
printf("\tpartition table hash for verify\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_PARTITION_TABLE_VERIFIED_OK) {
printf("\tpartition table verified ok\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_IMAGE_DEF_MATCHING_KEY_FOR_VERIFY) {
printf("\timage def matching key for verify\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_IMAGE_DEF_HASH_FOR_VERIFY) {
printf("\timage def hash for verify\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_IMAGE_DEF_VERIFIED_OK) {
printf("\timage def verified ok\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_LOAD_MAP_ENTRIES_LOADED) {
printf("\tload map entries loaded\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_IMAGE_LAUNCHED) {
printf("\timage launched\n");
}
if (boot_diagnostic & BOOT_DIAGNOSTIC_IMAGE_CONDITION_FAILURE) {
printf("\timage condition failure\n");
}
}
int main() {
stdio_init_all();
boot_info_t boot_info;
hard_assert(rom_get_boot_info(&boot_info));
// This information is also available via rom_get_last_boot_type or rom_get_last_boot_type_with_chained_flag
printf("boot_type: %u\n", boot_info.boot_type); print_boot_type_name(boot_info.boot_type);
printf("reboot_params: 0x%08x:0x%08x\n", boot_info.reboot_params[0], boot_info.reboot_params[1]);
printf("diagnostic_partition_index: %d\n", boot_info.diagnostic_partition_index); print_partition_name(boot_info.diagnostic_partition_index);
printf("recent_boot_partition: %d\n", boot_info.partition); print_partition_name(boot_info.partition);
printf("recent_boot_tbyb_and_update_info: %u\n", boot_info.tbyb_and_update_info); print_try_before_you_buy_name(boot_info.tbyb_and_update_info);
printf("boot_diagnostics 0x%08x:\n", boot_info.boot_diagnostic); print_boot_diagnostics(boot_info.boot_diagnostic);
printf("watchdog reboot %d (0x%x)\n", watchdog_caused_reboot(), watchdog_hw->reason);
}
This firmware image was imported from the pico-examples repository.
Copyright 2020 (c) 2020 Raspberry Pi (Trading) Ltd.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Before flashing, please put your Raspberry Pi Pico™ chip in the bootloader mode by keeping the BOOTSEL button pressed while powering up. For more information, please take a look at your board's datasheet.
If you find yourself unable to perform any of the operations, please navigate to the troubleshooting, and the Q&A pages.
The "π Check installed version" button doesn't send your firmware to the Internet. Instead, its algorithm compares the firmware builds' UF2 block hashes safely in your web browser.
The installed firmware version is compared only with all the different versions (builds) of the same project.
Exercise caution while exploring projects of unknown origin. In principle, anyone can publish their firmware here. Projects endorsed by this website will always come with the "submitted by flashmypico" text written just below their title.
A part of your chip's unique RANDID number may be sent to the server if this project's author has enabled the installed version tracking feature. This number will only be logged if the project's author already has it, and has used it to enable this feature for this particular board.