Simple typescript tool for updating firmware. Made for work purposes.
Choose any place where you wanna arrange project, for example /home/username/projects/, go to this folder:
cd /home/username/projects/Then cloning project files there:
git clone git@github.com:qwerty541/firmware-updater.gitGo to the appeared project folder:
cd ./firmware-updater/Important! For this step you need to have installed rust compiler, follow this link for details: https://www.rust-lang.org/tools/install
Now follow to subproject folder:
cd ./fake-firmware-process/Begin compilation by this command:
cargo buildAfter compilation of firmware emulator we need a http server from witch the new firmware version will be downloaded.
Important! For this and future steps you need to have installed nodejs, follow this link for details: https://nodejs.org/
Globally install nodejs package http-server:
sudo npm install -g http-serverAfter installation we need to prepare a folder for HTTP server where will be placed binary file with "new" version of firmware
Go to the project folder:
cd /home/username/projects/firmware-updater/Init folder for HTTP server, for example fake-http-server-storage:
mkdir ./fake-http-server-storage/Copy inside these new folder firmware binary file:
cp ./fake-firmware-process/target/debug/fake_firmware_process ./fake-http-server-storage/Now we need to give that file a name with contains firmware version, for example firmware-v2. Version 2 because will have version 1 running and we will upgrade it to 2.
mv ./fake-http-server-storage/fake_firmware_process ./fake-http-server-storage/firmware-v2Now all about HTTP server was read, lets run it:
cd ./fake-http-server-storage/
http-serverThe console will show ip address and port of HTTP server. Now we need to move it with firmware binary file path in configuration file:
cd /home/username/projects/firmware-updater/firmware-updater/
mv ./config.example.json ./config.jsonNow open config.json with any text editor and change properties remoteFirmwareStorageServer and firmwareFileNameWithoutVersion to your values. After these changes in configuration file these properties should look like:
{
"firmwareFileNameWithoutVersion": "firmware-v",
"remoteFirmwareStorageServer": {
"hostname": "127.0.0.1",
"port": 8080,
"path": "/"
},
}In current step will be organize folder for our current firmware binary file and write info about that in config file:
cd /home/username/projects/firmware-updater/
mkdir ./firmware-storage/
cp ./fake-firmware-process/target/debug/fake_firmware_process ./firmware-storage/
mv ./firmware-storage/fake_firmware_process ./firmware-storage/firmware-v1After that we need to rewrite property firmwareLocalStoragePath in config.json. After changes it should look like:
{
"firmwareLocalStoragePath": "/home/username/projects/firmware-updater/firmware-storage/",
}At this step we need to run our current firmware binary /home/username/projects/firmware-updater/firmware-storage/firmware-v1 as systemd process.
For that you need to create .service file from template:
cd /home/username/projects/firmware-updater/
sudo cp ./fake-firmware-process/fake_firmware.service /etc/systemd/system/Then open this will with text editor and change path to firmware binary file to your actual:
[Service]
ExecStart=/home/username/projects/firmware-updater/firmware-storage/firmware-v1Now we can launch it with systemctl command:
sudo systemctl daemon-reload
sudo systemctl start fake_firmwareAnd check its status to be sure that everything went without errors:
sudo systemctl status fake_firmwareIt remains only to change systemdFirmwareServiceConfigurationFilePath property in config file. After changes it should look like:
{
"systemdFirmwareServiceConfigurationFilePath": "/etc/systemd/system/fake_firmware.service"
}And the last preparation step, we need to install required dependencies for launching firmware-updater.
Important! For this and future steps you need to have installed yarn package manager, follow this link for details: https://yarnpkg.com/getting-started/install
cd /home/username/projects/firmware-updater/firmware-updater/
yarn installIn all previous steps was completed correctly now we can launch firmware-updater.
cd /home/username/projects/firmware-updater/firmware-updater/
sudo yarn update-firmwareAfter script finished its work check that firmware-storage folder contains binary file firmware-v2 instead firmware-v1, path to binary file inside .service file was changed and sudo systemctl status fake_firmware shows that process active and was run from new binary file.