76 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			76 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/bash
 | |
| 
 | |
| ###############################################
 | |
| #
 | |
| # Download and compile `picotool`.
 | |
| # src: https://github.com/raspberrypi/picotool
 | |
| #
 | |
| # The Pico C SDK must be installed before,
 | |
| # see: `install_sdk.bash`.
 | |
| #
 | |
| # ex: ./install_picotool.bash 2.1.0
 | |
| # NOTE: the version passed must match the SDK
 | |
| # version installed
 | |
| #
 | |
| ###############################################
 | |
| 
 | |
| PICOTOOL_VERSION=$1
 | |
| REGEX_VERSION="^[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}$"
 | |
| 
 | |
| if [[ -z ${INSTALL_PATH} ]]
 | |
| then
 | |
|     INSTALL_PATH=${PWD}
 | |
| fi
 | |
| 
 | |
| usage() {
 | |
|     echo "usage:"
 | |
|     echo "./install_picotool.bash <version> (ex: ./install_picotool.bash 2.1.0)"
 | |
| }
 | |
| 
 | |
| if [[ ! "${PICOTOOL_VERSION}" =~ ${REGEX_VERSION} ]]
 | |
| then
 | |
|     echo "error: unable to parse the picotool version: '${PICOTOOL_VERSION}'"
 | |
|     usage
 | |
|     exit 1
 | |
| fi
 | |
| 
 | |
| if [[ ! -d ${INSTALL_PATH}/sdk/${PICOTOOL_VERSION} ]]
 | |
| then
 | |
|     echo "error: SDK ${PICOTOOL_VERSION} must be installed"
 | |
|     exit 1
 | |
| fi
 | |
| 
 | |
| if [[ ! -d ${INSTALL_PATH}/picotool/${PICOTOOL_VERSION} ]]
 | |
| then
 | |
|     echo "install dependencies..."
 | |
|     sudo apt install build-essential pkg-config libusb-1.0-0-dev cmake
 | |
| 
 | |
|     echo "installing picotool..."
 | |
|     wget https://github.com/raspberrypi/picotool/releases/download/${PICOTOOL_VERSION}/picotool-${PICOTOOL_VERSION}.tar.gz -P ${INSTALL_PATH}
 | |
|     if [[ $? != 0 ]]
 | |
|     then
 | |
|         echo "error: unable to get picotool VERSION: ${PICOTOOL_VERSION}"
 | |
|         exit 1
 | |
|     fi
 | |
| 
 | |
|     mkdir -p ${INSTALL_PATH}/picotool/${PICOTOOL_VERSION}
 | |
|     tar xzvf ${INSTALL_PATH}/picotool-${PICOTOOL_VERSION}.tar.gz -C ${INSTALL_PATH}/picotool/${PICOTOOL_VERSION}
 | |
|     rm ${INSTALL_PATH}/picotool-${PICOTOOL_VERSION}.tar.gz
 | |
| fi
 | |
| 
 | |
| echo "building picotool..."
 | |
| mkdir -p ${INSTALL_PATH}/picotool/${PICOTOOL_VERSION}/build
 | |
| PICO_SDK_PATH=${INSTALL_PATH}/sdk/${PICOTOOL_VERSION}
 | |
| 
 | |
| cd ${INSTALL_PATH}/picotool/${PICOTOOL_VERSION}/build
 | |
| cmake ..
 | |
| make -C ${INSTALL_PATH}/picotool/${PICOTOOL_VERSION}/build
 | |
| 
 | |
| picotool_version=$(${INSTALL_PATH}/picotool/${PICOTOOL_VERSION}/build/picotool version)
 | |
| echo "${picotool_version} compiled successfully"
 | |
| 
 | |
| echo "adding udev picotool rules..."
 | |
| sudo cp ${INSTALL_PATH}/picotool/${PICOTOOL_VERSION}/udev/99-picotool.rules /etc/udev/rules.d/
 | |
| 
 | |
| echo "picotool installation completed"
 | 
