# LSDK
> Download source code from ==https://www.nxp.com/design/software/embedded-software/linux-software-and-development-tools/layerscape-software-development-kit-v21-08:LAYERSCAPE-SDK==
> choose

### Compilation
1. Either install ubuntu 20.04 on pc or try using 20.04 ubuntu with docker on existing ubuntu 18.04 pc. But with docket there are many errors and settings need to resolve.
2. Better to go with ubuntu-20.04 installed in pc.
3. Copy ==flexbuild_lsdk2108.tgz== and untar it ==tar -xvf flexbuild_lsdk2108.tgz==
4. cd ==flexbuild_lsdk2108==
5. First execute
==sudo su==
==source setup.env==
7. Using flex-builder compile source code.
==flex-builder -h==
I have used ==flex-builder -i auto== **which automatically build all firmware, linux, apps components and distro userland for all arm64 machines**
>> **components** folder have all the source downloaded
**build** folder has all output images rcw, atf, u-boot, linux, ubuntu, yocto, buildroot (desktop|lite|tiny) , firmwares. Including different type of boot media.
**packages** folder has .mk files
**configs** folder has board-manifest files, buildroot-defconfig, linux-.config, ubuntu-.cfg and packages_list, yocto-.config.
### Copying built images for sdcard boot
>> Connect sdcard via card reader to developement machine and find it's name under lsblk. For example /dev/sdc
>> Make sure you don't mention parition number of block device like sdc1 , just mention sdc
>> ==***cd build/images/***== Execute command ...........**don't foget**
---
>> **flex-installer -r rootfs_lsdk2108_ubuntu_desktop_arm64_202206150917.tgz -b boot_LS_arm64_lts_5.10_202206150847.tgz -f firmware_ls1028ardb_sdboot.img -d /dev/sdc**
>> Here i am considering ubuntu desktop as rootfs and bootimage for arm64 built on 15th june 2022 and firmware images for ls1028 board as we don't have option of ls1023a in build option now.
>> To know more about ==flex-installer== refer to **docs/build_and_deploy_distro.md**
### Links
How to update only one of the image tfa/u-boot/rcw/ https://community.nxp.com/t5/Layerscape-Knowledge-Base/Reference-Design-Boards-How-tos/ta-p/1109286
pps
https://docs.nxp.com/bundle/GUID-3FFCCD77-5220-414D-8664-09E6FB1B02C6/page/GUID-F53B3CE9-AB67-4713-937F-7D1F71057081.html
device tree patch of pps
https://community.toradex.com/t/pps-gpio-adding-to-device-tree-syntax-error/10834/10
Writing uboot to nor boot
>> copy firmware_ls1043ardb_norboot.img sdcard(/dev/sdd**2**)
>> refer docs/lsdk_build_install.md->For IFC-NOR flash
>> load ==mmc 0:**2**== a0000000 firmware_<machine>_uboot_norboot.img , where machine is ls1043ardb

#### New topic (vendor explained steps with the help of ls1046ardb board) NOTE: we are using ls1043 and it do not have qspi interface so don't apply these steps for ls1043ardb
##### If spi flash and spi boot option is available on device then we can follow steps as
Those example step using LS1046ARDB for your reference (QSPI booting and rootfs in emmc)
The LS1043ARDB without emmc device, you can using SDCard to practice
1. In VM/LSDK2108
user@ubuntu:~/flexbuild_lsdk2108$ flex-builder -m ls1046ardb
>> create
firmware_ls1046ardb_qspiboot.img - bootloader
boot_LS_arm64_lts_5.10.tgz - kernel rootfs_lsdk2108_ubuntu_main_arm64.tgz - rootfs
2. Using tftp download firmware_ls1046ardb_qspiboot.img and programing QSPI flash(writing bootloader to spi flash)
=> tftp $load_addr firmware_ls1046ardb_qspiboot.img
=> sf probe 0:1
=> sf erase 0 +$filesize && sf write $load_addr 0 $filesize
3. Using QSPI Boot setting Booting in TinyLinux and using root login
NXP LSDK tiny 2108 (based on Yocto)
TinyLinux login: root
4. Put those two file in USB disk connect to LS1046ARDB
boot_LS_arm64_lts_5.10.tgz
rootfs_lsdk2108_ubuntu_main_arm64.tgz
5. Mount USB disk in /mnt
root@TinyLinux:~# mount /dev/sda1 /mnt
6. Using flex-install create boot partition and rootfs
root@TinyLinux:~# cd /mnt/
root@TinyLinux:/mnt# flex-installer -b boot_LS_arm64_lts_5.10.tgz -r rootfs_lsdk2108_ubuntu_main_arm64.tgz -d /dev/mmcblk0
#### Modify RCW settings as per hardware design and follow D:\LSDK-Nxp\LS1043ARM_Rev6.pdf document
Modify RCW, compile and prepare firmware for sd card
>>cd flexbuild_lsdk2108
source setup.env
vi components/firmware/rcw/ls1043ardb/RR_FQPP_1455/rcw_1600_sdboot.rcw
flex-builder clean-firmware //**clean build is mandatory to take changes into effect**
flex-builder -i mkfw -m ls1043ardb -b sd
cd build/images/
flex-installer -f firmware_ls1043ardb_sdboot.img -d /dev/sdc //**check sd card node by lsblk command**
### Rebuild bootloader, linux and rootfs
**flex-builder -m ls1043ardb**
prepare sd card after confirming the timestamp of individual images using command
**cd build/images**
**flex-installer -r rootfs_lsdk2108_ubuntu_desktop_arm64.tgz -b boot_LS_arm64_lts_5.10.tgz -f firmware_ls1043ardb_sdboot.img -d /dev/sdq**
---------------
## Add 30MAR23
### Compile only bootloader image for all type of boot media for ls1043ardb machine
> flex-builder -i mkfw -m ls1043ardb
to compile only for sd boot media
>flex-builder -i mkfw -m ls1043ardb -b sd
### Compile only linux image and make boot in tar format
flex-builder -c linux
machine type and boot media is optional
flex-builder -c linux -m ls1043ardb -b sd
flex-builder -i mkboot # generate boot partition tarball (contains kernel, dtb, modules, distro boot script, etc) for deployment
### Create rootfs of your choice and pack it to .tgz format
flex-builder -i mkrfs -r ubuntu:desktop # generate Ubuntu desktop arm64 userland
flex-builder -i mkrfs -r ubuntu:lite # generate Ubuntu lite arm64 userland
flex-builder -i mkrfs -r yocto:tiny # generate Yocto-based arm64 tiny userland
flex-builder -i mkrfs -r buildroot:tiny # generate Buildroot-based arm64 tiny userland
flex-builder -i mkrfs -r centos # generate CentOS arm64 userland
flex-builder -i mkitb -r yocto:tiny # generate lsdk_yocto_tiny_LS_arm64.itb
> flex-builder i packrfs <os>:<variant>
for eg: flex-builder -i packrfs ubuntu:lite
### Compile all images for machine ls1043ardb
flex-builder -m ls1043ardb # automatically build all firmware, linux, apps components and distro userland for ls1046ardb
### Clean all or clean build for each subsystem
flex-builder clean # clean all obsolete firmware/linux/apps image except distro rootfs
flex-builder clean-rfs # clean distro rootfs, '-r ubuntu:main -a arm64' by default
flex-builder clean-firmware # clean obsolete firmware image
flex-builder clean-linux # clean obsolete linux image
------------------
### Installing linuxptp
wget http://ports.ubuntu.com/pool/universe/l/linuxptp/linuxptp_1.9.2-1_arm64.deb
dpkg -i linuxptp_1.9.2-1_arm64.deb