Diagonalizing a block diagonal matrix I have a matrix of $2 \times 2$ blocks which looks like
\begin{equation}
M = 
\begin{pmatrix}
A & B & B & \cdots \\
B & A & B & \cdots \\
B & B & A & \cdots \\
\vdots &\vdots& \vdots& \ddots
\end{pmatrix}
\end{equation}
with $dim M = 2N$ (or $N \times N$ blocks). I can put this into a nice block-diagonal form with Mathematica:
\begin{equation}
M = 
\begin{pmatrix}
A + (N-1)B &  &  &  \\
 & A-B &  &  \\
 &  & A-B &  \\
\, &\,& \,& \ddots
\end{pmatrix}
\end{equation}
but I don't know where exactly this form comes from. This may just be due to the form of the blocks, which for completeness are
\begin{equation}
A = 
\begin{pmatrix}
1 & 1 \\
a & a + 1
\end{pmatrix}, \; \; \; B =
\begin{pmatrix}
0 & 0\\
\eta & 0
\end{pmatrix}
\end{equation}
but I'd like to know how to see this diagonalization explicitly.
 A: First, let's review the problem where $A,B$ are merely scalars. Then we can express our matrix as $$M=(a-b)I_N+buu^\top$$ where $u$ is a vector of 1s. We take advantage of this by noting that the eigenbasis of the rank-one matrix $uu^\top$ is simply $u_1:=u$ itself (with eigenvalue $N$) and the $N-1$ eigenvectors $u_2,u_3,\ldots u_N$ where $u_k:=e_{k}-e_{1}$ (with eigenvalue $0$). Note that that the latter vectors are all orthogonal to $u$.
To make this more explicit, we introduce $$U=\begin{pmatrix} u_1 & u_2 & \cdots & u_N\end{pmatrix} = 
\begin{pmatrix}
1 & -1 & -1 & \cdots &  -1 \\
1 & 1 & 0 &\cdots & 0\\
\vdots & \vdots & \vdots & \ddots & \vdots \\
1 & 0 &    0 & \cdots & 1
\end{pmatrix}$$
and observe that $$uu^\top U=\begin{pmatrix} u(u^\top u_1) & u(u^\top u_2)& \cdots& u(u^\top u_N)\end{pmatrix}=\begin{pmatrix} Nu & 0 & \cdots & 0\end{pmatrix}=U \Lambda$$ where $\Lambda=\operatorname{diag}(N,0,\ldots,0)$. Hence $uu^\top$ is diagonalized as $uu^\top=U^{-1}\Lambda U$, and therefore $M$ is as well:
\begin{align}
UMU^{-1} 
&=(a-b)I_N+ b U^{-1}uu^\top U  \\
&=(a-b)I_N+b U^{-1}U\Lambda \\
&= (a-b)I_N+N b \Lambda\\
&= \operatorname{diag}(a+(N-1)b,a-b,\ldots, a-b)
\end{align} in agreement with Mathematica's proposition.
That's fine for the case of scalar $A,B$, but what about 2-by-2 matrices? To deal with this, we write $M$ using the Kronecker product $\otimes$  as $$M=I_N\otimes (A-B)+ uu^\top\otimes B.$$ We can now diagonalize $M$ as before, but now using the matrix
$$U\otimes I_2=
\begin{pmatrix}
I_2 & -I_2 & -I_2 & \cdots &  -I_2 \\
I_2 & I_2 & 0_2 &\cdots & 0_2\\
\vdots & \vdots & \vdots & \ddots & \vdots \\
I_2 & 0_2 &    0_2 & \cdots & I_2
\end{pmatrix}$$
where $0_2$ is a 2-by-2 matrix of zeros. We have
\begin{align}
(U\otimes I_2)M(U\otimes I_2)^{-1}
&=(U \otimes I_2)\Big[I_N\otimes (A-B)+uu^\top \otimes B\Big ](U^{-1} \otimes I_2)\\
&=(UI_N U^{-1})\otimes(I_2(A-B)I_2)+(Uu^\top U^{-1})\otimes(I_2 B I_2)\\
&=I_N\otimes (A-B)+\Lambda \otimes B
\end{align}
which is exactly the block-diagonal form given by Mathematica. So we can indeed block-diagonalize $M$ in the way proposed by Mathematica, in a way that's entirely analogous to the construction for scalar $A,B$. (Indeed, it's straightforward to do this for square matrices $A,B$ of arbitrary dimension.)
A closing observation: While the first column of $U$ was determined explicitly (up to a multiplicative constant), the remaining columns were chosen to have $N-1$ vectors which were orthogonal to $u$. These were far from unique: Not only would any permutation suffice, but we could also have picked for instance the vectors $$e_1-e_2,e_2-e_3,\ldots,e_N-e_{N-1}.$$ As such, there's no one way to diagonalize $M$ in the desired form. The form chosen above is simply what seemed easiest to write out explicitly.
