Skip to content

Commit

Permalink
genimage: define bootloader offset
Browse files Browse the repository at this point in the history
  • Loading branch information
Da Xue authored and lc-engineering-bot committed Oct 4, 2023
1 parent 7f7f8fe commit 5f7cdae
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 9 deletions.
38 changes: 38 additions & 0 deletions board/librecomputer/genimage/bootloader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

declare -A BOOTLOADER_OFFSET=(
[all-h3-cc-h3]=16
[all-h3-cc-h5]=16
[aml-a311d-cc]=1
[aml-s805x-ac]=1
[aml-s905x-cc]=1
[aml-s905x-cc-v2]=1
[aml-s905d-pc]=1
[aml-s905d3-cc]=1
[roc-rk3328-cc]=64
[roc-rk3399-pc]=64
)

BOOTLOADER_URL="https://boot.libre.computer/ci/"
BOOTLOADER_BLK_SIZE=512

BOOTLOADER_getOffset(){
local board=$1
echo -n $((${BOOTLOADER_OFFSET[$board]} * BOOTLOADER_BLK_SIZE))
}

BOOTLOADER_getURL(){
echo -n "${BOOTLOADER_URL}${1}"
}

BOOTLOADER_getHeaders(){
WGET_getHeaders "$BOOTLOADER_URL/$1"
}

BOOTLOADER_get(){
local board=$1
local bl=$2
echo "$FUNCNAME: downloading $board bootloader to $bl."
echo
wget -nc -O $bl "$BOOTLOADER_URL/$board" 2>&1 && echo "$FUNCNAME: downloaded $board bootloader to $bl." || echo "$FUNCNAME: noop $board bootloader exists at $bl."
}
2 changes: 1 addition & 1 deletion board/librecomputer/genimage/efi-btrfs/genimage.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ image sdcard.img {
}
partition bootloader {
in-partition-table = false
offset = 512
offset = __BL_OFFSET__
image = "__BOARD__"
}
partition bootfs {
Expand Down
15 changes: 11 additions & 4 deletions board/librecomputer/genimage/efi-btrfs/genimage.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
#!/bin/bash
set -x
set -ex

BOARD=$2

SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
. $SCRIPT_DIR/../bootloader.sh

GENIMG_CFG=$BINARIES_DIR/genimage.cfg

wget -nc https://boot.libre.computer/ci/$BOARD -O $BINARIES_DIR/$BOARD
BOOTLOADER_get $BOARD $BINARIES_DIR/$BOARD

#wget -nc https://boot.libre.computer/ci/$BOARD -O $BINARIES_DIR/$BOARD

cp -f $(dirname "${BASH_SOURCE[0]}")/genimage.cfg "$BINARIES_DIR/"
cp -f $(dirname "${BASH_SOURCE[0]}")/boot.ini "$BINARIES_DIR/"
cp -f $SCRIPT_DIR/genimage.cfg "$BINARIES_DIR/"
cp -f $SCRIPT_DIR/boot.ini "$BINARIES_DIR/"

sed -i "s/__BL_OFFSET__/$(BOOTLOADER_getOffset $BOARD)/" "$GENIMG_CFG"
sed -i "s/__BOARD__/$BOARD/" "$GENIMG_CFG"

support/scripts/genimage.sh -c "$GENIMG_CFG"
2 changes: 1 addition & 1 deletion board/librecomputer/genimage/initramfs/genimage.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ image sdcard.img {
}
partition bootloader {
in-partition-table = false
offset = 512
offset = __BL_OFFSET__
image = "__BOARD__"
}
partition rootfs {
Expand Down
12 changes: 9 additions & 3 deletions board/librecomputer/genimage/initramfs/genimage.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#!/bin/bash
set -x
set -ex

BOARD=$2
SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
. $SCRIPT_DIR/../bootloader.sh

IMAGE_SIZE=$(stat -c %s $BINARIES_DIR/Image)
IMAGE_SIZE=$((((IMAGE_SIZE + (17 << 20) - 1) >> 23 << 3) - 1))
GENIMG_CFG=$BINARIES_DIR/genimage.cfg

wget https://boot.libre.computer/ci/$BOARD -O $BINARIES_DIR/$BOARD
BOOTLOADER_get $BOARD $BINARIES_DIR/$BOARD

#wget -nc https://boot.libre.computer/ci/$BOARD -O $BINARIES_DIR/$BOARD

cp -f $(dirname "${BASH_SOURCE[0]}")/genimage.cfg "$GENIMG_CFG"
cp -f $SCRIPT_DIR/genimage.cfg "$BINARIES_DIR/"

sed -i "s/__SIZE__/$IMAGE_SIZE/" "$GENIMG_CFG"
sed -i "s/__BL_OFFSET__/$(BOOTLOADER_getOffset $BOARD)/" "$GENIMG_CFG"
sed -i "s/__BOARD__/$BOARD/" "$GENIMG_CFG"

support/scripts/genimage.sh -c "$GENIMG_CFG"

0 comments on commit 5f7cdae

Please sign in to comment.