Skip to content

Commit

Permalink
Updated to 3.02
Browse files Browse the repository at this point in the history
  • Loading branch information
danielk-98 committed May 26, 2022
1 parent b5ca2e6 commit 4b41c9d
Show file tree
Hide file tree
Showing 136 changed files with 948 additions and 449 deletions.
3 changes: 1 addition & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
.vscode/
docker_image/
udev/
config/udev/
scripts/docker-scripts/
scripts/wsl-usb-scripts/
*Project_Template/
.gitignore
install.sh
nxtOSEK.code-workspace
124 changes: 41 additions & 83 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,69 +1,14 @@
############################################################################################
# STAGE 1: Compile NXT utilities (and dependencies) for this platform
############################################################################################
#FROM ubuntu:14.04 AS stage1
#ARG DEBIAN_FRONTEND=noninteractive

# Install host compiler and prereqs
#RUN apt-get update \
# && apt-get -y --no-install-recommends install \
# apt-transport-https build-essential texinfo unzip \
# libgmp-dev libmpfr-dev libppl-dev libcloog-ppl-dev \
# tk-dev ncurses-dev wget gzip tar software-properties-common \
# xvfb gcc-4.8 gdb gdb-multiarch vim scons python3 \
# libc-dev make autoconf libtool libusb-dev

# Copy source code for NXT tools
#ADD src /src
#WORKDIR /src

# Build LibUSB
#RUN tar xf /src/libusb-0.1.12.tar \
# && mkdir -p /build/libusb \
# && cd /build/libusb \
# && ls /src \
# && /src/libusb-0.1.12/configure \
# && make CFLAGS="-Wno-error" CXXFLAGS="-Wno-error" install
# make install

# Build LibNXT
#RUN tar xf /src/libnxt-0.3.tar \
# && cd /src/libnxt-0.3 \
# && scons \
# && chmod +x ./fwflash \
# && chmod +x ./fwexec
## cp ./fwflash $TOOLDIR/fwflash
## cp ./fwexec $TOOLDIR/fwexec

# Build NeXTTOOl
#RUN unzip /src/bricxcc-3.3.8.10.zip \
# && cd /src/bricxcc-3.3.8.10 \
# && make -f nexttool.mak \
# && chmod +x ./nexttool
## cp ./nexttool $TOOLDIR/nexttool

# Build modified LibNXT from the LeJOS-OSEK source code
#ADD nxtosek /nxtosek
#RUN cd /nxtosek/lejos_nxj/src/libnxt \
## && scons

############################################################################################
# STAGE 2: Install NXTOSEK and dependencies
############################################################################################
FROM ubuntu:20.04 AS stage2
FROM ubuntu:20.04
ARG DEBIAN_FRONTEND=noninteractive
ARG USERNAME=nxtosek
ARG USERNAME=nxtuser
ARG USER_UID=1000
ARG USER_GID=$USER_UID
ENV NXTOSEK=/home/$USERNAME
ENV NXT_TOOLS_DIR=/usr/local/bin
ARG NXT_TOOLS_DIR=/usr/local/bin
ENV NXTOSEK=/usr/local/src/nxtosek
ENV DISPLAY=:0
ENV WINEARCH=win32
ENV WINEDLLOVERRIDES="mscoree,mshtml="

# Load 3rd-party source code into image
ADD src /src

# Add new nxtosek user with sudo privileges and no password
RUN groupadd -f --gid $USER_GID $USERNAME \
&& useradd --create-home --uid $USER_UID --gid $USER_GID -m $USERNAME \
Expand All @@ -72,27 +17,30 @@ RUN groupadd -f --gid $USER_GID $USERNAME \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME \
# Add user permissions for most USB devices \
&& usermod -aG plugdev nxtosek \
&& usermod -aG dialout nxtosek \
&& usermod -aG users nxtosek \
&& usermod -aG plugdev ${USERNAME} \
&& usermod -aG dialout ${USERNAME} \
&& usermod -aG users ${USERNAME} \
# Packages required to install more packages \
&& apt-get -y install --no-install-recommends \
make vim wget gnupg software-properties-common \
# Software required for building 3rd party tools \
# Software required for running 3rd party tools \
&& apt-get -y install --no-install-recommends \
gcc g++ build-essential fpc libusb-0.1-4 libusb-dev scons python \
libusb-0.1-4 \
# Software required for building 3rd party tools \
#&& apt-get -y install --no-install-recommends \
# gcc g++ build-essential fpc libusb-dev scons python \
# Build NeXTTool \
&& cd /src/bricxcc/code \
&& make -f nexttool.mak \
&& chmod +x nexttool \
&& cp nexttool ${NXT_TOOLS_DIR}/nexttool \
#&& cd /src/bricxcc/code \
#&& make -f nexttool.mak \
#&& chmod +x nexttool \
#&& cp nexttool ${NXT_TOOLS_DIR}/nexttool \
# Build LibNXT \
&& cd /src/libnxt \
&& scons \
&& chmod +x ./fwflash \
&& chmod +x ./fwexec \
&& cp ./fwflash ${NXT_TOOLS_DIR}/fwflash \
&& cp ./fwexec ${NXT_TOOLS_DIR}/fwexec \
#&& cd /src/libnxt \
#&& scons \
#&& chmod +x ./fwflash \
#&& chmod +x ./fwexec \
#&& cp ./fwflash ${NXT_TOOLS_DIR}/fwflash \
#&& cp ./fwexec ${NXT_TOOLS_DIR}/fwexec \
# Install ARM cross-compiler and debuggers \
&& apt-get -y install --install-recommends \
usbutils gcc-arm-none-eabi binutils-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib gdb-multiarch openocd \
Expand All @@ -111,21 +59,31 @@ RUN groupadd -f --gid $USER_GID $USERNAME \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /src
# Create projects folder \
&& mkdir -p /home/${USERNAME}/projects

# Install scripts into NXT_TOOLS_DIR
ADD scripts/include ${NXT_TOOLS_DIR}

# Install NXTOSEK
# Copy nxtOSEK core files
ADD nxtosek ${NXTOSEK}
COPY VERSION README.md ${NXTOSEK}/

# Copy NXT tools
ADD config/bricxcc /home/${USERNAME}/bricxcc
COPY src/bricxcc/code/nexttool src/libnxt/out/fwexec src/libnxt/out/fwflash ${NXT_TOOLS_DIR}/
# Make sure NXT tools always run as root
RUN chown root:root ${NXT_TOOLS_DIR}/nexttool \
&& chown root:root ${NXT_TOOLS_DIR}/fwexec \
&& chown root:root ${NXT_TOOLS_DIR}/fwflash \
&& chmod a+s ${NXT_TOOLS_DIR}/nexttool \
&& chmod a+s ${NXT_TOOLS_DIR}/fwexec \
&& chmod a+s ${NXT_TOOLS_DIR}/fwflash

# Copy scripts
COPY scripts/wine-headless.sh ${NXT_TOOLS_DIR}/wine-headless

# Switch to NXTOSEK user
WORKDIR ${NXTOSEK}
WORKDIR /home/${USERNAME}/projects
USER ${USERNAME}

# Initialize a 32-bit Wine install
# Initialize a 32-bit Wine install \
RUN wine-headless wineboot



124 changes: 68 additions & 56 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,28 @@ This process has been tested on Ubuntu 20.04 running in VMWare and on Ubuntu 20.

---

## Installation under Ubuntu Desktop 20.04 (Non-WSL)

### Prerequisites:

- [Visual Studio Code](https://linuxize.com/post/how-to-install-visual-studio-code-on-ubuntu-20-04/) for Ubuntu Desktop and the [Remote-Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension
### Prerequisites for Ubuntu Desktop 20.04 (Non-WSL):

- [Visual Studio Code](https://linuxize.com/post/how-to-install-visual-studio-code-on-ubuntu-20-04/) for Ubuntu Desktop
- *Optional*: [Remote-Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension.
- If running in a Virtual Machine (VMWare, Virtualbox, etc) you should set a USB device filter to autoconnect NXTs to your VM. Look up instructions for your particular software.
You need to autoattach both NXT and SAM-BA devices (for downloading firmware); the relevant Vendor:Product IDs are 0694:0002 and 03eb:6124, respectively.

### Installation:

1. Clone this repository:

```
git clone https://github.com/danielk-98/nxtOSEK
```
2. Run install script:
```
cd ./nxtOSEK
./install.sh
```
This will download and install Docker using the official Docker install script.
You will also be prompted to download the latest release of the nxtOSEK Docker image (this may take awhile). If you opt out, you can download it later using ./scripts/download_release.sh or download it manually from this repo's Releases page.
3. See the section "Starting A New nxtOSEK Project" for how to get started!
---
## Installation under Windows 11 (WSL2-Ubuntu)
### Prerequisites:
### Prerequisites for Windows 11 (WSL2-Ubuntu):

- Windows 11 (Likely not working in Windows 10 due to Win11-exclusive features)
- [WSL2](https://ubuntu.com/tutorials/install-ubuntu-on-wsl2-on-windows-11-with-gui-support) with Ubuntu 20.04 LTS.
- [Visual Studio Code](https://code.visualstudio.com/download) for Windows, the [Remote-Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension, and the [Remote-WSL](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl) extension.
- [Visual Studio Code](https://code.visualstudio.com/download) for Windows and the [Remote-WSL](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl) extension.
- *Optional*: [Remote-Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension.
- [USB-IP](https://github.com/dorssel/usbipd-win/releases/) server for Windows

### Installation:
---

1. Open VS Code. In File->Preferences->Settings, search for `remote.containers.executeInWSL` . Check the box to enable the option.
If you have multiple WSL instances, you can also change the `remote.containers.executeInWSLDistro` option and select which distro will contain Docker.
## Installation:

In a new WSL terminal:
1. Install prerequisite software for your system (see above)

2. Clone this repository:
2. Open a new terminal. Clone this repository:

```
git clone https://github.com/danielk-98/nxtOSEK
Expand All @@ -62,51 +38,87 @@ In a new WSL terminal:
cd ./nxtOSEK
./install.sh
```
This will download and install Docker using the official Docker install script.
You will also be prompted to download the latest release of the nxtOSEK Docker image (this may take awhile). If you opt out, you can download it later using ./scripts/download_release.sh or download it manually from this repo's Releases page.
After some preliminary configuration, the script will ask you to download the nxtOSEK Docker image.
4. See the section "Starting A New nxtOSEK Project" for how to get started!
If Docker is not installed or if you opt-out of the Docker image, the nxtOSEK toolchain can be installed locally instead (recommended). However, this requires installing many new packages (Wine, ARM cross-compiler, etc.) on your system.
---
The Docker image may take a long time to download but is much less likely to break far in the future due to missing dependencies, since it is already pre-compiled and working.
## Starting A New nxtOSEK Project
**The local installation option is recommended - but if packages are no longer available for your system, download the Docker image instead.**
---
Note: nxtOSEK **can** be used independently of VS-Code. From an Ubuntu or WSL2 terminal, launch `./scripts/bash_release.sh` to spin up a temporary nxtOSEK container and connect to a Bash terminal.
## Starting A New nxtOSEK Project
There are currently project templates available for C and C++ development using the OSEK kernel.
1. Choose OSEK_C_Project_Template or OSEK_C++_Project_Template, then copy the folder to wherever you want to store your new project. Feel free to rename it as desired.
1. Choose `OSEK_C_Project_Template` or `OSEK_C++_Project_Template`, then copy the folder to wherever you want to store your new project. Feel free to rename it as desired.
Then open the project in an nxtOSEK development container:
2. Open Visual Studio Code.
2. Open the project in Visual Studio Code.
2a. *For Windows 11/WSL2 ONLY*: press F1 to open the command menu and find: `Remote-WSL: New WSL Window Using Distro...` . Select the same WSL distro under which you ran install.sh.
*For Windows 11/WSL2 ONLY*: Press F1 to open the command menu and find: `Remote-WSL: New WSL Window Using Distro...` . Select the same WSL distro under which you ran install.sh. Once WSL is running and connected, open the template.code-workspace file as normal.
*If developing within Docker image*: Press F1 to open the command menu and find: `Remote-Containers: Open Workspace In Container` . Select the template.code-workspace file located in the project folder.
- The Project workspace will only open if VS Code is already connected to a running WSL2 instance.
*If developing using a local nxtOSEK install (no Docker image)*: Press F1 to open the command menu and find: `File: Open Workspace from File` . Select the template.code-workspace file located in the project folder.
3. Press F1 to open the command menu and find: `Remote-Containers: Open Workspace In Container` . Select the template.code-workspace file located in this folder.
Ignore the warning message regarding relative paths.
Edit the project, or leave as-is (helloworld code is already included).
3. Write code in ./src, define tasks in template.oil, and edit the build options in Makefile. Or leave the project as-is; "helloworld" code is already included.
4. Write code in ./src, define tasks in template.oil, and edit the build options in Makefile.
*If developing using a local nxtOSEK install (no Docker image)*: You can delete `.devcontainer/` and `run-in-container.sh`, as these will not be needed.
5. In a VS Code terminal, run "make all" to compile the project into an NXT executable. If you have the [Tasks extension](https://marketplace.visualstudio.com/items?itemName=actboy168.tasks) installed, you can simply click the "make all" button in the bottom ribbon.
4. In a VS Code terminal, run "make all" to compile the project into an NXT executable. If you have the [Tasks extension](https://marketplace.visualstudio.com/items?itemName=actboy168.tasks) installed, you can simply click the "make all" button in the bottom ribbon.
Finally, download the program to the NXT.
5. Connect an NXT to your computer via the USB cable.
6. Connect an NXT to your computer via the USB cable.
The device should be automatically passed through to the running Docker container. Both `lsusb` and `nexttool -listbricks` should confirm the NXT connection was successful.
*For Windows 11/WSL2 ONLY*:
The USB device should be automatically passed through to WSL within 10 seconds. Both `lsusb` and `nexttool -listbricks` should confirm the NXT connection was successful.
7. If you haven't yet installed the Enhanced Firmware on the NXT, do so by running "./flash-rxe-firmware.sh"
6. If you haven't yet installed the Enhanced Firmware on the NXT, do so by running "./flash-rxe-firmware.sh"
The NXT will enter SAM-BA (reset) mode and begin clicking with a blank screen.
Re-run the script if the firmware download fails.
Once the firmware download is complete the screen will return to the normal menu.
8. In a VS Code terminal, run "./flash-rxe-app.sh" to download the .rxe binary to the NXT.
7. In a VS Code terminal, run "./flash-rxe-app.sh" to download the .rxe binary to the NXT.
There are many options for configuring your project. Please see the documentation directory and/or the original website (http://lejos-osek.sourceforge.net/) for more information.
---
## Developing in Docker in WSL
It is possible to run VS Code inside a Docker container inside WSL. This is currently the most future-proof way to use nxtOSEK on Windows.
1. Complete the installation as outlined above. While running `install.sh`, choose the options to install Docker and download the nxtOSEK Docker image.
2. Open VS Code on Windows. In File->Preferences->Settings, search for `remote.containers.executeInWSL` . Check the box to enable the option.
If you have multiple WSL instances, you can also change the `remote.containers.executeInWSLDistro` option and select which distro contains the nxtOSEK Docker image.
3. Proceed with project setup as normal. Make sure VS Code is open and connected to WSL before running `Remote-Containers: Open Workspace In Container`
---
## Tips for developing nxtOSEK using Docker
If the nxtOSEK Docker image has been installed, you can use `my_project/run-in-container.sh` to run commands in a Docker container with your project files. For example (Run from the root of your project folder):
Build your project (Does not need nxtOSEK toolchain installed locally!):
`./run-in-container.sh make all`
Clean your project:
`./run-in-container.sh make clean`
Open an interactive terminal containing your project workspace and an nxtOSEK development environment:
`./run-in-container.sh bash`
Download your program to the NXT over USB (Does not need the NXT tools installed locally!):
`./run-in-container.sh ./flash-rxe-app.sh`
6 changes: 3 additions & 3 deletions OSEK_C++_Project_Template/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
//source=/dev/bus/usb,target=/dev/bus/usb,type=bind",
//"source=/var/run/dbus,target=/var/run/dbus,type=bind"
],
"workspaceMount": "source=${localWorkspaceFolder},target=/home/nxtosek/projects/${localWorkspaceFolderBasename},type=bind",
"workspaceFolder": "/home/nxtosek/projects/${localWorkspaceFolderBasename}",
"workspaceMount": "source=${localWorkspaceFolder},target=/home/nxtuser/projects/${localWorkspaceFolderBasename},type=bind",
"workspaceFolder": "/home/nxtuser/projects/${localWorkspaceFolderBasename}",

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
Expand All @@ -32,7 +32,7 @@

// Overrides the user for all operations run as inside the container.
// Defaults to either root or the last USER instruction in the related Dockerfile used to create the image.
"containerUser": "nxtosek",
"containerUser": "nxtuser",

// A command string or list of command arguments to run on the host machine before the container is created.
//"initializeCommand": "sudo sysctl -w vm.mmap_min_addr=0 && sudo killall -9 bluetoothd && sudo cp 70-nxt.rules /etc/udev/rules.d/ && sudo udevadm control --reload-rules",
Expand Down
11 changes: 5 additions & 6 deletions OSEK_C++_Project_Template/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"configurations": [
{
"name": "OSEK_C++",
"name": "OSEK",
"includePath": [
"${workspaceFolder}/**",
"${env:NXTOSEK}/c++/**",
"${env:NXTOSEK}/ecrobot/c/**",
"${env:NXTOSEK}/ecrobot/c++/**",
"${env:NXTOSEK}/toppers_osek/**",
"${env:NXTOSEK}/lejos_nxj/src/nxtvm/**"
"/usr/local/src/nxtosek/ecrobot/c",
"/usr/local/src/nxtosek/ecrobot/c++/**",
"/usr/local/src/nxtosek/toppers_osek/**",
"/usr/local/src/nxtosek/lejos_nxj/src/nxtvm/**"
],
"defines": [],
"compilerPath": "/usr/bin/arm-none-eabi-gcc",
Expand Down
Loading

0 comments on commit 4b41c9d

Please sign in to comment.