Skip to content

Commit 00a79b2

Browse files
Initial version
0 parents  commit 00a79b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2873
-0
lines changed

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# ESWIN EIC7X SDK Build
2+
3+
This builds a complete RISC-V cross-compile toolchain for the ESWIN EIC7X SoC.
4+
5+
## Prerequisites
6+
7+
Recommend OS: Ubuntu 16.04/18.04/20.04 x86_64
8+
9+
Install required additional packages:
10+
11+
```
12+
$ sudo apt update
13+
$ sudo apt-get install gdisk dosfstools build-essential libncurses-dev gawk flex bison \
14+
openssl libssl-dev tree dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf \
15+
device-tree-compiler xz-utils devscripts ccache debhelper wget curl pahole \
16+
libconfuse-dev mtools fastboot rsync
17+
$ sudo apt install -y debootstrap devscripts qemu-user-static qemu-utils binfmt-support mmdebstrap
18+
```
19+
20+
Additional docker:
21+
22+
```
23+
sudo apt install docker.io
24+
```
25+
26+
Get Eswin's RISC-V cross-compilation Docker Image:
27+
```
28+
wget http://120.92.155.32:8082/artifactory/virtOS/fml13v03-eswin/es_debian_compile_docker.tar
29+
sudo docker load -i es_debian_compile_docker.tar
30+
sudo docker pull multiarch/qemu-user-static
31+
sudo docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
32+
```
33+
34+
## Fetch Code Instructions
35+
36+
Checkout this repository. Then checkout all of the linked submodules using:
37+
```
38+
$ git clone https://github.com/DC-DeepComputing/fml13v03.git
39+
40+
# To fetch the code along with all tags, run the following command to initialize and update all submodules.
41+
# If you only need to compile, this step is not necessary. When you run the make commands, it will automatically pull the latest code as needed.
42+
$ git submodule foreach --recursive 'git checkout $(git config -f $toplevel/.gitmodules submodule.$name.branch)'
43+
```
44+
45+
## Quick Build Instructions
46+
47+
```
48+
cd fml13v03
49+
sudo docker run --rm --privileged -it -v "$(pwd)":/home/workspace -u root -w "/home/workspace" es_debian
50+
51+
source setenv.sh
52+
53+
Use the following method to start compiling:
54+
make_bootchain
55+
make_kernel
56+
make_debug_kernel
57+
make_desktop_images
58+
make_minimal_images
59+
make_all:bootchain kernel minimal_images
60+
61+
```
62+

deepcomputing/bmptoarr_tools.zip

1.36 KB
Binary file not shown.

deepcomputing/make_os_image.sh

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env bash
2+
3+
# Install required packages if not installed
4+
echo "Checking and installing required packages..."
5+
apt update
6+
apt install -y udev parted kpartx
7+
8+
# Read input parameters
9+
BOARD=${board_name}
10+
BOOT_IMG=${WORK_DIR}/${board_name}/output/boot-${board_name}.ext4
11+
ROOTFS_IMG=${WORK_DIR}/${board_name}/output/root-${board_name}.ext4
12+
13+
# Check if boot and rootfs image files exist
14+
if [ ! -f "$BOOT_IMG" ]; then
15+
echo "Error: Boot image '$BOOT_IMG' not found!"
16+
return 1
17+
fi
18+
19+
if [ ! -f "$ROOTFS_IMG" ]; then
20+
echo "Error: RootFS image '$ROOTFS_IMG' not found!"
21+
return 1
22+
fi
23+
24+
# Generate system image filename based on BOARD and RELEASE_TAG
25+
IMAGE="EIC7X-${BOARD}-${RELEASE_TAG}.img"
26+
27+
# Fixed sizes for Boot and Swap partitions
28+
BOOT_SIZE=512MiB
29+
SWAP_SIZE=4G
30+
31+
# Dynamically calculate RootFS size based on the rootfs image size (in MB) plus a 50 MB margin
32+
ROOT_SIZE=$(du -m "$ROOTFS_IMG" | awk '{print $1 + 50}')M
33+
34+
# Calculate the end of the swap partition in MiB
35+
SWAP_END=$((${BOOT_SIZE%MiB} + ${SWAP_SIZE%G} * 1024))
36+
37+
# Total image size: Boot + Swap + RootFS + an extra 256M for buffer
38+
TOTAL_SIZE=$(echo "$SWAP_END + ${ROOT_SIZE%M} + 256" | bc)M
39+
40+
echo "Creating minimal disk image: $IMAGE"
41+
echo "Total size: $TOTAL_SIZE (Boot: $BOOT_SIZE, Swap: $SWAP_SIZE, RootFS: $ROOT_SIZE)"
42+
43+
# Create an image file with the total size
44+
truncate -s "$TOTAL_SIZE" "$IMAGE"
45+
46+
BOOT_UUID=$(blkid -s UUID -o value "$BOOT_IMG")
47+
48+
# Create partition table using parted
49+
parted -s "$IMAGE" mklabel gpt
50+
parted -s "$IMAGE" mkpart boot ext4 1MiB ${BOOT_SIZE}
51+
parted -s "$IMAGE" mkpart swap linux-swap ${BOOT_SIZE} ${SWAP_END}MiB
52+
parted -s "$IMAGE" mkpart rootfs ext4 ${SWAP_END}MiB 100%
53+
54+
# Associate the image with a loop device (without --partscan)
55+
LOOPDEV=$(losetup --find --show "$IMAGE")
56+
echo "Using loop device: $LOOPDEV"
57+
58+
# Use kpartx to create partition mappings under /dev/mapper/
59+
kpartx -av "$LOOPDEV"
60+
61+
# Format the partitions
62+
mkswap /dev/mapper/$(basename "$LOOPDEV")p2
63+
mkfs.ext4 -F /dev/mapper/$(basename "$LOOPDEV")p3
64+
65+
ROOTFS_UUID=$(blkid -s UUID -o value "$ROOTFS_IMG")
66+
# 恢复 UUID
67+
if [ -n "$ROOTFS_UUID" ]; then
68+
yes | tune2fs -f -U "$ROOTFS_UUID" /dev/mapper/$(basename "$LOOPDEV")p3
69+
fi
70+
71+
# Get the UUID for swap partition
72+
SWAP_UUID=$(blkid -s UUID -o value /dev/mapper/$(basename "$LOOPDEV")p2)
73+
echo "Swap partition UUID: $SWAP_UUID"
74+
75+
# Get the UUID for root partition
76+
ROOTFS_UUID=$(blkid -s UUID -o value /dev/mapper/$(basename "$LOOPDEV")p3)
77+
echo "RootFS partition UUID: $ROOTFS_UUID"
78+
79+
# Mount and copy Boot data
80+
dd if="$BOOT_IMG" of=/dev/mapper/$(basename "$LOOPDEV")p1 bs=1M status=progress
81+
82+
# Mount and copy RootFS data
83+
mkdir -p /mnt/rootfs
84+
mount /dev/mapper/$(basename "$LOOPDEV")p3 /mnt/rootfs
85+
mkdir -p /mnt/rootfs_ext4
86+
mount -o loop "$ROOTFS_IMG" /mnt/rootfs_ext4
87+
echo "Copying rootfs image content into rootfs partition..."
88+
cp -a /mnt/rootfs_ext4/. /mnt/rootfs/
89+
90+
FSTAB_FILE="/mnt/rootfs/etc/fstab"
91+
# swap
92+
if grep -q "swap" "$FSTAB_FILE"; then
93+
sed -i "s|UUID=[a-f0-9-]*[[:space:]]*none[[:space:]]*swap|UUID=$SWAP_UUID none swap|" "$FSTAB_FILE"
94+
else
95+
echo "UUID=$SWAP_UUID none swap sw 0 0" >> "$FSTAB_FILE"
96+
fi
97+
98+
umount /mnt/rootfs_ext4
99+
rmdir /mnt/rootfs_ext4
100+
umount /mnt/rootfs
101+
rmdir /mnt/rootfs
102+
103+
# Clean up: remove partition mappings and detach loop device
104+
kpartx -dv "$LOOPDEV"
105+
losetup -d "$LOOPDEV"
106+
107+
echo "Disk image creation complete: $IMAGE"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# make_updateimg.sh Readme
2+
3+
This document provides a step-by-step guide for executing the `make_updateimg.sh` script to create the final update image.
4+
5+
## Overview
6+
7+
The `make_updateimg.sh` script performs the following tasks:
8+
9+
1. **Generate usbupdate.scr**
10+
It creates `usbupdate.scr` from `update-usb.sh`.
11+
12+
2. **Copy ext4 Files**
13+
Based on the configuration specified in `config.txt`, it copies the corresponding ext4 files into the `update` directory.
14+
15+
3. **Generate Final Image**
16+
It executes a shell script that generates the final update image.
17+
18+
## Prerequisites
19+
20+
- Ensure you have a working Linux environment.
21+
- Required tools: `bash`, `mkfs.ext4`, `dd`, and standard Unix utilities.
22+
- Confirm that `update-usb.sh`, `config.txt`, and all required ext4 files are present in the working directory.
23+
24+
## Steps
25+
26+
1. **Generate update.scr**
27+
The script will convert the `update-usb.sh` file into a script file named `update.scr`.
28+
29+
2. **Copy ext4 Files to update Directory**
30+
The script reads `config.txt` to determine which ext4 files should be copied into the `update` directory. Make sure that `config.txt` is correctly configured and that the ext4 files exist.
31+
32+
3. **Execute the Update Image Script**
33+
Finally, the script runs the shell commands to generate the final update image. This image includes the boot files and root filesystem as specified.
34+
35+
## Usage
36+
37+
Simply run the following command in your terminal:
38+
39+
```bash
40+
sh make_updateimg.sh
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# List file prefixes for update files
2+
bootloader
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Configuration file containing file name prefixes (one per line)
5+
CONFIG_FILE="config.txt"
6+
7+
# ANSI color codes
8+
RED='\033[31m'
9+
YELLOW='\033[33m'
10+
NC='\033[0m' # Reset color
11+
12+
# Ensure WORK_DIR and board_name are set
13+
if [ -z "$WORK_DIR" ] || [ -z "$board_name" ]; then
14+
echo -e "${RED}Error: WORK_DIR or board_name is not set!${NC}"
15+
echo "Please configure the environment variables WORK_DIR and board_name before running this script."
16+
return 1
17+
fi
18+
19+
# Define directories
20+
SOURCE_DIR="${WORK_DIR}/${board_name}/output"
21+
UPDATE_DIR="./update"
22+
23+
# Check if the configuration file exists
24+
if [ ! -f "$CONFIG_FILE" ]; then
25+
echo -e "${RED}Error: Configuration file '$CONFIG_FILE' not found!${NC}"
26+
return 1
27+
fi
28+
29+
rm -f update_image.img
30+
rm -rf "$UPDATE_DIR"
31+
32+
# Create the update directory if it doesn't exist
33+
mkdir -p "$UPDATE_DIR"
34+
35+
# Read file prefixes from config.txt and copy matching files
36+
while IFS= read -r line || [ -n "$line" ]; do
37+
# Ignore empty lines and comments
38+
[[ -z "$line" || "$line" =~ ^# ]] && continue
39+
40+
echo "Processing prefix: '$line'"
41+
42+
# Find matching files
43+
matches=( "$SOURCE_DIR"/"$line"* )
44+
45+
if [ ! -e "${matches[0]}" ]; then
46+
echo -e "${YELLOW}Warning: No files found with prefix '$line' in $SOURCE_DIR.${NC}"
47+
continue
48+
fi
49+
50+
# Copy matching files
51+
for file in "${matches[@]}"; do
52+
[ -f "$file" ] && echo "Copying: $file -> $UPDATE_DIR/" && cp "$file" "$UPDATE_DIR/"
53+
done
54+
55+
done < "$CONFIG_FILE"
56+
57+
echo "All matching files have been copied to the update directory."
58+
59+
# Execute additional scripts
60+
echo "Executing make_usbupdate_scr.sh"
61+
bash "sh/make_usbupdate_scr.sh"
62+
63+
echo "Executing make_update_image.sh"
64+
bash "sh/make_update_image.sh"
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Path to the update directory
5+
UPDATE_DIR="./update"
6+
# Temporary mount directory
7+
MOUNT_DIR="$PWD/mnt/update_img"
8+
# Output image file name
9+
IMG_FILE="./update_image.img"
10+
# Extra space to add (in bytes), here we add 10MB
11+
EXTRA_SPACE=$((10 * 1024 * 1024))
12+
13+
# Check if the update directory exists
14+
if [ ! -d "$UPDATE_DIR" ]; then
15+
echo "Directory $UPDATE_DIR does not exist!"
16+
return
17+
fi
18+
19+
echo "Calculating the size of the $UPDATE_DIR directory..."
20+
# Calculate the size of the update directory (in bytes)
21+
DIR_SIZE=$(du -sb "$UPDATE_DIR" | awk '{print $1}')
22+
echo "Size of update directory: $DIR_SIZE bytes"
23+
24+
# Calculate the total size for the image: directory size plus extra space
25+
TOTAL_SIZE=$((DIR_SIZE + EXTRA_SPACE))
26+
echo "Total image size set to: $TOTAL_SIZE bytes (including extra space)"
27+
28+
# Create an empty image file with the calculated size
29+
echo "Creating image file: $IMG_FILE"
30+
dd if=/dev/zero of="$IMG_FILE" bs=1 count=0 seek="$TOTAL_SIZE"
31+
32+
# Format the image file with the ext4 filesystem
33+
echo "Formatting the image as ext4..."
34+
mkfs.ext4 -F "$IMG_FILE" > /dev/null
35+
36+
# Create the mount directory if it doesn't exist
37+
echo "Creating mount directory: $MOUNT_DIR"
38+
mkdir -p "$MOUNT_DIR"
39+
40+
# Mount the image file to the mount directory using loop device
41+
echo "Mounting the image..."
42+
sudo mount -o loop "$IMG_FILE" "$MOUNT_DIR"
43+
44+
# Copy the contents of the update directory into the mounted image
45+
echo "Copying files from $UPDATE_DIR to the image..."
46+
sudo cp -r "$UPDATE_DIR"/* "$MOUNT_DIR"
47+
48+
# Sync data to ensure all writes are completed
49+
echo "Syncing data..."
50+
sync
51+
52+
# Unmount the image
53+
echo "Unmounting the image..."
54+
sudo umount "$MOUNT_DIR"
55+
56+
echo "Image $IMG_FILE has been successfully created!"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
set -e # Exit immediately if a command exits with a non-zero status
4+
5+
# ANSI color codes
6+
RED="\033[31m"
7+
YELLOW="\033[33m"
8+
RESET="\033[0m"
9+
10+
echo "Generating usbupdate.scr..."
11+
12+
# Create a temporary copy of update-usb-wic.sh
13+
TEMP_UPDATE_USB="./sh/update-usb-temp.sh"
14+
cp ./sh/update-usb-wic.sh "$TEMP_UPDATE_USB"
15+
16+
# Function to generate usbupdate.scr
17+
generate_usbupdate() {
18+
if [ -z "$board_name" ]; then
19+
echo -e "${RED}Error: board_name is not set!${RESET}"
20+
return 1
21+
fi
22+
23+
if [ ! -d "$WORK_DIR" ] || [ ! -f "$WORK_DIR/${board_name}/uboot-eswin/tools/mkimage" ]; then
24+
echo -e "${RED}Error: mkimage tool not found. Please check your WORK_DIR and board_name.${RESET}"
25+
return 1
26+
fi
27+
28+
# Replace BOARD_NAME_PLACEHOLDER with the actual board_name in the temporary file
29+
sed -i "s/BOARD_NAME_PLACEHOLDER/$board_name/g" "$TEMP_UPDATE_USB"
30+
31+
"${WORK_DIR}/${board_name}/uboot-eswin/tools/mkimage" \
32+
-A riscv -O linux -T script -C none \
33+
-a 0x90000000 -e 0x90000000 \
34+
-n "U-Boot Script" -d "$TEMP_UPDATE_USB" ./update/usbupdate.scr
35+
36+
echo "usbupdate.scr generated successfully."
37+
}
38+
39+
# Execute the function and handle errors
40+
generate_usbupdate || echo -e "${RED}Failed to generate usbupdate.scr${RESET}"
41+
42+
# Remove the temporary file
43+
rm -f "$TEMP_UPDATE_USB"

0 commit comments

Comments
 (0)