/* smutool Tool for SMU * Copyright (C) 2015 Damien Zammit * Copyright (C) 2023 Sheep Sun * * 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. * See . */ #include #include #include #include #include #include #include #include #define SMU_DATA 0x204 #define SMU_ADDR 0x200 int main(int argc, char* argv[]) { int fd = -1; char *filename = argv[1]; uint32_t target = strtoul(argv[2], 0, 0); uint32_t writeval = 0; int do_write = 0; if(argc > 3) { writeval = strtoul(argv[3], 0, 0); do_write = 1; } if((fd = open(filename, O_RDWR | O_SYNC)) == -1) exit(-1); //fprintf(stderr, "%s opened.\n", filename); void *map_base = mmap(0, 0x1000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); //fprintf(stderr, "%p\n", map_base); volatile uint32_t *smu_data_m = map_base + SMU_DATA; volatile uint32_t *smu_addr_m = map_base + SMU_ADDR; if (do_write == 0) { *smu_addr_m = target; uint32_t res = *smu_data_m; //fprintf(stderr, "[%p] -> 0x%08x\n",target, res) ; printf("0x%08x\n",res); } else { *smu_addr_m = target; *smu_data_m = writeval; //fprintf(stderr, "0x%08x -> [%p] (-> 0x%08x)\n", writeval, target, *smu_data_m); } //fprintf(stderr, "exiting\n"); return 0; }