Skip to content

Instantly share code, notes, and snippets.

@four0four
Last active June 1, 2023 21:18
Show Gist options
  • Save four0four/6bb30f67dff7e58664a4711eefde7cb8 to your computer and use it in GitHub Desktop.
Save four0four/6bb30f67dff7e58664a4711eefde7cb8 to your computer and use it in GitHub Desktop.
hacked up smurw.c tested on an rx580 (should work on most?) invocation is like ./smurw [path to resource5 BAR] [addr] (dword to write)
/* smutool Tool for SMU
* Copyright (C) 2015 Damien Zammit <[email protected]>
* Copyright (C) 2023 Sheep Sun <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <inttypes.h>
#include <pci/pci.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/io.h>
#include <stdlib.h>
#include <unistd.h>
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment