This repository has been archived by the owner on Jul 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6de3938
commit b785487
Showing
4 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
defmodule Mix.Tasks.Nerves.Gen.QemuScript do | ||
use Mix.Task | ||
|
||
@shortdoc "Generate QEMU start script" | ||
|
||
@moduledoc """ | ||
Generates a shell script for starting QEMU on a firmware image that | ||
uses `kiosk_system_x86_64`. | ||
To use the generated script, first create the firmware image using: | ||
`$ mix firmware.image [path/to/my_app.img]` | ||
Place this image somewhere where it won't get overwritten. This image | ||
has a similar purpose to the MicroSD card, Flash memory or hard drive | ||
that a real target would use. | ||
Next, run this command and specify the path to the image. This path | ||
may be overridden when invoking the script. | ||
Example usage: | ||
`$ mix nerves.gen.qemu_script [path/to/my_app.img]` | ||
If the `.img` file isn't specified, it will default to the OTP | ||
application's name plus the `.img` extension. | ||
## Options | ||
None | ||
""" | ||
|
||
@script_name "run-qemu.sh" | ||
|
||
def run(["--" <> _arg | _argv]) do | ||
error_image() | ||
end | ||
|
||
def run([image_path | _argv]) do | ||
if File.exists?(@script_name) do | ||
Mix.shell().yes?("Overwrite #{@script_name}?") || Mix.raise("Aborted") | ||
end | ||
|
||
source = | ||
:code.priv_dir(:nerves_system_x86_64) | ||
|> to_string | ||
|> Path.join(@script_name) | ||
|
||
bindings = [image_path: image_path] | ||
contents = EEx.eval_file(source, bindings, trim: true) | ||
File.write!(@script_name, contents) | ||
File.chmod!(@script_name, 0o755) | ||
|
||
Mix.shell().info("Created #{@script_name}") | ||
end | ||
|
||
def run([]) do | ||
otp_app = Mix.Project.config()[:app] | ||
image_path = "#{otp_app}.img" | ||
run([image_path]) | ||
end | ||
|
||
def run(_), do: error_image() | ||
|
||
defp error_image do | ||
Mix.raise(""" | ||
Unexpected arguments. Expecting to be run as follows: | ||
$ mix nerves.gen.qemu_script [path/to/app.img] | ||
""") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters