A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 89 lines 2.4 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * 9 * Copyright (C) 2022 by Aidan MacDonald 10 * 11 * This program is free software; you can redistribute it and/or 12 * modify it under the terms of the GNU General Public License 13 * as published by the Free Software Foundation; either version 2 14 * of the License, or (at your option) any later version. 15 * 16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 * KIND, either express or implied. 18 * 19 ****************************************************************************/ 20 21#include "bootdata.h" 22#include "crc32.h" 23#include <stddef.h> 24 25#ifdef BOOTLOADER 26# error "not to be included in bootloader builds" 27#endif 28 29bool boot_data_valid; 30 31static bool verify_boot_data_v0(void) INIT_ATTR; 32static bool verify_boot_data_v0(void) 33{ 34 /* validate protocol version */ 35 if (boot_data.version != 0) 36 return false; 37 38 /* validate length */ 39 if (boot_data.length != 4) 40 return false; 41 42 return true; 43} 44 45static bool verify_boot_data_v1(void) INIT_ATTR; 46static bool verify_boot_data_v1(void) 47{ 48 /* validate protocol version */ 49 if (boot_data.version != 1) 50 return false; 51 52 /* validate length */ 53 if (boot_data.length != 4) 54 return false; 55 56 return true; 57} 58 59struct verify_bd_entry 60{ 61 int version; 62 bool (*verify) (void); 63}; 64 65static const struct verify_bd_entry verify_bd[] INITDATA_ATTR = { 66 { 0, verify_boot_data_v0 }, 67 { 1, verify_boot_data_v1 }, 68}; 69 70void verify_boot_data(void) 71{ 72 /* verify payload with checksum - all protocol versions */ 73 uint32_t crc = crc_32(boot_data.payload, boot_data.length, 0xffffffff); 74 if (crc != boot_data.crc) 75 return; 76 77 /* apply verification specific to the protocol version */ 78 for (size_t i = 0; i < ARRAYLEN(verify_bd); ++i) 79 { 80 const struct verify_bd_entry *e = &verify_bd[i]; 81 if (e->version == boot_data.version) 82 { 83 if (e->verify()) 84 boot_data_valid = true; 85 86 return; 87 } 88 } 89}