p7utils/src/p7/dump.c

84 lines
2.9 KiB
C

/* ************************************************************************** */
/* _____ _ */
/* p7/dump.c |_ _|__ _ _| |__ ___ _ _ */
/* | Project: p7utils | |/ _ \| | | | '_ \ / _ \ | | | */
/* | | (_) | |_| | | | | __/ |_| | */
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
/* Last updated: 2017/01/16 23:55:54 |___/ */
/* */
/* ************************************************************************** */
#include "main.h"
#include <inttypes.h>
#include <libp7/packetio.h>
#define numformat "%" PRIuP7INT
#define addrformat "0x%08" PRIxP7INT
/**
* dump:
* Dump calculator information.
*
* @arg handle the libp7 handle
* @return the error code (0 if ok).
*/
int dump(p7_handle_t *handle)
{
/* get server info */
const p7_server_t *info = p7_get_info(handle);
/* Wiped out things */
if (info->preprog_rom_wiped)
log("Warning: Preprogrammed ROM information looks wiped out !\n");
if (info->bootcode_wiped)
log("Warning: Bootcode information looks wiped out !\n");
if (info->os_wiped)
log("Warning: OS information looks wiped out!\n");
if (!info->username[0])
log("Warning: Username is not set.\n");
/* main information */
printf("CPU ID (probably out of date): %s\n", info->cpuid);
printf("Environnement ID: %s\n", info->hwid);
printf("Product ID: %s\n", info->product_id);
/* Preprogrammed ROM */
if (!info->preprog_rom_wiped) {
printf("Preprogrammed ROM version: %02u.%02u",
info->preprog_rom_version.major, info->preprog_rom_version.minor);
if (info->preprog_rom_version.rev)
printf(" (%u)", info->preprog_rom_version.rev);
printf("\nPreprogrammed ROM capacity: " numformat "o\n",
info->preprog_rom_capacity);
}
/* ROM and RAM */
printf("ROM capacity: " numformat "KiB\n", info->flash_rom_capacity / 1024);
printf("RAM capacity: " numformat "KiB\n", info->ram_capacity / 1024);
/* Bootcode */
if (!info->bootcode_wiped) {
printf("Bootcode version: %02u.%02u",
info->bootcode_version.major, info->bootcode_version.minor);
if (info->bootcode_version.rev)
printf(" (%u)", info->bootcode_version.rev);
printf("\nBootcode offset: " addrformat "\n", info->bootcode_offset);
printf("Bootcode size: " numformat "KiB\n", info->bootcode_size / 1024);
}
/* OS */
if (!info->os_wiped) {
printf("OS version: %02u.%02u",
info->os_version.major, info->os_version.minor);
if (info->os_version.rev)
printf(" (%u)", info->os_version.rev);
printf("\nOS offset: " addrformat "\n", info->os_offset);
printf("OS size: " numformat "KiB\n", info->os_size / 1024);
}
/* Miscallenous information */
if (info->username[0])
printf("Username: %s\n", info->username);
return (0);
}