fix: improvements across the board

* Update README.md, make sure the disclaimer is seen before install instructions.
* update ustorage to have temp readings on some samsung ssds (stupid samsung)
* Patch and support ulcmd relying on output from ubnteeprom
* Move away from ubnthal FINALLY now that we patched ulcmd (hacky but works!)
* added README.md to ubnteeprom, since I expect at somepoint folks will fork/use it for other projects.
* Added our own kernel module to force mtd's RO, which does a better job than ubnthal did :)
This commit is contained in:
Chris Blake 2024-06-16 13:50:44 -05:00
parent 7858593f11
commit 116b6591a9
11 changed files with 173 additions and 18 deletions

1
tools/mtd-lock/Kbuild Normal file
View file

@ -0,0 +1 @@
obj-m := ubnt-mtd-lock.o

11
tools/mtd-lock/README.md Normal file
View file

@ -0,0 +1,11 @@
# mtd-lock
A stupid basic kernel module to ensure we set /dev/mtd as RO (fully) in our firmware. This is done to prevent users/bad actors from wiping your bootloader/Unifi EEPROM, which are required for your device to function!
## Building
make -C ${kernel_source_dir} M=$PWD
## License
This code is licensed under the GNU General Public License, version 2. A copy of said license can be found at [https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html#SEC1](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html#SEC1)

View file

@ -0,0 +1,78 @@
/*
* Copyright (C) 2024 Chris Blake <chrisrblake93@gmail.com>
*
* Inspired by mtd-rw: https://github.com/jclehner/mtd-rw/tree/master
*
* 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; version 2 of the License.
*
* 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.
*/
#include <linux/init.h>
#include <linux/module.h>
#include <linux/mtd/mtd.h>
#include <linux/err.h>
#ifndef MODULE
#error "uvnt-mtd-lock must be compiled as a module."
#endif
#define MOD_INFO KERN_INFO "ubnt-mtd-lock: "
#define MOD_ERR KERN_ERR "ubnt-mtd-lock: "
static int set_readonly(unsigned n)
{
struct mtd_info *mtd = get_mtd_device(NULL, n);
int err;
if (IS_ERR(mtd)) {
if (PTR_ERR(mtd) != -ENODEV) {
printk(MOD_ERR "error probing mtd%d %ld\n", n, PTR_ERR(mtd));
}
return PTR_ERR(mtd);
}
err = -EEXIST;
if (mtd->flags & MTD_WRITEABLE) {
printk(MOD_INFO "setting mtd%d \"%s\" readonly\n", n, mtd->name);
mtd->flags &= ~MTD_WRITEABLE;
err = 0;
}
put_mtd_device(mtd);
return err;
}
int ubnt_mtd_lock_init(void)
{
int i, err;
/* For all MTD partitions, go RO. Assume <10 for UNVR/UNVRPRO */
for (i = 0; i < 10; ++i) {
err = set_readonly(i);
if (err == -ENODEV) {
break;
}
}
return 0;
}
void ubnt_mtd_lock_exit(void)
{
/* Do nothing, we wanna keep mtd locked!!! */
}
module_init(ubnt_mtd_lock_init);
module_exit(ubnt_mtd_lock_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Chris Blake <chrisrblake93@gmail.com>");
MODULE_DESCRIPTION("Unifi UNVR/UNVRPRO driver to force MTD partitions RO");
MODULE_VERSION("1");

View file

@ -0,0 +1,37 @@
# ubnteeprom
A userspace tool to parse/read/render the EEPROM MTD partition on Unifi UNVR/UNVR Pro, and possibly other Dream Machine devices in the future.
## Purpose
This tool was created as a userspace replacement for the functions Unifi's ubnthal proprietary kernel module provides, by reporting most of the same information out as `/proc/ubnthal/*` as well as some output from `ubnt-tools id`.
The idea behind this is so we can get this repo off of using proprietary Unifi code as much as possible, so replacements for things are required. All code for this was reverse engineered and no unifi proprietary code was copied/used in the creation of this tool.
## Usage
Get similar output to `/proc/ubnthal/board`:
ubnteeprom -board
Get similar output to `/proc/ubnthal/system.info`:
ubnteeprom -systeminfo
Get similar output to `ubnt-tools id`:
ubnteeprom -tools
Get a specfic value for a selected key in output, for example, `boardid`:
ubnteeprom -board -key boardid
## Building
```
env GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o ubnteeprom main.go
```
## License
This code is licensed under the GNU General Public License, version 2. A copy of said license can be found at [https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html#SEC1](https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html#SEC1)

View file

@ -1,5 +1,8 @@
package main
// Copyright (C) 2024 Chris Blake <chrisrblake93@gmail.com>
// Licensed under the GNU Public License, version 2
import (
"encoding/hex"
"flag"