Get Legato Source Code

The initial package that you download contains a pre-built version of the Legato Application Framework, meaning that it contains all the source code that you need and make has already been run for the target that you downloaded the package for. (i.e.; if you download a wp76 package, then make will already be run for the wp76). This means that the build tools and other Legato tools are available for you to use as soon as the package gets installed and you use leaf shell.

If you need want to contribute back to the legato project or need a tracked version of the source code you can switch from using the pre-built version to the source code.

Before downloading the source code you must set up an account on [GitHub)[https://github.com], accept the license at https://swi-license.legato.io , and set up an SSH identity on your development machine.

GitHub

These steps only need to be done the first time you are connecting your development machine to GitHub.

Visit https://github.com

If you don't have an account click Sign up and create a user account.

Once you have an account click on Sign in and enter in your user name and password.

After you have successfully signed in, you will need to associate an SSH key with your account. The settings are available at https://github.com/settings/keys , but you can also access it by clicking on your user avatar in the right hand corner and choosing Settings . Then, on the left menu, click on SSH and GPG keys,

Next, if you have not created RSA keys for your linux development machine before follow these steps:

  • From the Terminal or Git Bash, run ssh-keygen
  • Confirm the default path .ssh/id_rsa
  • Enter a passphrase (recommended) or leave it blank. Remember this passphrase, as you will need it to unlock the key whenever you use it.
  • Click on New SSH key
  • Open ~/.ssh/id_rsa.pub and copy & paste the contents into the box labeled Key, then provide a short description in Title and click on Add New SSH key.
Note
id_rsa.pub is your public key and can be shared, while the key contained in id_rsa is your private key and should be kept secret. It should be treated with the same amount of care as a password.

If you already have a ~/.ssh/id_rsa.pub created, go to https://github.com/settings/keys and register a new key by clicking on New SSH key, then copy & paste the content of the file in Key. Finally, name that key in Title, and click Add SSH key.

Your account is now set up for SSH authentication to GitHub.

To make it possible for your account to access private repositories, go to https://swi-license.legato.io . Follow the instructions, and if you choose to accept the license, your GitHub user will be placed in the legatoproject organisation.

You can check that access was granted successfuly by accessing https://github.com/legatoproject/test-access/ .

For more details on manually cloning the source code see GitHub.

Switch to the Source Code

Legato Sources

To switch from the pre-built Legato Application Framework to the tracked Legato Source code make sure you are in your leaf workspace directory and enter the following command:

$ leaf getsrc legato
Note
If you wish to use the legato source code for all leaf profiles add the --workspace option to the end of your command. i.e., leaf getsrc legato --workspace

You will then be prompted to choose a directory to sync the source code to.

If at any reason the sync stops or times out you can run leaf getsrc legato again to re-sync from GitHub (it picks up where it left off).

To switch back and to use the pre-build version of Legato, disable the source in leaf. This does not delete the source directory, it re-configures leaf to use the original pre-build version of Legato that was downloaded with your SDK.

$ leaf getsrc legato --disable

Linux Sources

The Legato SDK comes with a pre-built image of the Linux OS for your target, if you wish to add drivers or reconfigure Linux you must download the source code for the Linux image, make your changes and then rebuild the image and the toolchain. Leaf provides a tool to automate the download of the Linux source repositories.

$ leaf getsrc swi-linux

Once the source code for Linux is downloaded leaf removes the links to the pre-built toolchain and linux images. You must rebuild those from source code.

To disable leaf from using the Linux source code and switch back to using the pre-built toolchain and Linux image disable the getsrc function.

$ leaf getsrc swi-linux --disable

Leaf Environment

Switching to use the source code is only currently supported for one profile per workspace. If you need to work with multiple version of the source code that we suggest creating different workspaces (folders) for each instance.

The legato source code is not pre-built for a target, to be able to use the Legato build and target management tools you must make Legato for your target from within the Legato root directory. See Configure the Application Framework for details on configuring the Legato Application Framework.

Once make is run the legato shell will pick up all the build and target management tools and you are able to use the Legato Application Framework Source Code to build your Systems and Apps in the same way that you used the pre-built Framework.

Update Source Code to a New Version

leaf update supports updating the source code as well, if you wish to update to a new version of the Framework (including the source code), from your workspace directory run leaf update -p <new package="" identifier>="">. As part of the set-up process leaf will run a repo command to update your source code to the version that matches the update.

Note
You will either need to commit or stash any changes before leaf update can be run when using the source code.

Disabling the Source Code

If for any reason that you want to switch back and use the pre-built version of the Legato Application Framework you can do that by using the following command:

$ leaf getsrc legato --disable
$ leaf getsrc swi-linux --disable

This will download and install any missing packages for the version and will update the environment to use the pre-built version of Legato or Linux. Leaf will not remove the source code directory.