|
|
@ -4,12 +4,11 @@ use igloo_manifest::*;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::Igloo;
|
|
|
|
use crate::Igloo;
|
|
|
|
use crate::igloo_target::IglooTarget;
|
|
|
|
use crate::igloo_target::IglooTarget;
|
|
|
|
|
|
|
|
|
|
|
|
use std::vec::Vec;
|
|
|
|
|
|
|
|
use std::fs::OpenOptions;
|
|
|
|
use std::fs::OpenOptions;
|
|
|
|
use std::fs::File;
|
|
|
|
use std::fs::File;
|
|
|
|
|
|
|
|
use std::vec::Vec;
|
|
|
|
use std::io::prelude::*;
|
|
|
|
use std::io::prelude::*;
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
// New Project
|
|
|
|
// New Project
|
|
|
|
// --- Verify location
|
|
|
|
// --- Verify location
|
|
|
|
// --- Populate base folders
|
|
|
|
// --- Populate base folders
|
|
|
@ -23,6 +22,7 @@ pub struct IglooPrj
|
|
|
|
name: String,
|
|
|
|
name: String,
|
|
|
|
target_bank: Vec<IglooTarget>,
|
|
|
|
target_bank: Vec<IglooTarget>,
|
|
|
|
pub project_dir: std::path::PathBuf,
|
|
|
|
pub project_dir: std::path::PathBuf,
|
|
|
|
|
|
|
|
root: PathBuf,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -35,6 +35,7 @@ impl IglooPrj
|
|
|
|
name: String::from(""),
|
|
|
|
name: String::from(""),
|
|
|
|
target_bank: Vec::default(),
|
|
|
|
target_bank: Vec::default(),
|
|
|
|
project_dir: std::path::PathBuf::default(),
|
|
|
|
project_dir: std::path::PathBuf::default(),
|
|
|
|
|
|
|
|
root: PathBuf::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -52,7 +53,8 @@ impl IglooPrj
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Err(res_err)
|
|
|
|
return Err(res_err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
match target_exists(&inst.master_make_man, &inst.master_target_man, target_in)
|
|
|
|
|
|
|
|
|
|
|
|
match target_is_valid(&inst.master_make_man, &inst.master_target_man, target_in)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Ok(v) =>
|
|
|
|
Ok(v) =>
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -96,6 +98,8 @@ impl IglooPrj
|
|
|
|
name: String::from(name_in),
|
|
|
|
name: String::from(name_in),
|
|
|
|
target_bank: temp,
|
|
|
|
target_bank: temp,
|
|
|
|
project_dir: IglooEnvInfo::get_env_info().cwd.join(name_in),
|
|
|
|
project_dir: IglooEnvInfo::get_env_info().cwd.join(name_in),
|
|
|
|
|
|
|
|
root: PathBuf::from(
|
|
|
|
|
|
|
|
IglooEnvInfo::get_env_info().cwd.join(name_in)),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -103,17 +107,14 @@ impl IglooPrj
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
// Create new directory
|
|
|
|
// Create new directory
|
|
|
|
let mut active_dir = IglooEnvInfo::get_env_info().cwd;
|
|
|
|
let mut active_dir = self.root.clone();
|
|
|
|
//println!("Active Directory: {:?}", active_dir.display());
|
|
|
|
|
|
|
|
println!("NAME: {}", self.name);
|
|
|
|
|
|
|
|
active_dir.push(&self.name);
|
|
|
|
|
|
|
|
match std::fs::create_dir(&active_dir)
|
|
|
|
match std::fs::create_dir(&active_dir)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Err(e) => println!("{:?}", e),
|
|
|
|
Err(e) => println!("{:?}", e),
|
|
|
|
_ => (),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//println!("Active Directory: {:?}", active_dir.display());
|
|
|
|
|
|
|
|
println!("Creating .igloo dir...");
|
|
|
|
// Create .igloo directory
|
|
|
|
match std::fs::create_dir(
|
|
|
|
match std::fs::create_dir(
|
|
|
|
std::path::Path::new(&active_dir)
|
|
|
|
std::path::Path::new(&active_dir)
|
|
|
|
.join(".igloo"))
|
|
|
|
.join(".igloo"))
|
|
|
@ -122,6 +123,7 @@ impl IglooPrj
|
|
|
|
_ => (),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create target directory
|
|
|
|
match std::fs::create_dir(
|
|
|
|
match std::fs::create_dir(
|
|
|
|
std::path::Path::new(&active_dir)
|
|
|
|
std::path::Path::new(&active_dir)
|
|
|
|
.join(".igloo/target"))
|
|
|
|
.join(".igloo/target"))
|
|
|
@ -130,6 +132,7 @@ impl IglooPrj
|
|
|
|
_ => (),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create src directory
|
|
|
|
match std::fs::create_dir(
|
|
|
|
match std::fs::create_dir(
|
|
|
|
std::path::Path::new(&active_dir)
|
|
|
|
std::path::Path::new(&active_dir)
|
|
|
|
.join("src"))
|
|
|
|
.join("src"))
|
|
|
@ -137,6 +140,8 @@ impl IglooPrj
|
|
|
|
Err(e) => println!("{:?}", e),
|
|
|
|
Err(e) => println!("{:?}", e),
|
|
|
|
_ => (),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create inc directory
|
|
|
|
match std::fs::create_dir(
|
|
|
|
match std::fs::create_dir(
|
|
|
|
std::path::Path::new(&active_dir)
|
|
|
|
std::path::Path::new(&active_dir)
|
|
|
|
.join("inc"))
|
|
|
|
.join("inc"))
|
|
|
@ -144,6 +149,8 @@ impl IglooPrj
|
|
|
|
Err(e) => println!("{:?}", e),
|
|
|
|
Err(e) => println!("{:?}", e),
|
|
|
|
_ => (),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create cfg directory
|
|
|
|
match std::fs::create_dir(
|
|
|
|
match std::fs::create_dir(
|
|
|
|
std::path::Path::new(&active_dir)
|
|
|
|
std::path::Path::new(&active_dir)
|
|
|
|
.join("cfg"))
|
|
|
|
.join("cfg"))
|
|
|
@ -151,6 +158,8 @@ impl IglooPrj
|
|
|
|
Err(e) => println!("{:?}", e),
|
|
|
|
Err(e) => println!("{:?}", e),
|
|
|
|
_ => (),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create ESF directory
|
|
|
|
match std::fs::create_dir(
|
|
|
|
match std::fs::create_dir(
|
|
|
|
std::path::Path::new(&active_dir)
|
|
|
|
std::path::Path::new(&active_dir)
|
|
|
|
.join("ESF"))
|
|
|
|
.join("ESF"))
|
|
|
@ -159,12 +168,15 @@ impl IglooPrj
|
|
|
|
_ => (),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Generate Targets
|
|
|
|
|
|
|
|
|
|
|
|
self.gen_targets();
|
|
|
|
self.gen_targets();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Generate igloo.h
|
|
|
|
self.gen_igloo_header();
|
|
|
|
self.gen_igloo_header();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Generate main.c
|
|
|
|
self.gen_igloo_main();
|
|
|
|
self.gen_igloo_main();
|
|
|
|
//self.debugManifests();
|
|
|
|
|
|
|
|
ErrNone
|
|
|
|
ErrNone
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -188,117 +200,16 @@ impl IglooPrj
|
|
|
|
/// Generates the target directories for all targets
|
|
|
|
/// Generates the target directories for all targets
|
|
|
|
pub fn gen_targets(&self) -> IglooErrType
|
|
|
|
pub fn gen_targets(&self) -> IglooErrType
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let prj_root = self.project_dir.join(".igloo");
|
|
|
|
|
|
|
|
for target in &self.target_bank
|
|
|
|
for target in &self.target_bank
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let target_root = prj_root.join(&("target/".to_owned() + &target.name));
|
|
|
|
target.generate();
|
|
|
|
println!("{:?}", target_root.display());
|
|
|
|
target.populate();
|
|
|
|
match std::fs::create_dir(&target_root)
|
|
|
|
target.generate_openocd_config();
|
|
|
|
{
|
|
|
|
|
|
|
|
Err(e) => println!("{:?}", e),
|
|
|
|
|
|
|
|
_ => (),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create project scripts dir
|
|
|
|
|
|
|
|
let scripts_dir = target_root.join("scripts");
|
|
|
|
|
|
|
|
match std::fs::create_dir(&scripts_dir)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Err(e) => println!("{:?}", e),
|
|
|
|
|
|
|
|
_ => (),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// populate scripts dir
|
|
|
|
|
|
|
|
//sym link gdb scripts
|
|
|
|
|
|
|
|
let gdb_scripts_paths = std::fs::read_dir(
|
|
|
|
|
|
|
|
&(String::from(
|
|
|
|
|
|
|
|
IglooEnvInfo::get_env_info()
|
|
|
|
|
|
|
|
.esfd.to_str()
|
|
|
|
|
|
|
|
.unwrap()) + "/scripts"))
|
|
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut gdb_scripts: std::vec::Vec<std::path::PathBuf>
|
|
|
|
|
|
|
|
= std::vec::Vec::new();
|
|
|
|
|
|
|
|
for entry in gdb_scripts_paths
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
match &entry
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Ok(v) => if !v.path().is_dir() {
|
|
|
|
|
|
|
|
gdb_scripts.push(v.path()) },
|
|
|
|
|
|
|
|
Err(e) => println!("{:?}", e),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for file in gdb_scripts
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
println!("Project Scripts Dir: {:?}", scripts_dir);
|
|
|
|
|
|
|
|
println!("ePenguin Scripts Dir: {:?}", file);
|
|
|
|
|
|
|
|
std::os::unix::fs::symlink(
|
|
|
|
|
|
|
|
&file, &scripts_dir.join(&file.file_name().unwrap())).unwrap();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let prj_esf_dir = self.project_dir.join("ESF");
|
|
|
|
|
|
|
|
for (sym_dir, loc_in_esf) in &target.links
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let link_to_dir = IglooEnvInfo::get_env_info()
|
|
|
|
|
|
|
|
.esfd
|
|
|
|
|
|
|
|
.join(&loc_in_esf.clone().into_str().unwrap());
|
|
|
|
|
|
|
|
std::os::unix::fs::symlink(link_to_dir, prj_esf_dir.join(sym_dir)).unwrap();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.gen_openocd_config(&target);
|
|
|
|
|
|
|
|
self.gen_makefile(&target);
|
|
|
|
self.gen_makefile(&target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ErrNone
|
|
|
|
ErrNone
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn gen_openocd_config(&self, target: &IglooTarget) -> IglooErrType
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let mut openocd_cfg = self.project_dir.join(".igloo/target");
|
|
|
|
|
|
|
|
openocd_cfg.push(&target.name);
|
|
|
|
|
|
|
|
openocd_cfg.push("scripts");
|
|
|
|
|
|
|
|
openocd_cfg.push(&self.name);
|
|
|
|
|
|
|
|
if openocd_cfg.with_extension("cfg").exists()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::fs::remove_file(openocd_cfg.with_extension("cfg")).unwrap();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::fs::File::create(
|
|
|
|
|
|
|
|
openocd_cfg.with_extension("cfg")).unwrap();
|
|
|
|
|
|
|
|
let mut ocfg_file = OpenOptions::new()
|
|
|
|
|
|
|
|
.write(true)
|
|
|
|
|
|
|
|
.append(true)
|
|
|
|
|
|
|
|
.open(openocd_cfg.with_extension("cfg"))
|
|
|
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
writeln!(ocfg_file, "#\n# ePenguin Generated OpenOCD \
|
|
|
|
|
|
|
|
Config Script\n#\n").unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
writeln!(ocfg_file, "\n# Transport Select").unwrap();
|
|
|
|
|
|
|
|
writeln!(ocfg_file, "source [find interface//{}.cfg]", target
|
|
|
|
|
|
|
|
.openocd.get("transport_cfg")
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
.into_str()
|
|
|
|
|
|
|
|
.unwrap()).unwrap();
|
|
|
|
|
|
|
|
writeln!(ocfg_file, "transport select {}", target
|
|
|
|
|
|
|
|
.openocd.get("transport")
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
.into_str()
|
|
|
|
|
|
|
|
.unwrap()).unwrap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
writeln!(ocfg_file, "\n# Chip Information").unwrap();
|
|
|
|
|
|
|
|
writeln!(ocfg_file, "set CHIPNAME {}", target.name).unwrap();
|
|
|
|
|
|
|
|
writeln!(ocfg_file, "source [find target//{}.cfg]", target
|
|
|
|
|
|
|
|
.openocd.get("chip_name_cfg")
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.clone()
|
|
|
|
|
|
|
|
.into_str()
|
|
|
|
|
|
|
|
.unwrap()).unwrap();
|
|
|
|
|
|
|
|
ErrNone
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Generates a makefile for a target
|
|
|
|
/// Generates a makefile for a target
|
|
|
|
pub fn gen_makefile(&self, target: &IglooTarget) -> IglooErrType
|
|
|
|
pub fn gen_makefile(&self, target: &IglooTarget) -> IglooErrType
|
|
|
|
{
|
|
|
|
{
|
|
|
|