Skip to content

Commit

Permalink
restructure, buildroot.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kaplan2539 committed Nov 25, 2024
1 parent 61e60d2 commit 3459228
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
book/output
output
46 changes: 28 additions & 18 deletions book/src/buildroot.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,18 @@ Luckily, Buildroot comes with
Download and unpack the latest "stable" release:

```shell
wget -c -P download https://buildroot.org/downloads/buildroot-2023.11.tar.gz
tar xf download/buildroot-2023.11.tar.gz
# set U-Boot version
export UBOOT_VER=2024.10
export LINUX_VER=6.6.63

# set Buildroot version
export BR=buildroot-2024.02.8

mkdir -p download

echo "# Downloading Buildroot"
wget -c -P download https://buildroot.org/downloads/${BR}.tar.gz
tar xf download/${BR}.tar.gz
```

## Customizing Buildroot for CHIP
Expand All @@ -28,32 +38,32 @@ We are going to use the 'br2-external' mechanism (c.f. Buildroot documentation
) in order to keep our
costumizations outside of the official buildroot tree:

```
mkdir buildroot-external
```shell
mkdir -p buildroot-external
export BR2_EXTERNAL="$(realpath buildroot-external)"
```

Create `buildroot-external/external.desc`:
Create `external.desc`:

```
cat <<EOF >buildroot-external/external.desc
```shell
cat <<EOF >"${BR2_EXTERNAL}"/external.desc
name: CHIP
desc: Buildroot configuration for CHIP
EOF
```

Create `buildroot-external/external.mk`:
Create `external.mk`:

```
cat <<EOF >buildroot-external/external.mk
```shell
cat <<EOF >"${BR2_EXTERNAL}"/external.mk
include \$(sort \$(wildcard \$(BR2_EXTERNAL_CHIP_PATH)/package/*/*.mk))
EOF
```

Create empty `buildroot-external/Config.in`:
Create empty `Config.in`:

```
touch buildroot-external/Config.in
```shell
touch "${BR2_EXTERNAL}"/Config.in
```

Create
Expand All @@ -74,11 +84,11 @@ BR2_cortex_a8=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="6.1.68"
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="${LINUX_VER}"
BR2_LINUX_KERNEL_PATCH="\${BR2_EXTERNAL_CHIP_PATH}/board/nextthingco/CHIP/linux"
BR2_LINUX_KERNEL_DEFCONFIG="sunxi"
BR2_LINUX_KERNEL_DTS_SUPPORT=y
BR2_LINUX_KERNEL_INTREE_DTS_NAME="sun5i-r8-chip"
BR2_LINUX_KERNEL_INTREE_DTS_NAME="allwinner/sun5i-r8-chip"
BR2_LINUX_KERNEL_DTB_OVERLAY_SUPPORT=y
BR2_LINUX_KERNEL_INSTALL_TARGET=y
BR2_TARGET_ROOTFS_CPIO=y
Expand All @@ -87,7 +97,7 @@ BR2_TARGET_ROOTFS_CPIO_UIMAGE=y
BR2_TARGET_UBOOT=y
BR2_TARGET_UBOOT_BUILD_SYSTEM_KCONFIG=y
BR2_TARGET_UBOOT_CUSTOM_VERSION=y
BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE="2023.10"
BR2_TARGET_UBOOT_CUSTOM_VERSION_VALUE="${UBOOT_VER}"
BR2_TARGET_UBOOT_PATCH="\${BR2_EXTERNAL_CHIP_PATH}/board/nextthingco/CHIP/uboot"
BR2_TARGET_UBOOT_BOARD_DEFCONFIG="CHIP"
BR2_TARGET_UBOOT_NEEDS_DTC=y
Expand All @@ -100,7 +110,7 @@ EOF
Now compile Linux, U-Boot and build a rootfs image using Buildroot:

```shell
cd buildroot-2023.11
cd "${BR}"
make nextthingco_chip_defconfig
make
```
Expand All @@ -125,5 +135,5 @@ for more details.

To boot, type the following in the `cu` terminal window:
```
=> bootz 0x42000000 0x50000000 0x43000000
bootz 0x42000000 0x50000000 0x43000000
```
3 changes: 2 additions & 1 deletion book/src/warmup.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ These commands are going to install a cross-compiler toolchain, the

```shell
sudo bash -c '\
{{#include ../../setup/install_packages.sh:3:}}'
{{#include ../../scripts/install_packages.sh:3:}}'
```

Let us add the current user to the `dialout` group in order to run the `cu`
Expand Down Expand Up @@ -70,6 +70,7 @@ To download and unpack U-Boot type:
export UBOOT_VER=2024.10

echo "# Downloading U-Boot"
mkdir -p download
wget -c -P download https://source.denx.de/u-boot/u-boot/-/archive/v${UBOOT_VER}/u-boot-v${UBOOT_VER}.tar.bz2

echo "# Extracting U-Boot"
Expand Down
92 changes: 92 additions & 0 deletions scripts/extract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import argparse
import re
import pathlib

bash_preamble = """#!/bin/bash
set -e
set -x
set -u
"""

r_include = re.compile(r"{{#include ([^:}]*)(:[0-9]*)?(:[0-9]*)?[^}]*}}([^{]*)")

def read_file(out,path,first_line=None,last_line=None):
n=0
with open(path,"rb") as f:
for line in f:
n+=1
if first_line!=None and n<first_line:
continue
if last_line!=None and n>last_line:
break
out.write(line)

def parse_code(f,out,input_path):
n = 0
for line in f:
n+=1
if line.startswith(b'```'):
return
cont=False
for m in r_include.finditer(line.decode()):
first = 1
last = None
filename = m.group(1)
print(f"#DEBUG# line={line.decode()}")
print(f"#DEBUG# g1=[{m.group(1)}]")
print(f"#DEBUG# g2=[{m.group(2)}]")
print(f"#DEBUG# g3=[{m.group(3)}]")
print(f"#DEBUG# g4=[{m.group(4)}]")
if(m.group(2)):
try:
first = int(m.group(2)[1:])
except:
pass
if(m.group(3)):
try:
last = int(m.group(3)[1:])
except:
pass
if not pathlib.Path(filename).is_absolute():
print(f"## filename = {filename}")
print(f"## input_path = {input_path}")
filename = input_path / filename
print(f"## filename = {filename}")
read_file(out,filename,first,last)
out.write(m.group(4).encode())
cont=True
if cont:
continue
out.write(line)

def main():
parser = argparse.ArgumentParser(
prog = "extract.py",
description = "Extracs shell code from Markdown files",
epilog = "Famous last words...",
)

parser.add_argument('input')
parser.add_argument('output')
args = parser.parse_args()

input_path = pathlib.Path(args.input).parent
print(f"input_path={input_path}")


with open(args.input,"rb") as f, open(args.output,"wb") as out:
out.write(bash_preamble.encode())
n = 0
for line in f:
n += 1
# print(f"{n}: {line}")
if line.startswith(b'```shell') and not b'ignore' in line:
parse_code(f,out,input_path)

if __name__ == "__main__":
main()
File renamed without changes.

0 comments on commit 3459228

Please sign in to comment.