/* * Copyright (C) 2016-2017 Paul Kocialkowski * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include "spm.h" #include "pcm_mcdi_mt8173_20160401_v1.h" #include "pcm_power_down_mt8173_V37.h" #include "pcm_suspend_20150805_V1.h" #include "pcm_suspend_20150917_V4.h" static const struct pcm_desc *pcm_descs[] = { &pcm_mcdi_mt8173_20160401_v1, &pcm_power_down_mt8173_V37, &pcm_suspend_20150805_V1, &pcm_suspend_20150917_V4, NULL }; static const struct pcm_desc *pcm_desc_find(const char *version) { int i; for (i = 0; pcm_descs[i] != NULL; i++) { if (strcmp(pcm_descs[i]->version, version) == 0) return pcm_descs[i]; } return NULL; } static void pcm_desc_list(void) { int i; printf("Available PCM descriptions:\n"); for (i = 0; pcm_descs[i] != NULL; i++) printf("%s\n", pcm_descs[i]->version); } int main(int argc, char *argv[]) { const struct pcm_desc *desc; char *version = NULL; char *name; int fd; int i; if (argc > 1 && argv[1] != NULL) version = argv[1]; if (version == NULL) { pcm_desc_list(); return 1; } desc = pcm_desc_find(version); if (desc == NULL) { printf("Couldn't find PCM description with version %s\n", version); return 1; } asprintf(&name, "%s.bin", desc->version); fd = open(name, O_CREAT | O_TRUNC | O_RDWR, 0644); if (fd < 0) return 1; free(name); write(fd, desc->base, desc->size * sizeof(unsigned int)); close(fd); asprintf(&name, "%s.txt", desc->version); fd = open(name, O_CREAT | O_TRUNC | O_RDWR, 0644); if (fd < 0) return 1; free(name); for (i = 0 ; i < desc->size ; i++) dprintf(fd, "[0x%04x] 0x%08x\n", i, desc->base[i]); close(fd); printf("Produced %s\n", desc->version); return 0; }